From e8aa2016b7f5780e28cd7a70ea39b0c90a58caf2 Mon Sep 17 00:00:00 2001 From: marcoskolodny Date: Wed, 13 Nov 2024 12:26:51 +0100 Subject: [PATCH] fix initial screen reader focus in mobile and paddings in burger menu in tablet --- src/navigation-bar.tsx | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/navigation-bar.tsx b/src/navigation-bar.tsx index e1f0df5cf..5fc78f82f 100644 --- a/src/navigation-bar.tsx +++ b/src/navigation-bar.tsx @@ -32,6 +32,7 @@ import {ButtonLink} from './button'; import {Grid, GridItem} from './grid'; import {DOWN, ESC, UP} from './utils/keys'; import {debounce, isEqual} from './utils/helpers'; +import NegativeBox from './negative-box'; import type {ExclusifyUnion} from './utils/utility-types'; import type {Variant} from './theme-variant-context'; @@ -362,7 +363,7 @@ const MainNavigationBarBurgerSection = ({ columns.map((column, columnIndex) => ( {column.title} - + {column.items.map( ({title: itemTitle, ...itemInteractiveProps}, itemIndex) => ( @@ -378,7 +379,7 @@ const MainNavigationBarBurgerSection = ({ ) )} - + )) )} @@ -404,7 +405,7 @@ const MainNavigationBarBurgerMenu = ({ disableFocusTrap: boolean; setDisableFocusTrap: (value: boolean) => void; }) => { - const {isDarkMode} = useTheme(); + const {isDarkMode, texts, t} = useTheme(); const [openedSection, setOpenedSection] = React.useState(-1); const [isSubMenuOpen, setIsSubMenuOpen] = React.useState(false); const [subMenuStatus, dispatch] = React.useReducer(burgerMenuReducer, 'closed'); @@ -428,6 +429,19 @@ const MainNavigationBarBurgerMenu = ({ return () => clearTimeout(id); }, [isSubMenuOpen, menuAnimationDuration]); + const sectionContainerRef = React.useRef(null); + + React.useEffect(() => { + // Make screen reader focus on back button when opening any section's menu + if (subMenuStatus === 'opening') { + const sectionBackButtonElement = sectionContainerRef.current?.querySelector( + `button[aria-label="${texts.backNavigationBar || t(tokens.backNavigationBar)}"]` + ); + + sectionBackButtonElement?.focus(); + } + }, [subMenuStatus, t, texts]); + return ( @@ -489,6 +503,7 @@ const MainNavigationBarBurgerMenu = ({