Nav
A row or column of links with a bar that slides to the current one.
SourcePackage @weft-js/warpPlayground
Preview
tsx
import { state } from '@weft-js/core'import { Nav } from '@weft-js/warp'export function Across() { const at = state('Deploys') const go = (e: Event, name: string) => { e.preventDefault(); at.value = name } return ( <Nav label="Project"> {PAGES.map(name => <a key={name} href={`#${name}`} aria-current={at.value === name ? 'page' : undefined} onClick={e => go(e, name)}>{name}</a>)} </Nav> )}const PAGES = ['Overview', 'Deploys', 'Logs', 'Settings']Installation
npm install @weft-js/warpUsage
tsx
import { Nav } from '@weft-js/warp'A column
axis="y" puts the bar beside the links.
App header
Put Nav links beside a title, and set aria-current on the link for the current page.
Settings pages
Use axis="y" to stack the links down the side, with aria-current marking the current page.
Table of contents
spy lights the link whose heading is at the top of the window. Scroll to watch it move.
When to use
Playground
Axis
import { Nav } from '@weft-js/warp'<Nav label="Project"> <a href="/overview">Overview</a> <a href="/deploys" aria-current="page">Deploys</a> <a href="/logs">Logs</a> <a href="/settings">Settings</a></Nav>Accessibility
- Tab
- Moves between links
- Enter
- Follows the link
labelnames the landmark, so a page with two navs can tell them apart.- The links are plain anchors.
aria-currentis what announces the page, as well as moving the bar.
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | The name of the navigation landmark. |
axis | "x" | "y" | 'x' | x for a row, y for a column. |
spy | boolean | false | Follow the headings the links point at, for a table of contents. |
children | unknown | — | What it contains. |
Parts
Every element carries a stable name, so you can style it from your own CSS: [data-scope="nav"] [data-part="indicator"]
indicator