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
7 changes: 7 additions & 0 deletions .changeset/navigation-focus-trap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@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` gives its navigation `selection` to `LayoutDefault`, and `LayoutDefault` is `inert` while the menu is open.
11 changes: 9 additions & 2 deletions examples/magento-graphcms/components/Layout/LayoutDefault.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useScrollOffset } from '@graphcommerce/framer-next-pages'
import { dvh } from '@graphcommerce/framer-utils'
import { dvh, useMotionValueValue } from '@graphcommerce/framer-utils'
import {
Container,
extendableComponent,
Expand All @@ -8,9 +8,10 @@ import {
sxx,
useFabSize,
} from '@graphcommerce/next-ui'
import type { NavigationPath, UseNavigationSelection } from '@graphcommerce/next-ui'
import type { SxProps, Theme } from '@mui/material'
import { Box } from '@mui/material'
import { useScroll, useTransform } from 'motion/react'
import { motionValue, useScroll, useTransform } from 'motion/react'

export type LayoutDefaultProps = {
className?: string
Expand All @@ -21,6 +22,7 @@ export type LayoutDefaultProps = {
cartFab?: React.ReactNode
children?: React.ReactNode
noSticky?: boolean
selection?: UseNavigationSelection
sx?: SxProps<Theme>
} & OwnerState

Expand All @@ -33,6 +35,8 @@ const { withState } = extendableComponent<OwnerState, 'LayoutDefault', typeof pa
parts,
)

const closedSelection = motionValue<NavigationPath | false>(false)

export function LayoutDefault(props: LayoutDefaultProps) {
const {
children,
Expand All @@ -42,6 +46,7 @@ export function LayoutDefault(props: LayoutDefaultProps) {
menuFab,
cartFab,
noSticky,
selection,
className,
sx = [],
} = props
Expand All @@ -54,9 +59,11 @@ export function LayoutDefault(props: LayoutDefaultProps) {

const classes = withState({ noSticky })
const fabIconSize = useFabSize('responsive')
const inert = useMotionValueValue(selection ?? closedSelection, (s) => s !== false)

return (
<Box
inert={inert}
className={`${classes.root} ${className ?? ''}`}
sx={sxx(
(theme) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { LayoutDefault, type LayoutDefaultProps } from './LayoutDefault'
import { MenuOverlay } from './MenuOverlay'

export type LayoutNavigationProps = LayoutQuery &
Omit<LayoutDefaultProps, 'footer' | 'header' | 'cartFab' | 'menuFab'>
Omit<LayoutDefaultProps, 'footer' | 'header' | 'cartFab' | 'menuFab' | 'selection'>

export function LayoutNavigation(props: LayoutNavigationProps) {
const { footer, menu, children, ...uiProps } = props
Expand All @@ -23,6 +23,7 @@ export function LayoutNavigation(props: LayoutNavigationProps) {
<LayoutDefault
{...uiProps}
noSticky={router.asPath.split('?')[0] === '/'}
selection={selection}
header={<Header menu={menu} selection={selection} />}
footer={<Footer footer={footer} />}
cartFab={<CartFab />}
Expand Down
11 changes: 9 additions & 2 deletions examples/magento-open-source/components/Layout/LayoutDefault.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useScrollOffset } from '@graphcommerce/framer-next-pages'
import { dvh } from '@graphcommerce/framer-utils'
import { dvh, useMotionValueValue } from '@graphcommerce/framer-utils'
import {
Container,
extendableComponent,
Expand All @@ -8,9 +8,10 @@ import {
sxx,
useFabSize,
} from '@graphcommerce/next-ui'
import type { NavigationPath, UseNavigationSelection } from '@graphcommerce/next-ui'
import type { SxProps, Theme } from '@mui/material'
import { Box } from '@mui/material'
import { useScroll, useTransform } from 'motion/react'
import { motionValue, useScroll, useTransform } from 'motion/react'

export type LayoutDefaultProps = {
className?: string
Expand All @@ -21,6 +22,7 @@ export type LayoutDefaultProps = {
cartFab?: React.ReactNode
children?: React.ReactNode
noSticky?: boolean
selection?: UseNavigationSelection
sx?: SxProps<Theme>
} & OwnerState

Expand All @@ -33,6 +35,8 @@ const { withState } = extendableComponent<OwnerState, 'LayoutDefault', typeof pa
parts,
)

const closedSelection = motionValue<NavigationPath | false>(false)

export function LayoutDefault(props: LayoutDefaultProps) {
const {
children,
Expand All @@ -42,6 +46,7 @@ export function LayoutDefault(props: LayoutDefaultProps) {
menuFab,
cartFab,
noSticky,
selection,
className,
sx = [],
} = props
Expand All @@ -54,9 +59,11 @@ export function LayoutDefault(props: LayoutDefaultProps) {

const classes = withState({ noSticky })
const fabIconSize = useFabSize('responsive')
const inert = useMotionValueValue(selection ?? closedSelection, (s) => s !== false)

return (
<Box
inert={inert}
className={`${classes.root} ${className ?? ''}`}
sx={sxx(
(theme) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LayoutDefault, type LayoutDefaultProps } from './LayoutDefault'
import { MenuOverlay } from './MenuOverlay'

export type LayoutNavigationProps = LayoutQuery &
Omit<LayoutDefaultProps, 'footer' | 'header' | 'cartFab' | 'menuFab'>
Omit<LayoutDefaultProps, 'footer' | 'header' | 'cartFab' | 'menuFab' | 'selection'>

export function LayoutNavigation(props: LayoutNavigationProps) {
const { menu, children, cmsBlocks, ...uiProps } = props
Expand All @@ -27,6 +27,7 @@ export function LayoutNavigation(props: LayoutNavigationProps) {
<LayoutDefault
{...uiProps}
noSticky={router.asPath.split('?')[0] === '/'}
selection={selection}
header={<Header menu={menu} selection={selection} />}
footer={
<Footer
Expand Down
11 changes: 9 additions & 2 deletions examples/magento-storyblok/components/Layout/LayoutDefault.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useScrollOffset } from '@graphcommerce/framer-next-pages'
import { dvh } from '@graphcommerce/framer-utils'
import { dvh, useMotionValueValue } from '@graphcommerce/framer-utils'
import {
Container,
extendableComponent,
Expand All @@ -8,9 +8,10 @@ import {
sxx,
useFabSize,
} from '@graphcommerce/next-ui'
import type { NavigationPath, UseNavigationSelection } from '@graphcommerce/next-ui'
import type { SxProps, Theme } from '@mui/material'
import { Box } from '@mui/material'
import { useScroll, useTransform } from 'motion/react'
import { motionValue, useScroll, useTransform } from 'motion/react'

export type LayoutDefaultProps = {
className?: string
Expand All @@ -21,6 +22,7 @@ export type LayoutDefaultProps = {
cartFab?: React.ReactNode
children?: React.ReactNode
noSticky?: boolean
selection?: UseNavigationSelection
sx?: SxProps<Theme>
} & OwnerState

Expand All @@ -33,6 +35,8 @@ const { withState } = extendableComponent<OwnerState, 'LayoutDefault', typeof pa
parts,
)

const closedSelection = motionValue<NavigationPath | false>(false)

export function LayoutDefault(props: LayoutDefaultProps) {
const {
children,
Expand All @@ -42,6 +46,7 @@ export function LayoutDefault(props: LayoutDefaultProps) {
menuFab,
cartFab,
noSticky,
selection,
className,
sx = [],
} = props
Expand All @@ -54,9 +59,11 @@ export function LayoutDefault(props: LayoutDefaultProps) {

const classes = withState({ noSticky })
const fabIconSize = useFabSize('responsive')
const inert = useMotionValueValue(selection ?? closedSelection, (s) => s !== false)

return (
<Box
inert={inert}
className={`${classes.root} ${className ?? ''}`}
sx={sxx(
(theme) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LayoutDefault, type LayoutDefaultProps } from './LayoutDefault'
import { MenuOverlay } from './MenuOverlay'

export type LayoutNavigationProps = LayoutQuery &
Omit<LayoutDefaultProps, 'footer' | 'header' | 'cartFab' | 'menuFab'> & {
Omit<LayoutDefaultProps, 'footer' | 'header' | 'cartFab' | 'menuFab' | 'selection'> & {
globalConfig?: StoryblokGlobalConfig | null
}

Expand All @@ -27,6 +27,7 @@ export function LayoutNavigation(props: LayoutNavigationProps) {
<LayoutDefault
{...uiProps}
noSticky={router.asPath.split('?')[0] === '/'}
selection={selection}
header={<Header menu={menu} selection={selection} />}
footer={<Footer />}
cartFab={<CartFab BadgeProps={{ color: 'secondary' }} />}
Expand Down
Loading