Skip to content

Commit

Permalink
Add aria-label to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
fhlavac committed Nov 21, 2023
1 parent 4225e81 commit 744f480
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/module/src/HorizontalNav/HorizontalNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { Tabs, Tab, TabProps, TabTitleText, TabsProps as TabsPropsPF } from '@pa
type TabsProps = Omit<TabsPropsPF, 'children' | 'ref' | 'onSelect'>;

export interface HorizontalNavProps extends TabsProps {
/** aria-label for all tabs */
ariaLabel?: string;
/** Navigation tabs */
tabs: Omit<TabProps, 'ref'>[];
/** Callback to handle tab selection */
onTabSelect?: (event: React.MouseEvent<HTMLElement, MouseEvent>, eventKey: number | string) => void;
};

const HorizontalNav: React.FunctionComponent<HorizontalNavProps> = ({
ariaLabel,
tabs,
defaultActiveKey,
onTabSelect,
Expand All @@ -28,13 +31,15 @@ const HorizontalNav: React.FunctionComponent<HorizontalNavProps> = ({
onTabSelect?.(e, eventKey);
}}
role="nav"
aria-label={ariaLabel}
{...props}
>
{tabs.map((tab) => (
<Tab
{...tab}
title={[ 'string', 'number', 'boolean' ].includes(typeof tab.title) ? <TabTitleText>{tab.title}</TabTitleText> : tab.title}
key={tab.eventKey}
aria-label={`Tab ${tab.eventKey}`}
>
{tab.children}
</Tab>
Expand Down

0 comments on commit 744f480

Please sign in to comment.