@@ -285,12 +285,25 @@ const Overlay: FCWithSlotMarker<React.PropsWithChildren<MenuOverlayProps>> = ({
285285 } = React . useContext ( MenuContext ) as MandateProps < MenuContextProps , 'anchorRef' >
286286
287287 const containerRef = React . useRef < HTMLDivElement > ( null )
288- useMenuKeyboardNavigation ( open , onClose , containerRef , anchorRef , isSubmenu )
289288 const isNarrow = useResponsiveValue ( { narrow : true } , false )
290- const responsiveVariant = useResponsiveValue ( variant , { regular : 'anchored' , narrow : 'anchored' } )
291289
292290 const isNarrowFullscreen = ! ! isNarrow && variant . narrow === 'fullscreen'
293291
292+ const handleClose : MenuCloseHandler = React . useCallback (
293+ gesture => {
294+ // In narrow fullscreen mode, don't close on tab, let focus stay in the menu
295+ if ( isNarrowFullscreen && gesture === 'tab' ) {
296+ return
297+ }
298+ onClose ?.( gesture )
299+ } ,
300+ [ isNarrowFullscreen , onClose ] ,
301+ )
302+
303+ useMenuKeyboardNavigation ( open , handleClose , containerRef , anchorRef , isSubmenu )
304+
305+ const responsiveVariant = useResponsiveValue ( variant , { regular : 'anchored' , narrow : 'anchored' } )
306+
294307 // If the menu anchor is an icon button, we need to label the menu by tooltip that also labelled the anchor.
295308 const [ anchorAriaLabelledby , setAnchorAriaLabelledby ] = useState < null | string > ( null )
296309 useEffect ( ( ) => {
@@ -311,7 +324,7 @@ const Overlay: FCWithSlotMarker<React.PropsWithChildren<MenuOverlayProps>> = ({
311324 anchorId = { anchorId }
312325 open = { open }
313326 onOpen = { onOpen }
314- onClose = { onClose }
327+ onClose = { handleClose }
315328 align = { align }
316329 side = { side ?? ( isSubmenu ? 'outside-right' : 'outside-bottom' ) }
317330 overlayProps = { overlayProps }
0 commit comments