Breadcrumbs
Breadcrumbs is the trail of pages above the one the user is on. It is a <nav> landmark named "Breadcrumb" with an ordered list of links, and the last one says it is the current page.
Anatomy
Breadcrumbs.Root is the <nav> landmark. Breadcrumbs.List is the <ol>, and each Breadcrumbs.Item is an <li> with a Breadcrumbs.Link in it. Breadcrumbs.Separator is the sign after a link, in the item.
<script>
import { Breadcrumbs } from '@human-kit/ui';
</script>
<Breadcrumbs.Root>
<Breadcrumbs.List>
<Breadcrumbs.Item>
<Breadcrumbs.Link href="/">Home</Breadcrumbs.Link>
<Breadcrumbs.Separator />
</Breadcrumbs.Item>
<Breadcrumbs.Item>
<Breadcrumbs.Link href="/docs">Docs</Breadcrumbs.Link>
<Breadcrumbs.Separator />
</Breadcrumbs.Item>
<Breadcrumbs.Item>
<Breadcrumbs.Link current>Breadcrumbs</Breadcrumbs.Link>
</Breadcrumbs.Item>
</Breadcrumbs.List>
</Breadcrumbs.Root>The current page
Give current to the last link. It gets aria-current="page", and data-current for your styles. It can keep its href: a link to the page the user is on is a way to reload it. Without an href, the link is a <span>: plain text, and not a tab stop.
The separator
Breadcrumbs.Separator renders a slash without children, or your own sign. It is aria-hidden: the list already separates the items, and a slash read aloud between each two is noise. Put it in the item, after the link, on every item but the last. The list then holds pages only, and the count a screen reader says is the count of pages.
A disabled link
disabled takes the href away from a link. The text stays, with aria-disabled and data-disabled, and the link is out of the tab order on its own. Use it for a page the user cannot open now.
A long trail
Give maxItems to fold the middle of a long trail. The first page and the last maxItems - 1 stay in view. A Breadcrumbs.Ellipsis in the list stands for the rest: put it after the first item. It is a button named "Show N more pages", in the locale of LocaleProvider. A press unfolds the trail, and the focus moves to the first page that comes into view. bind:expanded reads the state, and folds the trail again.
The name
The landmark is named "Breadcrumb", in the locale of LocaleProvider. Give aria-label for a name of your own, and always when the page has two sets of breadcrumbs. Two landmarks with one name are one to the screen reader.
Usage guidelines
- Put the trail near the top of the page, before the main content.
- Keep the page the user is on as the last item. A trail without its end leaves the user to guess where they are.
- Keep the separator out of the last item.
- Use
disabledand not a missinghreffor a page that exists and is out of reach now: the reader then knows the difference.
Accessibility
Breadcrumbs.Rootis a<nav>witharia-label="Breadcrumb", in the locale ofLocaleProvider. A screen reader user finds it in the list of landmarks, apart from the main navigation.Breadcrumbs.Listis an<ol>of<li>: a screen reader says the count and the position of each page. It hasrole="list"in writing, for the browsers that drop a list withlist-style: none.Breadcrumbs.Linkwithcurrenthasaria-current="page". Without anhref, or withdisabled, it is a<span>: not a link, and not a tab stop.Breadcrumbs.Separatorisaria-hidden.Breadcrumbs.Ellipsisis a button with a name that says how many pages it hides. After the press, the focus lands on the first of them. The button is gone, and a focus left on nothing is a focus lost.- The keyboard moves through the links with
Tab. Breadcrumbs are links on a page, not a widget with arrow keys.
API reference
Root
The `<nav>` landmark, named "Breadcrumb" in the locale of `LocaleProvider`.
* required. Native HTML attributes of the underlying element are also accepted.
List
The `<ol>` of the trail, with `role="list"` in writing. The order of the items is the order of the pages.
* required. Native HTML attributes of the underlying element are also accepted.
Item
One page of the trail, as an `<li>`. It holds a link, and a separator after the link on every item but the last.
* required. Native HTML attributes of the underlying element are also accepted.
Link
The page, as an `<a>` with an `href`, or a `<span>` without one. `current` marks the page the user is on.
* required. Native HTML attributes of the underlying element are also accepted.
Ellipsis
The button that stands for the folded middle of a long trail, in an `<li>`. It renders only while the trail is folded, named "Show N more pages".
* required. Native HTML attributes of the underlying element are also accepted.
Separator
The sign between two pages, hidden from the screen reader. A slash without children.
* required. Native HTML attributes of the underlying element are also accepted.