Navigation
Breadcrumb
Path trail with chevron or slash separators and collapsing middle levels.
react-aria-componentslucide-react
Preview
"use client";
import { Building2, Home } from "lucide-react";
import { Breadcrumb } from "@/components/ui/breadcrumb";
export default function Example() {
return (
<div className="flex flex-col gap-4">
<Breadcrumb
items={[
{ id: "home", label: "Home", href: "#", icon: <Home /> },
{ id: "companies", label: "Companies", href: "#", icon: <Building2 /> },
{ id: "ledgerly", label: "Ledgerly" },
]}
/>
<Breadcrumb
separator="slash"
items={[
{ id: "ws", label: "Workspace", href: "#" },
{ id: "lists", label: "Lists", href: "#" },
{ id: "list", label: "Series B — VP Sales" },
]}
/>
<Breadcrumb
maxItems={3}
items={[
{ id: "a", label: "Home", href: "#" },
{ id: "b", label: "Analytics", href: "#" },
{ id: "c", label: "Outreach", href: "#" },
{ id: "d", label: "Sequences", href: "#" },
{ id: "e", label: "Post-event: SaaStr" },
]}
/>
</div>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-components lucide-reactCreate a
breadcrumb.tsxfile and paste the following code into it.src/components/ui/breadcrumb.tsx"use client"; import { ChevronRight, Slash } from "lucide-react"; import type { ReactNode } from "react"; import { Breadcrumb as AriaBreadcrumb, Breadcrumbs, Link } from "react-aria-components"; import { cx } from "@/utils/cx"; export interface BreadcrumbItem { id: string; label: string; href?: string; icon?: ReactNode; } export interface BreadcrumbProps { items: BreadcrumbItem[]; separator?: "chevron" | "slash"; /** Collapse middle items into "…" when there are more than this many. */ maxItems?: number; className?: string; } /** Path trail. The last item is the current page. */ export function Breadcrumb({ items, separator = "chevron", maxItems, className }: BreadcrumbProps) { const shown: (BreadcrumbItem | "…")[] = maxItems && items.length > maxItems ? [items[0]!, "…", ...items.slice(items.length - (maxItems - 1))] : items; const Sep = separator === "chevron" ? ChevronRight : Slash; return ( <Breadcrumbs className={cx("flex flex-wrap items-center gap-1.5 text-base", className)}> {shown.map((it, i) => ( <AriaBreadcrumb key={it === "…" ? "ellipsis" : it.id} id={it === "…" ? "ellipsis" : it.id} className="flex items-center gap-1.5"> {it === "…" ? ( <span className="px-1 text-fg-muted">…</span> ) : ( <Link href={it.href} className={cx( "inline-flex items-center gap-1.5 rounded-xs outline-none data-focus-visible:shadow-focus [&_svg]:size-4", "text-fg-secondary data-hovered:text-fg data-current:font-medium data-current:text-fg", )} > {it.icon} {it.label} </Link> )} {i < shown.length - 1 && <Sep aria-hidden className={cx("text-fg-disabled", separator === "chevron" ? "size-3.5" : "size-3 -rotate-12")} />} </AriaBreadcrumb> ))} </Breadcrumbs> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.