suiss/ui · Pattern
Trail
A navigation trail that shows breadcrumbs on desktop and a back link with history on mobile.
Trail is an open-source pattern from suiss/ui for React. The @esuiss/ui CLI copies its source into your project, so you own the code.
Trail shows where the current page sits in a hierarchy. On desktop it renders a suiss/ui Breadcrumb that links every ancestor and marks the last item as the current page; with maxItems, it keeps the root and the nearest ancestors and folds the rest into an ellipsis.
On mobile (below 48rem, via useIsMobile) it renders a single back link to the parent page, like an iOS navigation bar. When there is more than one ancestor, a long press, right-click, the Context Menu key or Shift+F10 opens a menu of all ancestors, nearest first. Use it on documentation, support and settings pages with nested structure.
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:
-
Add the pieces it builds on: Breadcrumb,
use-mobile. -
Copy the source into
components/patterns/trail.tsx:
- Update the import paths to match your project.
Usage
- Pass
itemsin order from the root to the current page. EachTrailItemhas alabeland an optionalhref; the last item is the current page. - On mobile, nothing renders when there is only one item.
- Use
renderto output links through your router, for example a frameworkLinkelement. It applies to breadcrumb links, the mobile back link and the history menu items.
Examples
Collapsed
Folds the middle of a deep trail into an ellipsis with maxItems.
Back label
Labels the mobile back link Back instead of the parent's name.
Two levels
Shows a trail with one parent and the current page.
API Reference
Trail
The navigation element that renders the breadcrumbs or the mobile back link.
| Prop | Type | Default | Description |
|---|---|---|---|
items | TrailItem[] | Required | The pages from the root to the current page. |
maxItems | number | - | The maximum number of items shown on desktop before the middle collapses into an ellipsis. |
backLabel | string | - | Text for the mobile back link; defaults to the parent's label. |
ellipsisLabel | string | "More" | The accessible label of the collapsed ellipsis. |
render | React.ReactElement | <TrailAnchor /> | The element used to render links. |
Also accepts the props of React.ComponentProps<"nav">.
Accessibility
- On desktop the trail is a navigation landmark named breadcrumb, and the current page has
aria-current="page". - On mobile it is a navigation landmark named Back. When a history menu is available, the back link has
aria-haspopup="menu"andaria-expanded. - The history menu opens from the keyboard with the Context Menu key or Shift+F10.
Notes
Styling hooks: data-slot="trail", trail-back, trail-history and trail-history-item. A long press opens the history only for touch and pen input, and cancels if the pointer moves more than 10 pixels; the press does not also follow the back link.