Skip to content

Breadcrumb

The trail of pages above the one being read. Use it wherever a screen sits inside a hierarchy the reader may want to climb back out of.

tsx
import { Breadcrumb, BreadcrumbItem } from 'neba';

<Breadcrumb>
  <BreadcrumbItem href="/">Home</BreadcrumbItem>
  <BreadcrumbItem href="/projects">Projects</BreadcrumbItem>
  <BreadcrumbItem>Settings</BreadcrumbItem>
</Breadcrumb>;

Props

PropTypeDefaultDescription
localestringBCP 47 tag naming the nav landmark and the … button
sizeshared'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Height and type scale
colorshared'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info''primary'Semantic colour role. Arbitrary colour values are not accepted
densityshared'default' | 'compact''default'The space between steps only
separator'chevron' | 'arrow' | 'slash' | 'dot' | ReactNode'chevron'What is drawn between two steps: one of the four names, or any node. chevron and arrow say "and then", slash says "path", dot says "peers of one thing"
maxItemsnumberHow many steps to show before the middle is folded away behind a `…`. Left out, the whole trail is shown however long it gets
itemsBeforeCollapsenumber1How many steps stay at the front of a folded trail
itemsAfterCollapsenumber1How many stay at the end
expandablebooleantrueWhether pressing the `…` unfolds the trail in place. Turn it off to leave the fold as a plain mark
labelstringThe name the trail is announced by, as the nav's aria-label
expandLabelstringWhat the `…` is announced as
structuredDatabooleanfalseAlso emits a schema.org BreadcrumbList as JSON-LD, folded steps included
baseUrlstringWhat relative hrefs are resolved against for structuredData: the site's origin
childrenReactNodeThe BreadcrumbItems

Every other <nav> attribute passes through. The shared axes are in prop conventions.

PropTypeDefaultDescription
hrefstringRenders the step as a link
onClickMouseEventHandler<HTMLElement>Fires when the step is pressed. Renders it as a button when there is no href
startIconReactNodeContent before the label: a home glyph, a repository avatar
endIconReactNodeContent after the label
currentbooleanMarks this step as the page you are on, which stops it being a link. The last step is the current one on its own, so this is only needed for a trail that ends somewhere the reader is not, and setting it anywhere takes the mark off the last step, because only one step in a trail can be it
disabledbooleanfalseUnavailable. Keeps its place in the trail
childrenReactNodeThe step's label

Every other <li> attribute passes through to the step.

Examples

separator

separator takes one of four names (chevron, arrow, slash, dot), or any node. The two that point turn back under RTL.

maxItems

A trail past maxItems steps folds its middle away behind a , which puts it back when pressed. itemsBeforeCollapse and itemsAfterCollapse decide how many stay at each end; both default to 1. expandable={false} leaves the fold as a plain mark.

The fold only happens when it removes more than one step, since standing in for a single step makes the trail longer rather than shorter.

The current step

The last step is the page you are on, so it is not a link even when it is given an href. current on an earlier step moves that mark, and takes it off the last one.

startIcon

size

structuredData

Correct markup alone is not what puts a path under a search result: the structured data is. Turning structuredData on emits a schema.org BreadcrumbList in a <script type="application/ld+json"> beside the trail. baseUrl is what relative hrefs are resolved against, since a search engine wants an absolute URL.

Every step goes in, including the ones a maxItems fold is hiding: what is collapsed is a matter of how much room the row has, and the path is the path either way. A step with no href is emitted without an item, which is the last step's usual case.

It is off by default. A page can only have one BreadcrumbList, and a great many apps already emit theirs from an SEO layer of their own.

Accessibility

  • The trail is a nav named by label, which defaults to Breadcrumb, holding an ordered list.
  • The current step carries aria-current="page", and exactly one step in a trail ever does.
  • The separators are aria-hidden, so a reader hears the steps and not the punctuation between them.
  • The is a real button named by expandLabel. With expandable={false} it is a mark and is hidden from readers.
  • locale names the nav landmark and the button; label and expandLabel write them out instead.
  • structuredData is not an accessibility feature: it is read by a crawler and draws nothing on screen.

Released under the MIT License