Skip to main content

Breadcrumb Block

Breadcrumbs is a navigation trail built on MUI Breadcrumbs, with a primary bar style and chevron separators.

Installation

npm install @nodeblocks/frontend-breadcrumb-block

What You Need

ItemWhy it matters
items (optional)Renders the trail from { label, url? } segments (default pattern)
Breadcrumbs.Item (optional)Build the trail with compound children instead of items
onNavigate (optional)Called with the clicked segment href for client-side routing
children (function, optional)Override defaultBlocks and blockOrder
Composition modes

Use the items prop for the simplest trail (see Quick Start). Use Breadcrumbs.Item compound children when you want full control per segment—the items prop is ignored when children are JSX elements (not a function). Use a function child with defaultBlocks and blockOrder for custom keys, order, or non-link nodes; omit items unless you want those segments rendered before your blockOrder blocks. MUI inserts separators between children—do not add manual chevron elements.

Code Examples

Live Editor
function Example() {
  const [lastEvent, setLastEvent] = React.useState('Ready');

  return (
    <>
      <Breadcrumbs
        items={[
          { label: 'Home', url: '#home' },
          { label: 'Products', url: '#products' },
          { label: 'Shoes' },
        ]}
        onNavigate={(url) => {
          setLastEvent(`Navigate: ${url}`);
        }}
      />
      <div style={{ marginTop: 8, fontSize: 12, color: '#666' }}>{lastEvent}</div>
    </>
  );
}
Result
Loading...

Important Props

Core Props

PropTypeRequiredDefaultDescription
itemsreadonly { label: ReactNode; url?: string; onClick?: React.MouseEventHandler<HTMLAnchorElement> }[]NoundefinedTrail segments; omit url on the current page; optional per-item onClick
onNavigate(url: string) => voidNoundefinedCalled when a segment with href / url is clicked (runs after the segment’s onClick, if any)
maxItemsnumberNo8Maximum visible items before MUI collapses the trail
itemsBeforeCollapsenumberNo1Items shown before the collapse ellipsis
itemsAfterCollapsenumberNo1Items shown after the collapse ellipsis

Content Props

ComponentPropTypeRequiredDefaultDescription
ItemhrefstringNoundefinedLink target; omit for the current (non-link) segment
ItemchildrenReactNodeYes-Label for the segment
ItemcomponentReact.ElementTypeNo'a'Root element for the link
ItemonClickReact.MouseEventHandler<HTMLAnchorElement>NoundefinedClick handler; onNavigate still runs when href is a string
Breadcrumbs (root)separatorReactNodeNoMUI ChevronRight iconSeparator between segments

Layout and Composition Props

PropTypeRequiredDefaultDescription
childrenBlocksOverride | ReactNodeNoundefinedBreadcrumbs.Item elements or function override returning blocks and blockOrder
classNamestringNoundefinedClass name for the root container (nbb-breadcrumb is applied by default)
sxSxPropsNoundefinedMUI system styles for the root container

Breadcrumbs inherits BreadcrumbsProps from MUI (except children), including expandText and slotProps. Default blockOrder without overrides is ['item'] (defaultBlockOrder).

Default UI Blocks

BlockBuilt onNotes
Breadcrumbs (root)BreadcrumbsPrimary bar (bgcolor: primary.main); separator default ChevronRight
Breadcrumbs.ItemLinkSegment link (nbb-breadcrumb-item); uses href, calls onNavigate when set

TypeScript

import { Breadcrumbs } from '@nodeblocks/frontend-breadcrumb-block';
import type { MouseEventHandler, ReactNode } from 'react';

// Same shape as the package's BreadcrumbNavItem (not re-exported from the entry point).
type TrailItem = {
label: ReactNode;
url?: string;
onClick?: MouseEventHandler<HTMLAnchorElement>;
};

const trail: TrailItem[] = [
{ label: 'Home', url: '/home' },
{ label: 'Products', url: '/products' },
{ label: 'Shoes' },
];

<Breadcrumbs items={trail} onNavigate={(url) => router.push(url)} />;