oakoss/ui
Components

Breadcrumb

A trail of links from the top of the site to the current page.

SourceReact Aria

Installation

npx shadcn@latest add @oakoss/breadcrumb

Usage

import {
  Breadcrumb,
  BreadcrumbItem,
  BreadcrumbLink,
  BreadcrumbList,
  BreadcrumbPage,
} from '#/components/ui/navigation/breadcrumb';

<Breadcrumb>
  <BreadcrumbList>
    <BreadcrumbItem>
      <BreadcrumbLink href="/">Home</BreadcrumbLink>
    </BreadcrumbItem>
    <BreadcrumbItem>
      <BreadcrumbPage>Settings</BreadcrumbPage>
    </BreadcrumbItem>
  </BreadcrumbList>
</Breadcrumb>;

Links take an href, and follow your router when the app sets up React Aria's RouterProvider.

Examples

Ellipsis

BreadcrumbEllipsis stands in for the levels left out of a long trail. It's decorative, so screen readers skip it.

Accessibility

React Aria renders the trail as an ordered list named "Breadcrumbs" in the user's language. The last item is the current page: its link gets aria-current="page" and is disabled, so it leaves the Tab order.

This component adds:

  • Landmark: the trail sits in a nav landmark named after the list, so it takes the same translated name. Give Breadcrumb an aria-label or aria-labelledby to name it yourself.
  • Current page: it's semibold as well as darker, so the cue isn't color alone.
  • Separators: the chevrons between items are hidden from screen readers, and point the other way right to left.
  • Focus: links show the focus outline on keyboard focus, and none at rest, so Windows High Contrast draws no box around each one.
  • Target size: links are text height, spaced so each still meets the 24px minimum.
KeyAction
TabMoves to the next link, skipping the current page
EnterFollows the focused link

React Aria adds no keys. Follows the WAI-ARIA breadcrumb pattern.

API

A nav element, and accepts all its props.

Data attributes

AttributePresent when
data-slotAlways breadcrumb

Extends React Aria's Breadcrumbs, and accepts all its props except id, which names the nav. onAction gets the key of the item whose link was pressed.

Data attributes

AttributePresent when
data-slotAlways breadcrumb-list

Extends React Aria's Breadcrumb, and renders the separator after every item but the last.

Props

Prop

Type

Also accepts all React Aria Breadcrumb props.

Data attributes

AttributePresent when
data-slotAlways breadcrumb-item; the separator is breadcrumb-separator
data-currentIt's the last item
data-disabledIt's the last item, or the list is disabled

Extend React Aria's Link, and accept all its props. BreadcrumbPage is styled as the current page; a BreadcrumbLink in the last item takes the same look.

Data attributes

AttributePresent when
data-slotAlways breadcrumb-link or breadcrumb-page
data-currentIt's in the last item
data-disabledIt's in the last item, or the list is disabled
data-hoveredA pointer hovers it
data-pressedIt's being pressed
data-focusedIt has focus
data-focus-visibleIt has keyboard focus

A span hidden from screen readers, and accepts all its props.

Data attributes

AttributePresent when
data-slotAlways breadcrumb-ellipsis