diff --git a/packages/ui-components/src/Containers/NavBar/__tests__/index.test.jsx b/packages/ui-components/src/Containers/NavBar/__tests__/index.test.jsx new file mode 100644 index 0000000000000..6e1bd8ea1e038 --- /dev/null +++ b/packages/ui-components/src/Containers/NavBar/__tests__/index.test.jsx @@ -0,0 +1,54 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert/strict'; + +import { render, screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; + +import NavBar from '..'; + +const Logo = () => Node.js; + +describe('NavBar', () => { + it('uses a keyboard-accessible button to toggle the mobile navigation', async () => { + const user = userEvent.setup(); + + render( + + Search + + ); + + const menuButton = screen.getByRole('button', { + name: 'Toggle navigation menu', + }); + const navigation = screen + .getByRole('navigation') + .querySelector('#navbar-navigation'); + + assert.ok(menuButton); + assert.ok(navigation); + assert.equal(menuButton.tagName, 'BUTTON'); + assert.equal(menuButton.getAttribute('tabindex'), null); + assert.equal(menuButton.getAttribute('aria-expanded'), 'false'); + assert.match(navigation.className, /\bhidden\b/); + + await user.click(menuButton); + + assert.equal(menuButton.getAttribute('aria-expanded'), 'true'); + assert.match(navigation.className, /\bflex\b/); + + await user.click(menuButton); + + assert.equal(menuButton.getAttribute('aria-expanded'), 'false'); + assert.match(navigation.className, /\bhidden\b/); + }); +}); diff --git a/packages/ui-components/src/Containers/NavBar/index.module.css b/packages/ui-components/src/Containers/NavBar/index.module.css index a7f3a189d5cc3..ce97385d91d96 100644 --- a/packages/ui-components/src/Containers/NavBar/index.module.css +++ b/packages/ui-components/src/Containers/NavBar/index.module.css @@ -41,6 +41,10 @@ .sidebarItemTogglerLabel { @apply block cursor-pointer + appearance-none + border-0 + bg-transparent + p-0 xl:hidden; .navInteractionIcon { @@ -49,16 +53,6 @@ } } - .sidebarItemToggler { - @apply absolute - right-4 - -z-10 - size-6 - -translate-y-[200%] - appearance-none - opacity-0; - } - .main { @apply flex-1 flex-col diff --git a/packages/ui-components/src/Containers/NavBar/index.tsx b/packages/ui-components/src/Containers/NavBar/index.tsx index 0d9404b27c521..b59c4df0dc65f 100644 --- a/packages/ui-components/src/Containers/NavBar/index.tsx +++ b/packages/ui-components/src/Containers/NavBar/index.tsx @@ -1,6 +1,5 @@ import Hamburger from '@heroicons/react/24/solid/Bars3Icon'; import XMark from '@heroicons/react/24/solid/XMarkIcon'; -import * as Label from '@radix-ui/react-label'; import classNames from 'classnames'; import { useState } from 'react'; @@ -55,25 +54,22 @@ const NavBar: FC> = ({ - setIsMenuOpen(previousState => !previousState)} > {navInteractionIcons[isMenuOpen ? 'close' : 'show']} - + - setIsMenuOpen(() => e.target.checked)} - aria-label={sidebarItemTogglerAriaLabel} - tabIndex={-1} - /> -
+