From f2f3443b17323c61494c0b70d602ff49fd3f27ce Mon Sep 17 00:00:00 2001 From: Simon Rapilly <85184231+srapilly@users.noreply.github.com> Date: Fri, 27 Oct 2023 16:12:38 -0400 Subject: [PATCH 1/2] Add aria-expanded for mobile navigation dropdown --- .../src/theme/NavbarItem/DropdownNavbarItem.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx index bc315a1fa750..f150a53d0c4b 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx @@ -146,6 +146,8 @@ function DropdownNavbarItemMobile({ 'menu__link menu__link--sublist menu__link--sublist-caret', className, )} + href="#" + aria-expanded={!collapsed} {...props} onClick={(e) => { e.preventDefault(); From c055219cf8e64a500e4c8d346fa5a37727a0274c Mon Sep 17 00:00:00 2001 From: Simon Rapilly <85184231+srapilly@users.noreply.github.com> Date: Fri, 27 Oct 2023 16:33:25 -0400 Subject: [PATCH 2/2] handle keyUp and keyDown --- .../src/theme/NavbarItem/DropdownNavbarItem.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx index f150a53d0c4b..4d7db6ebd91f 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem.tsx @@ -142,12 +142,25 @@ function DropdownNavbarItemMobile({ })}> { + if (e.code === 'Space') { + toggleCollapsed(); + } + }} + onKeyDown={(e) => { + if (e.code === 'Space') { + e.preventDefault(); + } + if (e.code === 'Enter') { + toggleCollapsed(); + } + }} {...props} onClick={(e) => { e.preventDefault();