suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Patterns19
  • Overview
  • Action Bar
  • Action Menu
  • App Shell
  • Command Palette
  • Confirm
  • Context Actions
  • Date Picker
  • Flyout
  • Modal
  • Navbar
  • Paged List
  • Panel
  • Picker
  • Preview
  • Search Picker
  • Segment Picker
  • Split View
  • Table List
  • Trail

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.

import * as React from "react"
import { Trail, type TrailItem } from "@/components/patterns/trail"

type Page = { label: string; parent?: string; children: string[] }

const pages: Record<string, Page> = {
  support: { label: "Support", children: ["account", "billing"] },
  account: {
    label: "Account",
    parent: "support",
    children: ["security", "profile"],
  },
  billing: { label: "Billing", parent: "support", children: [] },
  security: {
    label: "Security",
    parent: "account",

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. On mobile it renders a single back link to the parent page, with a menu of all ancestors.

Use it on documentation, support and settings pages with nested structure.

Installation

$ pnpm dlx shadcn@latest add @esuiss/trail

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add patterns trail
  1. Install the following dependencies and add the cn helper:
$ pnpm add @base-ui/react @phosphor-icons/react
  1. Add the pieces it builds on: Breadcrumb, use-mobile.

  2. Copy and paste the following code into your project.

components/patterns/trail.tsx
"use client"

import { Menu as MenuPrimitive } from "@base-ui/react/menu"
import { useRender } from "@base-ui/react/use-render"
import { ArrowBendUpLeftIcon, CaretLeftIcon } from "@phosphor-icons/react"
import * as React from "react"
import {
  Breadcrumb,
  BreadcrumbEllipsis,
  BreadcrumbItem,
  BreadcrumbLink,
  BreadcrumbList,
  BreadcrumbPage,
  BreadcrumbSeparator,
} from "@/components/ui/breadcrumb"
import { useIsMobile } from "@/hooks/use-mobile"
  1. Update the import paths to match your project setup.

Usage

import { Trail, type TrailItem } from "@/components/patterns/trail"
const items: TrailItem[] = [
  { label: "Support", href: "/support" },
  { label: "Account", href: "/support/account" },
  { label: "Turn on two-factor authentication" },
]

<Trail items={items} />

Examples

Collapsed

Set maxItems to cap the items shown on desktop. The trail keeps the root and the nearest ancestors and folds the rest into an ellipsis.

import { Trail, type TrailItem } from "@/components/patterns/trail"

const deep: TrailItem[] = [
  { label: "Support", href: "#support" },
  { label: "Products", href: "#products" },
  { label: "Workspace", href: "#workspace" },
  { label: "Billing", href: "#billing" },
  { label: "Invoices", href: "#invoices" },
  { label: "Download an invoice as PDF" },
]

export default function TrailCollapsed() {
  return <Trail items={deep} maxItems={4} />
}

Back label

Set backLabel to label the mobile back link Back instead of the parent's name.

import { Trail, type TrailItem } from "@/components/patterns/trail"

const article: TrailItem[] = [
  { label: "Support", href: "#support" },
  { label: "Account", href: "#account" },
  { label: "Security", href: "#security" },
  { label: "Turn on two-factor authentication" },
]

export default function TrailBackLabel() {
  return <Trail items={article} backLabel="Back" />
}

Two levels

Shows a trail with one parent and the current page.

import { Trail, type TrailItem } from "@/components/patterns/trail"

const article: TrailItem[] = [
  { label: "Support", href: "#support" },
  { label: "Account", href: "#account" },
  { label: "Security", href: "#security" },
  { label: "Turn on two-factor authentication" },
]

export default function TrailTwoLevels() {
  return <Trail items={article.slice(2)} />
}

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" and aria-expanded.
  • The history menu opens from the keyboard with the Context Menu key or Shift+F10.

API Reference

Trail

The navigation element that renders the breadcrumbs or the mobile back link.

PropTypeDefault
itemsTrailItem[]Required
maxItemsnumber-
backLabelstring-
ellipsisLabelstring"More"
PropTypeDefault
renderReact.ReactElementA plain a
PropTypeDefault
render(props: React.ComponentProps<"a">) => React.ReactNodeA plain a

Also accepts the props of React.ComponentProps<"nav">.

Pass items in order from the root to the current page. Each TrailItem has a label and an optional href; the last item is the current page. ellipsisLabel is the accessible label of the collapsed ellipsis.

On mobile (below 48rem, via useIsMobile) the trail renders a back link to the parent page, and nothing when there is only one item. 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. A long press opens it only for touch and pen input, cancels if the pointer moves more than 10 pixels, and does not also follow the back link.

Use render to output links through your router, for example a framework Link element. It applies to breadcrumb links, the mobile back link and the history menu items.

Pass a render function to output links through your router. It receives the link props, including href, and applies to breadcrumb links, the mobile back link and the history menu items.

Each part sets a data-slot, such as trail, trail-back or trail-history-item, for styling.

NextInteractionsPreviousTable List

On this page

  1. 01Installation
  2. 02Usage
  3. 03Examples
    • Collapsed
    • Back label
    • Two levels
  4. 04Accessibility
  5. 05API Reference
    • Trail