39 — Navigation
Nav List
The links of a sidebar, in groups, each with its icon and a count, the current page marked.
Calendar
Installation
pnpm dlx @human-kit/design add nav-listnpx @human-kit/design add nav-listyarn dlx @human-kit/design add nav-listbunx @human-kit/design add nav-listThe command copies the files to src/lib/components/ui/nav-list. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as NavList from '$lib/components/ui/nav-list';
import { page } from '$app/state';
</script>
<NavList.Root>
<NavList.Group>
<NavList.Item href="/inbox" current={page.url.pathname === '/inbox'}>Inbox</NavList.Item>
<NavList.Item href="/calendar" current={page.url.pathname === '/calendar'}>Calendar</NavList.Item>
</NavList.Group>
</NavList.Root> Guidelines
- Use it for the links of a sidebar: places to go, not actions. An action in the sidebar ("New patient") is a
Button.Root. - Mark the page being shown with
current. Only one link at a time, and only for the page itself, not for its parent section. - Give every link an icon or none: a column with icons on some rows reads as broken. In a sidebar that folds, icons are required, since they are all that stays.
- Use
countfor what waits there and asks to be seen: unread messages, pending results. Not for totals that only grow. - Name a group with
headingonce there are more than a handful of links. The first group, the main places, usually needs none.
Accessibility
- The root is a
<nav>landmark named bylabel, "Main" by default. Give another name to a second navigation on the page. - Each group is a real
<ul>of<li>, named by its heading througharia-labelledby, so a screen reader says how many links it holds. - Every item is a native
<a href>, reached with Tab and opened with Enter.currentsetsaria-current="page". - In a folded sidebar the names leave the eye but stay for a screen reader, and a tooltip gives them to the pointer.
- The icons are hidden from assistive technology: the name says it all.
API reference
NavList.Root
| Prop | Type | Default |
|---|---|---|
label | string The landmark's name: a page can have more than one navigation. | 'Main' |
Plus every attribute of a <nav>.
NavList.Group
| Prop | Type | Default |
|---|---|---|
heading | string The group's heading. Its links are read as a list named by it. | — |
Plus every attribute of a <div>, on the wrapper around the list.
NavList.Item
| Prop | Type | Default |
|---|---|---|
href | string Where it goes. Required. | — |
current | boolean The page this link leads to is the one shown. Sets | false |
icon | Component The icon before the name. | — |
count | number How many wait there: unread, pending. At the far end. | — |
Plus every attribute of a native <a>.