@c2n/navigation-menu
v0.0.24
Published
`c2-navigation-menu` is a site navigation bar: a row of items that are either plain links or triggers opening a panel of `c2-navigation-menu-link` rows below the bar.
Maintainers
Readme
@c2n/navigation-menu
c2-navigation-menu is a site navigation bar: a row of items that are either plain links or triggers opening a panel
of c2-navigation-menu-link rows below the bar.
<c2-navigation-menu aria-label="Main">
<c2-navigation-menu-item value="products">
Products
<div class="grid" slot="panel">
<c2-navigation-menu-link href="/analytics">Analytics<span slot="description">Realtime dashboards</span></c2-navigation-menu-link>
<c2-navigation-menu-link href="/warehouse">Warehouse<span slot="description">Columnar storage</span></c2-navigation-menu-link>
</div>
</c2-navigation-menu-item>
<c2-navigation-menu-item value="docs" href="/docs">Docs</c2-navigation-menu-item>
<c2-navigation-menu-item value="pricing" href="/pricing" current>Pricing</c2-navigation-menu-item>
</c2-navigation-menu>valueis the item whose panel is open (''when closed) andvalue-changereports every change;open(value)andclose()drive it from code.- Panels open on hover after
open-delayand closeclose-delayafter the pointer leaves both the item and the panel.open-on="click"ignores hover entirely.panel-anchor="menu"lines every panel up with the bar for mega panels. - Items:
href,target,current(aria-current="page"plus the indicator line),disabled,placement, and thepanelslot that turns the item into a trigger. - A trigger follows its panel: while one of its rows is the current page (
current, or anyaria-current), the item setscurrent-groupon itself and takes the__currentstyling, so the closed bar still shows the active section. It tracks later changes, so an SPA route change moves the group on its own. mode="mobile"swaps the row for a single button that opens the whole navigation as one hierarchy: links are rows, panel items are headings with their rows underneath.collapsiblemakes those groups open one at a time (the open one isvalue, and the list opens on the group holding the current page). Themobile-triggerslot replaces the button,mobile-labelnames the default one, and--c2-navigation-menu__mobile-trigger--*themes it.mobile-breakpoint="800"lets the bar switch itself at or below that viewport width;modereflects, so the current layout is in the DOM. Leave it unset to drivemodeyourself from whatever knows better.- Panel width: each panel is as wide as its own content, with
--c2-navigation-menu-item__panel--min-width(260px) as a floor. That variable belongs to the item — set it on the bar and every panel of that bar gets the same width. - The panel is a
c2-overlaypopover on the top layer, so a header withoverflow: hiddennever clips it. Dismissal is the bar's own: a press outside it or Escape closes the panel. - Keyboard: every item is a tab stop; ArrowLeft / ArrowRight and Home / End walk the bar (and keep browsing panels while one is open), ArrowDown / Enter / Space opens the panel and moves into it, Escape closes and returns focus.
- Theming:
--c2-navigation-menu--*(the bar),--c2-navigation-menu-item--*(the triggers, with__hover,__expanded,__current,__indicatorand__panelparts) and--c2-navigation-menu-link--*(the panel rows).
