suiss/ui · Component
Breadcrumb
A trail of links that shows where the current page sits in the site hierarchy.
Breadcrumb is an open-source component from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
A Breadcrumb is a labelled nav that contains a BreadcrumbList. The list holds BreadcrumbItem parts separated by BreadcrumbSeparator parts. Each item contains either a BreadcrumbLink to an ancestor page or, for the last item, a BreadcrumbPage for the current page. Use BreadcrumbEllipsis inside an item to stand in for collapsed levels.
Use breadcrumbs in deep hierarchies so people can see their location and move up quickly. For top-level navigation between sections, use a navigation menu or tabs.
Installation
CLI
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Manual
- Install the dependencies and add the
cnhelper:
- Copy the source into
components/ui/breadcrumb.tsx:
- Update the import paths to match your project.
Usage
Place a BreadcrumbSeparator between items as its own sibling, not inside a BreadcrumbItem. It renders a caret by default; pass children to use a different separator.
BreadcrumbLink renders an a by default and can render your router's link component instead.
Use the render prop to render your router's link component: render={<Link href="/" />}.
Set asChild on BreadcrumbLink and pass your router's link component as the child.
Pass a render function to BreadcrumbLink that returns your router's link component with the props it receives.
For an icon-only link, such as a home icon, add an aria-label.
Examples
With home icon
Replaces the first link with a home icon and an aria-label.
With ellipsis
Collapses middle levels with BreadcrumbEllipsis.
Custom separator
Uses a slash instead of the default caret separator.
API Reference
Breadcrumb
The nav landmark that wraps the trail.
Also accepts the props of React.ComponentProps<"nav">.
BreadcrumbList
The ordered list of items.
Also accepts the props of React.ComponentProps<"ol">.
BreadcrumbItem
A single step in the trail.
Also accepts the props of React.ComponentProps<"li">.
BreadcrumbLink
A link to an ancestor page.
Also accepts the props of useRender.ComponentProps<"a">.
BreadcrumbPage
The current page, rendered as plain text.
Also accepts the props of React.ComponentProps<"span">.
BreadcrumbSeparator
A decorative divider between items.
Also accepts the props of React.ComponentProps<"li">.
BreadcrumbEllipsis
A placeholder for collapsed levels, with a screen-reader label.
Also accepts the props of React.ComponentProps<"span">.
Accessibility
Breadcrumbrenders anavwitharia-label="breadcrumb".BreadcrumbPagesetsaria-current="page".- Separators have
role="presentation"andaria-hidden="true", so only items are announced as list items. BreadcrumbEllipsishides its icon and includes visually hidden text,Moreby default; pass children to change it.- Only links are in the tab order; the ellipsis and current page are skipped.
Notes
- Styling hooks:
data-slotvalues frombreadcrumbthroughbreadcrumb-ellipsis. - The default caret separator flips in right-to-left layouts.
- Ancestor links use
text-muted-foregroundand the current page usestext-foreground.