The navigation bar, or header, is the single most important element for orienting people inside a website. Designing a navigation menu that is responsive on mobile devices and at the same time fully usable with a keyboard or assistive technology requires specific accessibility patterns. Many common mobile menus make the mistake of hiding links visually without removing them from the tab order, forcing keyboard users to navigate through invisible elements.
This component solves that structural problem by combining CSS classes for positioning with JavaScript for controlling the accessibility attributes. The mobile menu trigger (the hamburger icon) carries the aria-expanded attribute (set to true or false depending on state) and references the navigation menu's ID through aria-controls. When the menu is closed on mobile it is set to display: none or taken out of the flow via visibility, making sure it can't receive focus by mistake.
To improve the experience further, keyboard event handling is built in: pressing Escape automatically closes an open menu and returns focus to the button that opened it. The link matching the current page is marked with aria-current="page", giving a clear semantic signal of where the user is, both visually (through dedicated stylesheets) and to screen readers.