Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove non-tab elements from TabNav focus zone #2367

Merged
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
5 changes: 5 additions & 0 deletions .changeset/weak-ears-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": minor
---

Remove non-tab elements from `TabNav` focus zone
3 changes: 2 additions & 1 deletion src/TabNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ function TabNav({children, 'aria-label': ariaLabel, ...rest}: TabNavProps) {
containerRef: customContainerRef,
bindKeys: FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd,
focusOutBehavior: 'wrap',
focusInStrategy: customStrategy
focusInStrategy: customStrategy,
focusableElementFilter: element => element.getAttribute('role') === 'tab'
})
return (
<TabNavBase {...rest} ref={navRef as React.RefObject<HTMLDivElement>}>
Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/TabNav.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('TabNav', () => {
</TabNav.Link>
<TabNav.Link id="middle" href="#" selected>
Middle
<a href="https://example.com">Focuseable Link</a>
</TabNav.Link>
<TabNav.Link id="last" href="#">
Last
Expand Down Expand Up @@ -102,12 +103,16 @@ describe('TabNav', () => {
const user = userEvent.setup()
const {getByText, getByRole} = HTMLRender(tabNavMarkup)
const middleTab = getByText('Middle')
const link = getByText('Focuseable Link')
const button = getByRole('button')

await user.click(middleTab)
expect(middleTab).toHaveFocus()
await user.tab()

expect(link).toHaveFocus()
await user.tab()

expect(button).toHaveFocus()
})

Expand Down