Skip to main content

Breadcrumb

Show a resource hierarchy and mark its current page.

Props
Slots

Anatomy#

Breadcrumb [component; slot=root; <nav>]
└── list [slot]
    ├── item [slot]
    │   ├── link [slot]
    │   │   ├── leading [slot]
    │   │   └── label [slot]
    │   └── page [slot]
    │       ├── leading [slot]
    │       └── label [slot]
    └── separator [slot]

Usage#

Use Breadcrumb to show where a resource sits in a navigation hierarchy. Keep ancestor destinations as links and render the current page as a non-link item. For in-page section switching, use Tabs instead.

import { Breadcrumb } from 'moraine'

export function Example() {
  return <Breadcrumb items={[{ label: 'Home', href: '/' }, { label: 'Settings' }]} />
}

Items and current page#

Use href for navigable ancestors, with target, rel, and onClick as needed. The last item is the current page by default; set active on another item to mark it instead (the first active item wins). The current page renders as a span with aria-current="page". Disabled ancestors render without href or onClick and expose aria-disabled="true". disabled has no effect on the current page.

<Breadcrumb
  items={[
    { label: 'Home', href: '/' },
    { label: 'Components', href: '/button' },
    { label: 'Breadcrumb' },
  ]}
/>
<Breadcrumb
  items={[
    { label: 'Home', href: '/', icon: 'i-lucide:home' },
    { label: 'Private workspace', href: '/workspace', disabled: true },
    { label: 'Activity', active: true },
    { label: 'Archived' },
  ]}
/>

separator accepts an icon name, an element, or a component, and defaults to icon-chevron-right. It is hidden from assistive technology. wrap (default true) lets a long trail break onto extra lines in a narrow column; with wrap={false}, the trail stays on one line and clips any overflow. The <nav> is labeled breadcrumb by default. Set aria-label, or translations={{ label }}, to change it.

Pass itemRender to replace each item’s link or page element, for example with a router link. The component receives { item, index, active, disabled } and is responsible for aria-current and disabled handling.

<Breadcrumb
  items={items}
  itemRender={(ctx) => (
    <A href={ctx.item.href ?? '#'} aria-current={ctx.active ? 'page' : undefined}>
      {ctx.item.label}
    </A>
  )}
/>

Examples#

Trail to the current page#

Link ancestors and leave the last item as the current page.

import { Breadcrumb } from 'moraine'
import type { BreadcrumbT } from 'moraine'

const BREADCRUMB_ITEMS = [
  { label: 'Home', href: '/' },
  { label: 'Components', href: '/button' },
  { label: 'Breadcrumb' },
] satisfies BreadcrumbT.Item[]

export function ItemsPage() {
  return (
    <div class="max-w-md w-full">
      <Breadcrumb items={BREADCRUMB_ITEMS} />
    </div>
  )
}

Locked ancestor with a custom separator#

Keep a disabled private workspace in the trail. Replace the chevron with a slash.

import { Breadcrumb } from 'moraine'

export function CustomSeparatorDisabled() {
  return (
    <Breadcrumb
      separator={() => <span>/</span>}
      classes={{
        separator: 'size-unset',
      }}
      items={[
        { label: 'Home', href: '/', icon: 'i-lucide:home' },
        { label: 'Private workspace', href: '/breadcrumb', disabled: true, icon: 'i-lucide:lock' },
        { label: 'Activity' },
      ]}
    />
  )
}

Long trail in a narrow column#

Leave wrap on so the trail can break across lines. Set wrap={false} to keep every item on one line.

import { Breadcrumb, Switch } from 'moraine'
import { createSignal } from 'solid-js'

export function Wrapping() {
  const [wrap, setWrap] = createSignal(true)

  return (
    <div class="min-w-0 w-full space-y-4">
      <Switch checked={wrap()} onCheckedChange={setWrap} label="Wrap items" />

      <div
        class="p-4 border border-border rounded-lg"
        classList={{ 'w-full max-w-sm': wrap(), 'w-max': !wrap() }}
      >
        <Breadcrumb
          wrap={wrap()}
          classes={{
            list: wrap() ? undefined : 'overflow-visible',
            item: wrap() ? undefined : 'shrink-0',
          }}
          items={[
            { label: 'Home', href: '#' },
            { label: 'Workspace', href: '#' },
            { label: 'Projects', href: '#' },
            { label: 'Design system', href: '#' },
            { label: 'Components', href: '#' },
            { label: 'Breadcrumb' },
          ]}
        />
      </div>

      <p class="text-sm text-muted-foreground">
        Turn wrapping off to show the full trail on a single line.
      </p>
    </div>
  )
}

Custom item rendering#

Use itemRender to render each item yourself for router links or custom chip styling. It receives item, index, active, and disabled.

import { Breadcrumb } from 'moraine'
import type { BreadcrumbT } from 'moraine'

const TRAIL = [
  { label: 'Documentation', href: '/docs' },
  { label: 'Components', href: '/components' },
  { label: 'Breadcrumb' },
] satisfies BreadcrumbT.Item[]

export function CustomItemRender() {
  return (
    <div class="max-w-md w-full">
      <Breadcrumb
        items={TRAIL}
        itemRender={(props) => (
          <a
            href={props.item.href}
            class="text-xs px-2 py-1 rounded-md inline-flex gap-1.5 transition-colors items-center"
            classList={{
              'bg-primary/10 text-primary font-medium': props.active,
              'text-muted-foreground hover:text-foreground': !props.active,
            }}
          >
            <span>{props.item.label}</span>
          </a>
        )}
      />
    </div>
  )
}

API Reference#

Attributes#

Attributes
data-disabled
Slot: breadcrumb-link
Description: Present when the component, slot, or item is disabled.
data-current
Slot: breadcrumb-page
Description: Present when the item represents the current location or step.

Props#

Props for the Breadcrumb component. Renders a <nav> element by default.

Prop