Skip to the content
human-kit design
39 — Navigation

Nav List

The links of a sidebar, in groups, each with its icon and a count, the current page marked.

Installation

pnpm dlx @human-kit/design add nav-list
npx @human-kit/design add nav-list
yarn dlx @human-kit/design add nav-list
bunx @human-kit/design add nav-list

The 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 count for what waits there and asks to be seen: unread messages, pending results. Not for totals that only grow.
  • Name a group with heading once 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 by label, "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 through aria-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. current sets aria-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

PropTypeDefault
labelstring

The landmark's name: a page can have more than one navigation.

'Main'

Plus every attribute of a <nav>.

NavList.Group

PropTypeDefault
headingstring

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

PropTypeDefault
hrefstring

Where it goes. Required.

—
currentboolean

The page this link leads to is the one shown. Sets aria-current="page".

false
iconComponent

The icon before the name.

—
countnumber

How many wait there: unread, pending. At the far end.

—

Plus every attribute of a native <a>.