Skip to main content

Navigation

Site navigation with URL synchronization and roving tabindex.

Usage

<w-nav label="Main navigation">
<w-slot item><w-link href="/home">Home</w-link></w-slot>
<w-slot item><w-link href="/about">About</w-link></w-slot>
<w-slot item><w-link href="/contact">Contact</w-link></w-slot>
</w-nav>

Props

PropTypeDefaultDescription
labelstring"Navigation"Accessible label
orientation"horizontal" | "vertical""horizontal"Navigation layout
valuestring""Currently active item value

Slots

SlotElementDescription
itemw-link / buttonNavigation items (uses href or data-value for value)

Events

EventDetailDescription
change{ value }Fired when active item changes

Keyboard

KeyAction
ArrowRight / ArrowDownFocus next item
ArrowLeft / ArrowUpFocus previous item
HomeFocus first item
EndFocus last item

Examples

Vertical Navigation

<w-nav label="Sidebar" orientation="vertical">
<w-slot item><w-link href="/dashboard">Dashboard</w-link></w-slot>
<w-slot item><w-link href="/profile">Profile</w-link></w-slot>
<w-slot item><w-link href="/settings">Settings</w-link></w-slot>
</w-nav>

With Data Values (Buttons)

<w-nav label="Options" value="option1">
<w-slot item><button data-value="option1">Option 1</button></w-slot>
<w-slot item><button data-value="option2">Option 2</button></w-slot>
</w-nav>
<w-nav label="Resources">
<w-slot item><w-link href="/docs">Docs</w-link></w-slot>
<w-slot item><w-link href="https://github.com" external>GitHub</w-link></w-slot>
</w-nav>

Styling

w-nav {
display: flex;
gap: 4px;
background: #f5f5f5;
border-radius: 4px;
}

w-nav[orientation="vertical"] {
flex-direction: column;
}

w-nav w-slot[item] {
padding: 12px 16px;
text-decoration: none;
color: inherit;
}

/* Active state */
w-nav [aria-current="page"] {
background-color: #0056b3;
color: white;
}

With Views

Navigation works with w-view for single-page routing:

<w-nav label="Navigation">
<w-slot item><w-link href="/home">Home</w-link></w-slot>
<w-slot item><w-link href="/about">About</w-link></w-slot>
</w-nav>

<w-view path="/home">
<h1>Home Page</h1>
</w-view>

<w-view path="/about">
<h1>About Page</h1>
</w-view>

Accessibility

  • role="navigation" on container
  • aria-label from label prop
  • aria-current="page" on active item
  • Roving tabindex for keyboard navigation
  • Works with both w-link and buttons