Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,6 @@ const TabNavList = React.forwardRef<HTMLDivElement, TabNavListProps>((props, ref
<ResizeObserver onResize={onListHolderResize}>
<div
ref={useComposeRef(ref, containerRef)}
role="tablist"
aria-orientation={tabPositionTopOrBottom ? 'horizontal' : 'vertical'}
className={clsx(`${prefixCls}-nav`, className, tabsClassNames?.header)}
style={{ ...styles?.header, ...style }}
onKeyDown={() => {
Expand All @@ -635,6 +633,8 @@ const TabNavList = React.forwardRef<HTMLDivElement, TabNavListProps>((props, ref
<ResizeObserver onResize={onListHolderResize}>
<div
ref={tabListRef}
role="tablist"
aria-orientation={tabPositionTopOrBottom ? 'horizontal' : 'vertical'}
className={`${prefixCls}-nav-list`}
style={{
transform: `translate(${transformLeft}px, ${transformTop}px)`,
Expand Down
8 changes: 4 additions & 4 deletions tests/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ exports[`Tabs.Basic Normal 1`] = `
class="rc-tabs rc-tabs-top"
>
<div
aria-orientation="horizontal"
class="rc-tabs-nav"
role="tablist"
>
<div
class="rc-tabs-nav-wrap rc-tabs-nav-wrap-ping-right"
>
<div
aria-orientation="horizontal"
class="rc-tabs-nav-list"
role="tablist"
style="transform: translate(0px, 0px);"
>
<div
Expand Down Expand Up @@ -108,15 +108,15 @@ exports[`Tabs.Basic Skip invalidate children 1`] = `
class="rc-tabs rc-tabs-top"
>
<div
aria-orientation="horizontal"
class="rc-tabs-nav"
role="tablist"
>
<div
class="rc-tabs-nav-wrap"
>
<div
aria-orientation="horizontal"
class="rc-tabs-nav-list"
role="tablist"
style="transform: translate(0px, 0px);"
>
<div
Expand Down
23 changes: 23 additions & 0 deletions tests/accessibility.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,27 @@ describe('Tabs.Accessibility', () => {
expect(queryByRole('tab', { name: /Tab1/i })).toBeInTheDocument();
expect(queryByRole('tab', { name: /Tab3/i })).toBeInTheDocument();
});

it('should scope tablist role to the nav list so extra content is not owned by the tablist', () => {
const { container, getByRole } = render(
createTabs({
tabBarExtraContent: {
left: <button type="button">Left Extra</button>,
right: <button type="button">Right Extra</button>,
},
}),
);

const navList = getByRole('tablist');
expect(navList).toHaveClass('rc-tabs-nav-list');
expect(container.querySelector('.rc-tabs-nav')).not.toHaveAttribute('role');

// Extra content and operations buttons live outside the tablist element,
// so the tablist only owns tab nodes (axe: aria-required-children).
// Confirm both extra buttons rendered first, so the querySelector below
// cannot pass vacuously when extra content fails to mount.
getByRole('button', { name: 'Left Extra' });
getByRole('button', { name: 'Right Extra' });
expect(navList.querySelector('button')).toBeNull();
});
});