Reference
NavigationMenu
A site's main navigation whose entries open panels (a mega menu) as disclosures: one open at a time, the arrow keys along the row, Down into a panel, Escape, a press outside or the focus leaving closes it.
NavigationMenu(label: String) { … }
Since 6.2.0
label
Example
NavigationMenu(label: "Main") {
NavigationMenu.Item("Learn") {
Stack(gap: .sm) {
Link("The guide", to: "/learn")
Link("Data and requests", to: "/learn/15-data")
Link("Recipes", to: "/recipes")
}
}
NavigationMenu.Item("Reference") {
Stack(gap: .sm) {
Link("Components", to: "/reference")
Link("Diagnostics", to: "/errors")
}
}
NavigationMenu.Link("Playground", to: "/playground")
NavigationMenu.Link("Showcase", to: "/showcase")
}
Only links, no panels
NavigationMenu(label: "Site") {
NavigationMenu.Link("Home", to: "/")
NavigationMenu.Link("Reference", to: "/reference").prefix
}
Props
| Prop | Type | Unset | Meaning |
|---|---|---|---|
label: | String |
| The navigation's accessible name ( |
Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.
Flags and cases
A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.
No flags of its own.
Events
Every element also takes the props, the events and the attribute families listed on every element.
Slots
children
Parts
The parts of NavigationMenu are written under its name, inside it. Each is described here, with what it takes.
NavigationMenu.Item
An entry that opens a panel: its words are its button, its block the panel.
NavigationMenu.Item(_ label: String) { … }
| Prop | Type | Unset | Meaning |
|---|---|---|---|
label | String (positional) | — | The words on the button that opens its panel; the block is the panel |
NavigationMenu.Link
An entry that is a link, beside the ones that open panels.
NavigationMenu.Link(_ label: String, to: Path, active: Enum)
| Prop | Type | Unset | Meaning |
|---|---|---|---|
label | String (positional) | — | The link's words |
to: | Path (required) | — | The route it links to, navigated in place; while it matches the current route it carries |
active: | one of its cases | exact match | How it decides it is the current page: unset, the route must equal
|
.prefix
Drawn for it
What NavigationMenu draws itself, by the class a stylesheet can select. They are not written.
| Part | Class | Meaning |
|---|---|---|
NavigationMenu.List | — | Its entries. |
NavigationMenu.Trigger | — | An entry's button. |
NavigationMenu.Panel | — | An entry's panel. |
Renders with the class wf-nav-menu, stable across releases, so a stylesheet may target it.