Breadcrumbs
The trail of pages above the current one, its middle folded when it runs long.
Installation
pnpm dlx @human-kit/design add breadcrumbsnpx @human-kit/design add breadcrumbsyarn dlx @human-kit/design add breadcrumbsbunx @human-kit/design add breadcrumbsThe command copies the files to src/lib/components/ui/breadcrumbs. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as Breadcrumbs from '$lib/components/ui/breadcrumbs';
</script>
<Breadcrumbs.Root>
<Breadcrumbs.List>
<Breadcrumbs.Item>
<Breadcrumbs.Link href="/patients">Patients</Breadcrumbs.Link>
<Breadcrumbs.Separator />
</Breadcrumbs.Item>
<Breadcrumbs.Item>
<Breadcrumbs.Link current>Ana María Ruiz</Breadcrumbs.Link>
</Breadcrumbs.Item>
</Breadcrumbs.List>
</Breadcrumbs.Root> Examples
Folded trail
Past maxItems, the middle of the trail folds into a "…" button: the first page and the last maxItems - 1 stay. Put a Breadcrumbs.Ellipsis after the first item; a press unfolds the trail.
Guidelines
- Use breadcrumbs on a page two levels or more down a hierarchy, above its title, to show where it sits and to go back up.
- End the trail with the page the user is on, marked
currentand without anhref. - Put a
Breadcrumbs.Separatorafter the link of every item but the last. - Set
maxItemswhen a trail can grow long, so it stays on one line. Fold it to three or four. - Breadcrumbs show where a page is, not the steps that led to it. For a flow in steps, use a stepper.
Accessibility
- The root is a
<nav>landmark named "Breadcrumb". Give anaria-labelof your own when the page has two trails. - The list is an
<ol>, so a screen reader says how many pages it holds and where each one is. - The
currentlink carriesaria-current="page". Without anhref, or withdisabled, a link is plain text and leaves the tab order. - The separators are hidden from screen readers: the list already parts the pages.
- The "…" is a button named "Show N more pages". After it is pressed, the focus lands on the first page that comes into view.
API reference
Breadcrumbs.Root
| Prop | Type | Default |
|---|---|---|
maxItems | number How many items the trail shows before its middle folds. Without it, the trail never folds. | — |
expanded | boolean Whether the user unfolded the trail. Bindable, to fold it again. | false |
onExpandedChange | (expanded: boolean) => void Called when the trail unfolds or folds. | — |
aria-label | string The name of the landmark, in the locale of the page. | 'Breadcrumb' |
element | HTMLElement | null The rendered | — |
Plus every attribute of a <nav>. It draws nothing of its own.
Breadcrumbs.List
| Prop | Type | Default |
|---|---|---|
element | HTMLOListElement | null The rendered | — |
Plus every attribute of an <ol>.
Breadcrumbs.Item
| Prop | Type | Default |
|---|---|---|
element | HTMLLIElement | null The rendered | — |
Plus every attribute of an <li>. It holds a link and, after it, a separator.
Breadcrumbs.Link
| Prop | Type | Default |
|---|---|---|
href | string The address of the page. Without it, the link is plain text. | — |
current | boolean Marks the page the user is on: full ink, and | false |
disabled | boolean Keeps the text and drops the | false |
element | HTMLAnchorElement | HTMLSpanElement | null The rendered | — |
Plus every attribute of an <a>.
Breadcrumbs.Separator
| Prop | Type | Default |
|---|---|---|
children | Snippet Your own sign in place of the chevron. The chevron turns round on a right-to-left page. | — |
Plus every attribute of a <span>.
Breadcrumbs.Ellipsis
| Prop | Type | Default |
|---|---|---|
children | Snippet Your own content in place of the three dots. | — |
separator | Snippet The sign after the button. Without it, a | — |
aria-label | string The name of the button. | 'Show N more pages' |
element | HTMLButtonElement | null The rendered button, while the trail is folded. Bindable. | — |
Plus every attribute of a <button>. It shows only while the trail is folded.