@@ -5,6 +5,8 @@ import {UnderlineNavContext} from './UnderlineNavContext'
55import { ActionMenu } from '../ActionMenu'
66import { ActionList } from '../ActionList'
77import { useResizeObserver , ResizeObserverEntry } from '../hooks/useResizeObserver'
8+ import { useFocusZone } from '../hooks/useFocusZone'
9+ import { FocusKeys } from '@primer/behaviors'
810
911type Overflow = 'auto' | 'menu' | 'scroll'
1012type ChildWidthArray = Array < { width : number } >
@@ -84,6 +86,16 @@ export const UnderlineNav = forwardRef(
8486 ) => {
8587 const backupRef = useRef < HTMLElement > ( null )
8688 const newRef = ( forwardedRef ?? backupRef ) as MutableRefObject < HTMLElement >
89+
90+ // This might change if we decide tab through the navigation items rather than navigationg with the arrow keys.
91+ // TBD. In the meantime keeping it as a menu with the focus trap.
92+ // ref: https://www.w3.org/WAI/ARIA/apg/example-index/menubar/menubar-navigation.html (Keyboard Support)
93+ useFocusZone ( {
94+ containerRef : backupRef ,
95+ bindKeys : FocusKeys . ArrowHorizontal | FocusKeys . HomeAndEnd ,
96+ focusOutBehavior : 'wrap'
97+ } )
98+
8799 const styles = {
88100 display : 'flex' ,
89101 justifyContent : align === 'right' ? 'flex-end' : 'space-between' ,
@@ -144,7 +156,7 @@ export const UnderlineNav = forwardRef(
144156 < UnderlineNavContext . Provider
145157 value = { { setChildrenWidth, selectedLink, setSelectedLink, afterSelect : afterSelectHandler , variant} }
146158 >
147- < Box as = { as } sx = { merge ( styles , sxProp ) } aria-label = { label } ref = { newRef } >
159+ < Box tabIndex = { 0 } as = { as } sx = { merge ( styles , sxProp ) } aria-label = { label } ref = { newRef } >
148160 < Box as = "ul" sx = { merge < BetterSystemStyleObject > ( overflowStyles , ulStyles ) } >
149161 { responsiveProps . items }
150162 </ Box >
0 commit comments