仕組み
A <nav> with one non-wrapping <ol>; separators sit inside each <li> and are aria-hidden, so the item count matches the visible levels. Every level is a pill: links get a hover pill, the current page is weight 600 in the body colour. When there are more levels than maxItems the middle folds into a round “…” chip (it turns ink while open) that opens a menu (absolute, no portal). When space runs short, short names stay put and longer ones shrink and truncate, with the full text in title.
向いている場面
- Pages three or more levels deep, where people need to know where they are and jump up in one step.
- In a top bar title position (size sm) or above the page title in the content area.
- Admin pages that go from a list to a detail and a sub-detail: it offers more than a single “Back” button.
向かない場面
- One or two levels: the page title is enough.
- Steps in a flow (details, review, payment): use a step indicator; a breadcrumb shows hierarchy, not order.
- Switching between pages on the same level: use tabs or a side navigation.
- The main way back on narrow phone screens: use the title bar's back arrow.
使い方
import { useNavigate } from 'react-router-dom'
import { Breadcrumb } from './Breadcrumb.jsx'
// Items with href are links; the last item is the current page and needs no href.
// Five levels exceed the default of 4 slots, so the middle two fold into "…"
export function FileCrumb() {
return (
<Breadcrumb
items={[
{ label: 'Home', href: '/' },
{ label: 'Documents', href: '/documents' },
{ label: 'Projects', href: '/documents/projects' },
{ label: 'Travel plans', href: '/documents/projects/travel' },
{ label: 'Lisbon itinerary' },
]}
/>
)
}
// Client-side routing: keep href (right-click and Ctrl / Cmd-click still open a new tab), navigate on a plain click
export function RouterCrumb({ trail }) {
const navigate = useNavigate()
return (
<Breadcrumb
size="md"
items={trail.map((t) => ({
key: t.path,
label: t.name,
href: t.path,
onClick: (e) => {
if (e.metaKey || e.ctrlKey) return
e.preventDefault()
navigate(t.path)
},
}))}
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
items | Array<{ key?, label, href?, onClick?, icon? }> | — | Levels from outermost to innermost. href renders an <a>, onClick alone a <button>, neither plain text. The last item is the current page and not clickable. |
separator | ReactNode | '/' | Separator, decorative only (aria-hidden). You can pass “›” or an SVG that uses currentColor. |
size | 'sm' | 'md' | 'sm' | Font 13 / 14px and pill height 28 / 32px. Use sm in a top bar. |
maxItemWidth | number | 160 | Widest an item may be, in px. Longer text is truncated and shows in full on hover. |
maxItems | number | 4 | Most slots shown (“…” counts as one), at least 3. With more levels it keeps the first item and the last maxItems − 2, and folds the rest into a “…” menu. |
label | string | 'Breadcrumb' | Accessible name of the navigation region. |
labels | object | — | Replaces built-in text (more: (count) => string, the name of the “…” button). Shallow-merged over the English defaults. |
...rest | HTMLAttributes<HTMLElement> | — | Other attributes (className, style) go to the root <nav>. Use --ds-breadcrumb-z for the folded menu's z-index (default 30). |
アクセシビリティ
- The structure is <nav aria-label="Breadcrumb"><ol>…</ol></nav>; separators are aria-hidden and not read as “slash”.
- The last item has aria-current="page" and is not clickable; it is also heavier (600), so colour is not the only cue.
- Items with href are real links and onClick-only items are buttons; Tab moves through them and Enter activates, with a visible focus ring (an outline in forced-colors mode).
- The “…” button is named “Show N hidden levels” (replaceable through labels), with aria-haspopup="menu", aria-expanded and aria-controls; the menu uses role="menu" and menuitem.
- Enter, Space or Down opens the menu on the first item, Up on the last; inside, arrows loop, Home / End jump, and Esc closes only the menu and returns focus to the button.
- On touch, hit areas grow to 44px while the look stays compact. With reduced motion the menu only fades in and the current page does not slide.
モーション
The folded menu grows out of the “…” chip in 200ms ease-out (scale 0.96 and 4px) and leaves in 140ms ease-in. When the current page changes it slides in 6px from the left over 240ms; nothing moves on first paint. Hover pills take 160ms and a press scales to 0.96; menu highlights have no transition.
プロジェクトに追加
プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。
Breadcrumb.jsxbreadcrumb.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

