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

Example

wf

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

wf

NavigationMenu(label: "Site") { NavigationMenu.Link("Home", to: "/") NavigationMenu.Link("Reference", to: "/reference").prefix }

Props

Props of NavigationMenu
PropTypeUnsetMeaning

label:

String

Main

The navigation's accessible name (aria-label on its <nav>)

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.

An entry that opens a panel: its words are its button, its block the panel.

NavigationMenu.Item(_ label: String) { … }
Props of NavigationMenu.Item
PropTypeUnsetMeaning

label

String (positional)

—

The words on the button that opens its panel; the block is the panel

An entry that is a link, beside the ones that open panels.

NavigationMenu.Link(_ label: String, to: Path, active: Enum)
Props of NavigationMenu.Link
PropTypeUnsetMeaning

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 and aria-current="page"

active:

one of its cases

exact match

How it decides it is the current page: unset, the route must equal to; .prefix also matches routes beneath it. Written as a flag, .prefix, or by name, active: .prefix.

  • .prefix: Also current on every route beneath to: /docs for /docs/forms

.prefix

Drawn for it

What NavigationMenu draws itself, by the class a stylesheet can select. They are not written.

Drawn for it
PartClassMeaning

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.