Skip to content

Commit

Permalink
Remove non-tab elements from TabNav focus zone (#2367)
Browse files Browse the repository at this point in the history
* Remove non-tab elements from `TabNav` focus zone

* Create weak-ears-search.md

* Fix lint error in test

* Change from patch to minor
  • Loading branch information
iansan5653 committed Sep 23, 2022
1 parent aeb6152 commit 252a605
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
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

0 comments on commit 252a605

Please sign in to comment.