Skip to content

Disclosure Navigation

A site navigation whose buttons show and hide submenus. <cinq-disclosure-navigation> updates aria-expanded and hidden, keeps one branch open at a time, adds the keyboard support of the APG example, and can open the submenus on hover.

Follows the WAI-ARIA Authoring Practices disclosure navigation example. Inspired by @19h47/disclosure-navigation.

Terminal window
pnpm add @agencecinq/disclosure-navigation

Import once:

import "@agencecinq/disclosure-navigation";

Then write the markup: the component only adds interactivity.

HTML is the source of truth. The component does not set a missing aria-expanded, hidden or label, nor warns about them. Run an a11y linter (axe, Lighthouse) to catch invalid markup.

<cinq-disclosure-navigation data-hover>
<nav aria-label="Main">
<ul>
<li><a href="/">Home</a></li>
<li>
<button type="button" aria-expanded="false" aria-controls="about-menu">About</button>
<ul id="about-menu" hidden>
<li><a href="/about/overview">Overview</a></li>
<li><a href="/about/team" aria-current="page">Team</a></li>
</ul>
</li>
</ul>
</nav>
</cinq-disclosure-navigation>
Attribute On Role
aria-expanded <button> Required. The state. A button without it is ignored. The component updates it.
aria-controls <button> Required. ID(s) of the submenu(s), inside the host.
hidden Submenu Present while collapsed, or hidden="until-found" to keep its links searchable.
aria-label <nav> Names the landmark when the page has more than one navigation.
aria-current <a> Optional: marks the current page.

To render a submenu open, write aria-expanded="true" on its button and leave out hidden. A submenu can hold buttons with their own submenus: opening one keeps its parents open and closes the other branches. In a submenu, the arrow keys follow the reading order of its visible items, as Tab does: Enter on a nested button opens its submenu, ArrowDown moves into it, and Escape closes it and focuses its button.

Attribute On Effect
data-hover Host A mouse opens the submenus on hover.
data-arrow-keys="false" Host Leaves the arrow, Home and End keys to the browser.

Both are read on each interaction: setting or removing them needs no call.

With data-hover, a mouse opens a submenu when it enters its button, and closes it when it leaves the button and the submenu. Touch and pen keep the click.

  • The click still works. The first click after the mouse opened a submenu keeps it open, as the user meant to open it. The next click closes it.
  • No gap. The pointer goes from the button to the submenu: leave no space between them, or fill it with the submenu’s padding.
  • Escape closes it wherever the focus is, as WCAG 1.4.13 asks of content shown on hover.

Write hidden="until-found" on collapsed submenus and their links stay searchable. When find in page or a link to a fragment reveals a submenu, the component opens it, nested ones included, and keeps until-found when it closes again. Tailwind 4’s preflight leaves until-found out of its [hidden] rule; Bootstrap’s Reboot does not.

Method Description
init() Binds listeners. Runs on connect. Call destroy() first if already bound.
destroy() Removes listeners. Runs on disconnect. The markup stays as it is.
open($button) Opens the submenu of $button and closes the other branches.
close($button?) Closes the submenu of $button, or every open submenu.
toggle($button) Opens or closes the submenu of $button.

Buttons are read from the DOM on each interaction: adding or removing items needs no call.

The component fires the platform’s ToggleEvents at each submenu, the way a popover does.

Event Cancelable Description
beforetoggle When the submenu opens Fired before the DOM changes.
toggle No Fired after, in a later task. Changes in a row coalesce into one event.

event.target is the submenu, event.source its button. The events do not bubble: listen on the submenu, or on the host in the capture phase.

const $navigation = document.querySelector("cinq-disclosure-navigation");
$navigation.addEventListener(
"toggle",
(event) => console.log(event.target.id, event.newState),
{ capture: true },
);
Key Focus on Action
Enter / Space Button Toggles its submenu.
Escape Submenu Closes the innermost one and focuses its button.
Escape Button, top-level link or outside Closes the open submenu.
ArrowDown Expanded top-level button Moves focus to the first item of its submenu.
Arrow keys Top-level item Previous or next button or link, wrapping.
Arrow keys Submenu item Previous or next visible item, open nested submenus included, wrapping.
Home / End Top-level or submenu item First or last item.

Moving focus out of the navigation closes the open submenu. Inside a dialog, Escape closes the submenu first, then the dialog. In a right-to-left context, ArrowLeft and ArrowRight swap.

  • Not a menubar: keep <nav>, <button> and <a>, without menu / menuitem roles. The APG reserves the menubar pattern for application menus.
  • Parents that are also pages: an element can’t be both a link and a button. Put a link to the parent page in its submenu, or a link and a separate button side by side.
  • Hover only adds: keyboard and screen reader users open the same submenus with the buttons.

Chrome and Edge 135, Firefox 136 and Safari 17. event.source needs Chrome 140, Firefox 145 and Safari 26.5. hidden="until-found" needs Chrome 102, Firefox 139 and Safari 26.2, and acts as hidden elsewhere.

Guild hall navigation

One branch open at a time, a nested submenu under Quests, arrow keys in reading order and Escape to close: Enter on Dungeons, then ArrowDown, reaches the Tomb of Horrors. With data-hover, the mouse opens the submenus: the first click after it keeps them open. The Armory ishidden="until-found": search the page for “Vorpal” and it opens.

Last event: -

Accessible Web Components, built on the platform.

© 2026 CINQ

Released under the MIT License.