Top nav
A horizontal app bar: brand, primary links, actions. Folds its links into a
drawer below a width of its own. ds::top-nav and ds::top-nav-item.
Anatomy
header.group/topnav[data-ds-menu once Alpine runs] sticky? bordered?
├── a[href=#skipTo].sr-only.focus:not-sr-only skipTo only
├── div.@container/topnav
│ └── div (container width)
│ ├── button[aria-haspopup=dialog][aria-expanded] menu: hidden until Alpine and narrow
│ ├── div brand slot
│ ├── nav[aria-label] > ul the items; hidden when narrow with Alpine
│ └── div actions slot
└── ds::drawer (left, sm) collapseAt only
└── template x-if > nav[aria-label] > ul[data-ds-top-nav-menu] the items again, only while open
li top-nav-item
├── a[aria-current=page?] icon · label · badge a link
└── details a group: a disclosure
├── summary[data-current?] icon · label · badge · chevron
└── ul[data-ds-top-nav-panel][x-ds-anchor] > li top-nav-item …
The container is the inner bar, not the header: a size container applies
layout containment, which would make the header the containing block of the
drawer's fixed layer. collapseAt is a closed set of literal classes
(40, 48, 64, 80rem); the items hide and the button shows only once Alpine has
marked the header, so with no Alpine the items wrap and nothing is lost.
An item reads where it is from its ancestors (in-data-[ds-top-nav-menu]:,
in-data-[ds-top-nav-panel]:): a pill in the bar, a full-width row in the
drawer, a menu-like row in a group's panel. In the drawer a group's panel
opens in place (static); x-ds-anchor is told not to place it there.
States
| Current | aria-current="page" on the link; tinted. A group is tinted when a link in its slot is current (read from the rendered slot) |
| Narrow, Alpine | links hidden, menu button shown; the drawer holds them |
| Narrow, no Alpine | links wrap onto further rows |
| Group open | the native open; Alpine adds Escape, press outside and focus leaving |
Accessibility
| Role | header > nav named by label > list of links. A group is a details disclosure (its summary is a button with an expanded state). No menubar, no menu |
| Name | links by their text; the menu button by menuLabel; the drawer by its title (menuLabel) |
| Keyboard | Tab through links and groups; Enter or Space opens a group, Tab walks its links; Escape closes it and focuses its summary; Tab past the last link closes it |
| Focus | every stop draws the system ring (inside in the drawer and the panel); the drawer traps focus and returns it to the menu button |
Skip link: skipTo renders "Skip to content" first in the bar, shown on
focus, linking to the main content's id.
Do not
- Do not use
role="menubar"for site navigation: it promises arrow keys and application-style menus that links are not. - Do not nest groups more than one level.
- Do not transform or filter the header (
backdrop-blur): it becomes the drawer's containing block. - Do not render the items twice yourself for the phone: the drawer draws them only while open.
From the package repo: edit this page on GitHub.