Breadcrumbs

A breadcrumbs trail is a secondary form of navigation that allows users to keep track and maintain awareness of their location as they move through a hierarchically structured web application.

Props

NameTypeDescriptionDefault
ariaLabelstringProvides a label that describes the type of navigation enabled by the component.'Breadcrumbs'
Required
items
Item[]

being Item an object with the following properties:

{ href?: string; label: string; }
Array of objects representing the items of the breadcrumbs.-
itemsBeforeCollapsenumberNumber of items before showing a collapsed version of the breadcrumbs. It can't be lower than two (root/collapsed action and current page).4
onItemClick(value: string) => voidCallback for custom navigation with third-party libraries such as Next (useRouter) or React Router (useNavigate). This function will be called when an item is clicked, receiving its href as a parameter.-
showRootbooleanWhen items are collapsed, whether the root item should always be displayed or not.true

Examples

Basic usage

() => {
  const items = [
    {
      label: "Select component",
      href: "/components/select",
    },
    {
      label: "Specifications",
      href: "/components/select/specifications",
    },
    {
      label: "Design Tokens",
      href: "/components/select/specifications/#design-tokens",
    },
    {
      label: "Color",
    }
  ];

  return (
    <DxcInset space="2rem">
      <DxcBreadcrumbs items={items} />
    </DxcInset>
  );
}

Custom navigation

There are many React based routers, unfortunately all with different APIs.

As we explained above, the onItemClick prop is a callback that will be called when an item is clicked, receiving its href as a parameter. You can take advantage of this prop to navigate programmatically with third-party libraries hooks or functions.

Next.js useRouter

() => {
  const router = useRouter();
  const handleClick = (href) => {
    router.push(href);
  };

  const items = [
    {
      label: "Select component",
      href: "/components/select",
    },
    {
      label: "Specifications",
      href: "/components/select/specifications",
    },
    {
      label: "Design Tokens",
      href: "/components/select/specifications/#design-tokens",
    },
    {
      label: "Color",
    }
  ]; 

  return (
    <DxcInset space="2rem">
      <DxcBreadcrumbs items={items} onItemClick={handleClick} />
    </DxcInset>
  );
}