From 1b22b3ffbbfd79da512e2feac06c905ecbb0cb49 Mon Sep 17 00:00:00 2001 From: Dylan van Nierop <60508913+DivaniNL@users.noreply.github.com> Date: Tue, 3 Nov 2026 09:49:49 +0100 Subject: [PATCH 1/2] Keep keyboard focus inside the open navigation menu, so a keyboard user does not tab into the page behind the menu or into parent columns that are off screen on mobile. --- .changeset/navigation-focus-trap.md | 5 +++++ .../next-ui/Navigation/components/NavigationItem.tsx | 2 +- .../Navigation/components/NavigationOverlay.tsx | 11 +++++++++++ packages/next-ui/Overlay/components/OverlayBase.tsx | 4 ++-- 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 .changeset/navigation-focus-trap.md diff --git a/.changeset/navigation-focus-trap.md b/.changeset/navigation-focus-trap.md new file mode 100644 index 00000000000..7a07a319380 --- /dev/null +++ b/.changeset/navigation-focus-trap.md @@ -0,0 +1,5 @@ +--- +'@graphcommerce/next-ui': patch +--- + +Tab and Shift+Tab stay inside the open `NavigationOverlay`. Only the items of the deepest open column are tab stops, and focus wraps from the last element to the first and back. `overlayPaneProps` of `OverlayBase` accepts the props of a motion `div`. diff --git a/packages/next-ui/Navigation/components/NavigationItem.tsx b/packages/next-ui/Navigation/components/NavigationItem.tsx index 2a92a1a9338..f17c9992864 100644 --- a/packages/next-ui/Navigation/components/NavigationItem.tsx +++ b/packages/next-ui/Navigation/components/NavigationItem.tsx @@ -64,7 +64,7 @@ export const NavigationItem = React.memo((props) => { ) const tabIndex = useMotionValueValue(selection, (s) => - s !== false && s.join(',').includes(parentPath) ? undefined : -1, + s !== false && s.join(',') === parentPath ? undefined : -1, ) const hideItem = hidingRoot && itemPath.length === 1 diff --git a/packages/next-ui/Navigation/components/NavigationOverlay.tsx b/packages/next-ui/Navigation/components/NavigationOverlay.tsx index c7827ba256a..f01cd9e5f3c 100644 --- a/packages/next-ui/Navigation/components/NavigationOverlay.tsx +++ b/packages/next-ui/Navigation/components/NavigationOverlay.tsx @@ -127,6 +127,17 @@ export const NavigationOverlay = React.memo((props: NavigationOverlayProps) => { onLayoutAnimationComplete: () => { animating.set(false) }, + onKeyDown: (e) => { + if (e.key !== 'Tab') return + const tabbable = [ + ...e.currentTarget.querySelectorAll('a[href], button:not(:disabled)'), + ].filter((el) => el.tabIndex >= 0 && el.offsetParent !== null) + const first = tabbable[0] + const last = tabbable[tabbable.length - 1] + if (document.activeElement !== (e.shiftKey ? first : last)) return + e.preventDefault() + ;(e.shiftKey ? last : first)?.focus() + }, }} sx={sxx( { diff --git a/packages/next-ui/Overlay/components/OverlayBase.tsx b/packages/next-ui/Overlay/components/OverlayBase.tsx index 2d1e61fa62c..6896fb1a19e 100644 --- a/packages/next-ui/Overlay/components/OverlayBase.tsx +++ b/packages/next-ui/Overlay/components/OverlayBase.tsx @@ -10,7 +10,7 @@ import { import { sxx } from '@graphcommerce/next-ui' import type { SxProps, Theme } from '@mui/material' import { Box, styled, useTheme, useThemeProps } from '@mui/material' -import type { MotionProps } from 'framer-motion' +import type { HTMLMotionProps } from 'framer-motion' import { m, motionValue, @@ -56,7 +56,7 @@ export type LayoutOverlayBaseProps = { offsetPageY?: number isPresent: boolean safeToRemove?: (() => void) | null | undefined - overlayPaneProps?: MotionProps + overlayPaneProps?: HTMLMotionProps<'div'> disableInert?: boolean /* For `variantSm='left|right' */ From 88be4e4331b574a418e2e955825bfd1785083fc6 Mon Sep 17 00:00:00 2001 From: Dylan van Nierop <60508913+DivaniNL@users.noreply.github.com> Date: Tue, 1 Dec 2026 14:29:53 +0100 Subject: [PATCH 2/2] feat(GCOM-1616): Refactored OnKeyDown event to inert --- .changeset/navigation-focus-trap.md | 5 ++++- .../components/Layout/LayoutDefault.tsx | 3 +++ .../components/Layout/LayoutNavigation.tsx | 3 +++ .../components/Layout/LayoutDefault.tsx | 3 +++ .../components/Layout/LayoutNavigation.tsx | 3 +++ .../components/Layout/LayoutDefault.tsx | 3 +++ .../components/Layout/LayoutNavigation.tsx | 3 +++ .../Navigation/components/NavigationOverlay.tsx | 11 ----------- packages/next-ui/Overlay/components/OverlayBase.tsx | 4 ++-- 9 files changed, 24 insertions(+), 14 deletions(-) diff --git a/.changeset/navigation-focus-trap.md b/.changeset/navigation-focus-trap.md index 7a07a319380..1abf24155cb 100644 --- a/.changeset/navigation-focus-trap.md +++ b/.changeset/navigation-focus-trap.md @@ -1,5 +1,8 @@ --- '@graphcommerce/next-ui': patch +'@graphcommerce/magento-graphcms': patch +'@graphcommerce/magento-open-source': patch +'@graphcommerce/magento-storyblok': patch --- -Tab and Shift+Tab stay inside the open `NavigationOverlay`. Only the items of the deepest open column are tab stops, and focus wraps from the last element to the first and back. `overlayPaneProps` of `OverlayBase` accepts the props of a motion `div`. +Keyboard focus and screen readers stay out of the page behind the open `NavigationOverlay`. `LayoutNavigation` makes `LayoutDefault` `inert` while the menu is open, and only the items of the deepest open column are tab stops. diff --git a/examples/magento-graphcms/components/Layout/LayoutDefault.tsx b/examples/magento-graphcms/components/Layout/LayoutDefault.tsx index e3e380ce0ab..eedd3e450f6 100644 --- a/examples/magento-graphcms/components/Layout/LayoutDefault.tsx +++ b/examples/magento-graphcms/components/Layout/LayoutDefault.tsx @@ -21,6 +21,7 @@ export type LayoutDefaultProps = { cartFab?: React.ReactNode children?: React.ReactNode noSticky?: boolean + inert?: boolean sx?: SxProps } & OwnerState @@ -42,6 +43,7 @@ export function LayoutDefault(props: LayoutDefaultProps) { menuFab, cartFab, noSticky, + inert, className, sx = [], } = props @@ -57,6 +59,7 @@ export function LayoutDefault(props: LayoutDefaultProps) { return ( ({ diff --git a/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx b/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx index 56bcb676333..022de10854f 100644 --- a/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx +++ b/examples/magento-graphcms/components/Layout/LayoutNavigation.tsx @@ -1,3 +1,4 @@ +import { useMotionValueValue } from '@graphcommerce/framer-utils' import { CartFab } from '@graphcommerce/magento-cart' import { NavigationFab, useNavigationSelection } from '@graphcommerce/next-ui' import { useRouter } from 'next/router' @@ -15,6 +16,7 @@ export function LayoutNavigation(props: LayoutNavigationProps) { const selection = useNavigationSelection() const router = useRouter() + const navigationOpen = useMotionValueValue(selection, (s) => s !== false) return ( <> @@ -23,6 +25,7 @@ export function LayoutNavigation(props: LayoutNavigationProps) { } footer={