Skip to content

Commit e3592d9

Browse files
authored
ActionMenu: Ensure uncontrolled ActionMenu is handled properly when fullscreen (#7408)
1 parent 4072e44 commit e3592d9

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

.changeset/fast-pots-say.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
ActionMenu: Ensures that uncontrolled ActionMenu(s) retain tab-focus when fullscreen

packages/react/src/ActionMenu/ActionMenu.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)