Skip to content

Commit 0e33a00

Browse files
authored
fix: add href to tab items if they're set (#3527)
1 parent 70110a4 commit 0e33a00

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

packages/shared/src/components/header/FeedExploreHeader.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export function FeedExploreHeader({
9494
>
9595
{isExtension ? (
9696
<TabList<ExploreTabs>
97-
items={Object.values(ExploreTabs)}
97+
items={Object.values(ExploreTabs).map((label) => ({
98+
label,
99+
}))}
98100
active={tab}
99101
onClick={setTab}
100102
/>

packages/shared/src/components/tabs/TabContainer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ export function TabContainer<T extends string = string>({
140140
)}
141141
>
142142
<TabList<T>
143-
items={children.map((child) => child.props.label)}
143+
items={children.map((child) => ({
144+
label: child.props.label,
145+
url: child.props?.url,
146+
}))}
144147
renderTab={renderTab}
145148
onClick={onClick}
146149
active={currentActive}

packages/shared/src/components/tabs/TabList.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import React, {
77
useState,
88
} from 'react';
99
import { RenderTab } from './common';
10+
import type { TabProps } from './TabContainer';
1011

1112
export type AllowedTabTags = keyof Pick<JSX.IntrinsicElements, 'a' | 'button'>;
1213

@@ -21,7 +22,7 @@ interface DimensionProps {
2122
indicatorOffset: number;
2223
}
2324
export interface TabListProps<T extends string = string> {
24-
items: T[];
25+
items: Pick<TabProps<T>, 'label' | 'url'>[];
2526
active: T;
2627
onClick?: (label: T) => unknown;
2728
className?: ClassName;
@@ -39,7 +40,8 @@ function TabList<T extends string = string>({
3940
renderTab,
4041
tag: Tag = 'button',
4142
}: TabListProps<T>): ReactElement {
42-
const hasActive = items.includes(active);
43+
const labels = items.map((item) => item.label);
44+
const hasActive = labels.includes(active);
4345
const currentActiveTab = useRef<HTMLButtonElement>(null);
4446
const [dimensions, setDimensions] = useState<DimensionProps>({
4547
offset: 0,
@@ -104,22 +106,22 @@ function TabList<T extends string = string>({
104106

105107
return (
106108
<ul className="relative flex flex-row">
107-
{items.map((tab) => {
108-
const isActive = tab === active;
109-
const renderedTab = renderTab?.({ label: tab, isActive }) ?? (
109+
{items.map(({ label, url: href }) => {
110+
const isActive = label === active;
111+
const renderedTab = renderTab?.({ label, isActive }) ?? (
110112
<span
111113
className={classNames(
112114
'inline rounded-10 px-3 py-1.5',
113115
isActive && 'bg-theme-active',
114116
)}
115117
>
116-
{tab}
118+
{label}
117119
</span>
118120
);
119121

120122
return (
121123
<Tag
122-
key={tab}
124+
key={label}
123125
ref={(el) => {
124126
if (!el || !isActive) {
125127
return;
@@ -133,11 +135,12 @@ function TabList<T extends string = string>({
133135
isActive ? '' : 'text-text-tertiary',
134136
isAnchor && 'cursor-pointer',
135137
)}
136-
onClick={() => onClick(tab)}
138+
onClick={() => onClick(label)}
137139
{...(isAnchor
138140
? {
139-
'aria-label': tab,
140-
title: tab,
141+
'aria-label': label,
142+
title: label,
143+
...(href ? { href } : {}),
141144
}
142145
: { type: 'button', role: 'menuitem' })}
143146
>

0 commit comments

Comments
 (0)