An open source design system that's fully customizable and agent ready
TypeScript
fix(TabList): keep TabMenu arrow keys out of the tab strip (#7323)
zakelstorm4789178a2e77
diff --git a/.changeset/keep-tabmenu-arrow-key-navigation-from-moving-fo-wzt7.md b/.changeset/keep-tabmenu-arrow-key-navigation-from-moving-fo-wzt7.mdnew file mode 100644index 0000000000..bc1f13a08e--- /dev/null+++ b/.changeset/keep-tabmenu-arrow-key-navigation-from-moving-fo-wzt7.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] Keep TabMenu arrow-key navigation from moving focus to the outer tab strip.+@korkt-kimdiff --git a/packages/core/src/TabList/TabList.test.tsx b/packages/core/src/TabList/TabList.test.tsxindex 698726bde4..b35200f389 100644--- a/packages/core/src/TabList/TabList.test.tsx+++ b/packages/core/src/TabList/TabList.test.tsx@@ -946,6 +946,49 @@ describe('TabMenu keyboard navigation (roving tabindex)', () => {expect(analytics).toHaveFocus();});+ it('still navigates when the tablist is inside a popover', async () => {+ const user = userEvent.setup();+ render(+ <div popover="manual">+ <TabList value="home" onChange={() => {}} role="tablist">+ <Tab value="home" label="Home" panelId="home-panel" />+ <Tab value="settings" label="Settings" panelId="settings-panel" />+ </TabList>+ </div>,+ );++ screen.getByRole('tab', {name: 'Home', hidden: true}).focus();+ await user.keyboard('{ArrowRight}');+ expect(+ screen.getByRole('tab', {name: 'Settings', hidden: true}),+ ).toHaveFocus();+ });++ it('leaves horizontal arrows to the open menu', async () => {+ const user = userEvent.setup();+ render(+ <TabList value="home" onChange={() => {}}>+ <Tab value="home" label="Home" />+ <TabMenu label="More" options={menuOptions} />+ </TabList>,+ );++ const trigger = screen.getByRole('button', {name: 'More'});+ await user.click(trigger);+ const item = screen.getByRole('menuitemradio', {+ name: 'Reports',+ hidden: true,+ });+ item.focus();++ fireEvent.keyDown(item, {key: 'ArrowRight'});+ expect(item).toHaveFocus();++ fireEvent.keyDown(item, {key: 'ArrowLeft'});+ expect(item).toHaveFocus();+ expect(trigger).toHaveAttribute('aria-expanded', 'true');+ });+it('moves the roving tab stop with arrow navigation', async () => {const user = userEvent.setup();render(diff --git a/packages/core/src/TabList/TabList.tsx b/packages/core/src/TabList/TabList.tsxindex 778271228b..c15b2279fe 100644--- a/packages/core/src/TabList/TabList.tsx+++ b/packages/core/src/TabList/TabList.tsx@@ -448,6 +448,7 @@ export function TabList({// the first enabled stop when none is tabbable.const {listRef, handleKeyDown, handleFocus} = useListFocus<HTMLElement>({itemSelector: TAB_STOP_SELECTOR,+ boundarySelector: '.astryx-tab-list, [popover]',orientation: isTabList ? 'horizontal' : 'both',hasRovingTabIndex: true,});