Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/navigation-focus-trap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@graphcommerce/next-ui': patch
'@graphcommerce/magento-graphcms': patch
'@graphcommerce/magento-open-source': patch
'@graphcommerce/magento-storyblok': patch
---

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.
3 changes: 3 additions & 0 deletions examples/magento-graphcms/components/Layout/LayoutDefault.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type LayoutDefaultProps = {
cartFab?: React.ReactNode
children?: React.ReactNode
noSticky?: boolean
inert?: boolean
sx?: SxProps<Theme>
} & OwnerState

Expand All @@ -42,6 +43,7 @@ export function LayoutDefault(props: LayoutDefaultProps) {
menuFab,
cartFab,
noSticky,
inert,
className,
sx = [],
} = props
Expand All @@ -57,6 +59,7 @@ export function LayoutDefault(props: LayoutDefaultProps) {

return (
<Box
inert={inert}
className={`${classes.root} ${className ?? ''}`}
sx={sxx(
(theme) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -15,6 +16,7 @@ export function LayoutNavigation(props: LayoutNavigationProps) {

const selection = useNavigationSelection()
const router = useRouter()
const navigationOpen = useMotionValueValue(selection, (s) => s !== false)

return (
<>
Expand All @@ -23,6 +25,7 @@ export function LayoutNavigation(props: LayoutNavigationProps) {
<LayoutDefault
{...uiProps}
noSticky={router.asPath.split('?')[0] === '/'}
inert={navigationOpen}
header={<Header menu={menu} selection={selection} />}
footer={<Footer footer={footer} />}
cartFab={<CartFab />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type LayoutDefaultProps = {
cartFab?: React.ReactNode
children?: React.ReactNode
noSticky?: boolean
inert?: boolean
sx?: SxProps<Theme>
} & OwnerState

Expand All @@ -42,6 +43,7 @@ export function LayoutDefault(props: LayoutDefaultProps) {
menuFab,
cartFab,
noSticky,
inert,
className,
sx = [],
} = props
Expand All @@ -57,6 +59,7 @@ export function LayoutDefault(props: LayoutDefaultProps) {

return (
<Box
inert={inert}
className={`${classes.root} ${className ?? ''}`}
sx={sxx(
(theme) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMotionValueValue } from '@graphcommerce/framer-utils'
import { CartFab } from '@graphcommerce/magento-cart'
import { CmsBlock } from '@graphcommerce/magento-cms'
import { NavigationFab, useNavigationSelection } from '@graphcommerce/next-ui'
Expand All @@ -17,6 +18,7 @@ export function LayoutNavigation(props: LayoutNavigationProps) {

const selection = useNavigationSelection()
const router = useRouter()
const navigationOpen = useMotionValueValue(selection, (s) => s !== false)

const footerBlock = cmsBlocks?.items?.find((item) => item?.identifier === 'footer_links_block')

Expand All @@ -27,6 +29,7 @@ export function LayoutNavigation(props: LayoutNavigationProps) {
<LayoutDefault
{...uiProps}
noSticky={router.asPath.split('?')[0] === '/'}
inert={navigationOpen}
header={<Header menu={menu} selection={selection} />}
footer={
<Footer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type LayoutDefaultProps = {
cartFab?: React.ReactNode
children?: React.ReactNode
noSticky?: boolean
inert?: boolean
sx?: SxProps<Theme>
} & OwnerState

Expand All @@ -42,6 +43,7 @@ export function LayoutDefault(props: LayoutDefaultProps) {
menuFab,
cartFab,
noSticky,
inert,
className,
sx = [],
} = props
Expand All @@ -57,6 +59,7 @@ export function LayoutDefault(props: LayoutDefaultProps) {

return (
<Box
inert={inert}
className={`${classes.root} ${className ?? ''}`}
sx={sxx(
(theme) => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -19,6 +20,7 @@ export function LayoutNavigation(props: LayoutNavigationProps) {

const selection = useNavigationSelection()
const router = useRouter()
const navigationOpen = useMotionValueValue(selection, (s) => s !== false)

return (
<GlobalConfigProvider value={globalConfig}>
Expand All @@ -27,6 +29,7 @@ export function LayoutNavigation(props: LayoutNavigationProps) {
<LayoutDefault
{...uiProps}
noSticky={router.asPath.split('?')[0] === '/'}
inert={navigationOpen}
header={<Header menu={menu} selection={selection} />}
footer={<Footer />}
cartFab={<CartFab BadgeProps={{ color: 'secondary' }} />}
Expand Down
2 changes: 1 addition & 1 deletion packages/next-ui/Navigation/components/NavigationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const NavigationItem = React.memo<NavigationItemProps>((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
Expand Down
Loading