Breadcrumb

Breadcrumbs, or a breadcrumb navigation, can help to enhance how users navigate to previous page levels of a website, especially if that website has many pages or products.

Import#

Chakra UI exports 4 breadcrumb related components:

  • Breadcrumb: The parent container for breadcrumbs.
  • BreadcrumbItem: Individual breadcrumb element containing a link and a divider.
  • BreadcrumbLink: The breadcrumb link, obviously.
  • BreadcrumbSeparator: The visual separator between each breadcrumb

Usage#

Add isCurrentPage prop to the BreadcrumbItem that matches the current path. When this prop is present, the BreadcrumbItem doesn't have a separator, and the BreadcrumbLink has aria-current set to page.

Editable Example

Separators#

Change the separator used in the breadcrumb by passing a string, like - or an icon.

Editable Example

Using an icon as the separator#

Editable Example

Styling the Separator#

To gain control over the style of the breadcrumb separator. Set addSeparator to false, and manually add the BreadcrumbSeparator as a child of the BreadcrumbItem.

You can then pass the style props to change the styling. You can also override the content of the BreadcrumbSeparator by passing its children.

Editable Example

Composition#

Breadcrumb composes Box so you can pass all Box props to change the style of the breadcrumbs. Let's say we need to increase the fontSize of the breadcrumbs.

Editable Example

Usage with Routing Library#

To use the Breadcrumb with a routing Library like Reach Router or React Router, all you need to do is to pass the as prop to the BreadcrumbLink component.

It'll replace the rendered a tag with with Reach's Link.

Accessibility#

  • The Breadcrumbs are rendered in a nav to denote that it's a navigation landmark.
  • The Breadcrumb nav has aria-label set to breadcrumb.
  • The BreadcrumbItem with isCurrentPage prop adds the aria-current=page to the BreadcrumbLink.
  • The separator has role set to presentation to denote that its for presentation purposes.

Props#

NameTypeDefaultDescription
separatorstring, React.ReactNode/The visual separator between the breadcrumb item.
spacingStyledSystem.MarginProps0.5remThe left and right margin applied to the separator.
addSeparatorbooleantrueIf true, the breadcrumb will add the separator automatically.
NameTypeDefaultDescription
isCurrentPagebooleanIf true, it indicates that the breadcrumb link is active page, adds aria-current=page and renders a span

The BreadcrumbLink composes the Link component so you can all Link props.

The BreadcrumbSeparator composes the Box component so you can all Box props.

Proudly made in 🇳🇬

Released under the MIT License.

Copyright © 2020 Segun Adebayo