Breadcrumb
Breadcrumbs, or a breadcrumb navigation, can help 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.BreadcrumbSeparator
: The visual separator between each breadcrumb.
import {Breadcrumb,BreadcrumbItem,BreadcrumbLink,BreadcrumbSeparator,} from "@chakra-ui/react"
Usage#
Add isCurrentPage
prop to the BreadcrumbItem
that matches the current path.
When this prop is present, the BreadcrumbLink
renders a span
with
aria-current
set to page
instead of an anchor element.
Separators#
Change the separator used in the breadcrumb by passing a string, like -
or an
icon.
Using an icon as the separator#
Composition#
Breadcrumb composes Box so you can pass all Box
props to
change the style of the breadcrumbs. Let's say we need to reduce the fontSize
of the breadcrumbs.
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 Reach's Link.
// import { Link } from "@reach/router"<Breadcrumb><BreadcrumbItem><BreadcrumbLink as={Link} to="#">Home</BreadcrumbLink></BreadcrumbItem><BreadcrumbItem><BreadcrumbLink as={Link} to="#">About</BreadcrumbLink></BreadcrumbItem><BreadcrumbItem isCurrentPage><BreadcrumbLink>Contact</BreadcrumbLink></BreadcrumbItem></Breadcrumb>
Accessibility#
- The Breadcrumbs are rendered in a
nav
to denote that it is a navigation landmark. - The Breadcrumb
nav
hasaria-label
set tobreadcrumb
. - The BreadcrumbItem with
isCurrentPage
prop adds thearia-current=page
to the BreadcrumbLink. - The separator has
role
set topresentation
to denote that its for presentation purposes.
Props#
Breadcrumb Props#
Name | Type | Description | Default |
---|---|---|---|
colorScheme | "blue" | "cyan" | "gray" | "green" | "orange" | "pink" | "purple" | "red" | "teal" | "yellow" | "whiteAlpha" | "blackAlpha" | "linkedin" | "facebook" | "messenger" | "whatsapp" | "twitter" | "telegram" | Color Schemes for Breadcrumb are not implemented in the default theme. You can extend the theme to implement them. | - |
separator | string | React.ReactElement | The visual separator between each breadcrumb item | - |
size | string | Sizes for Breadcrumb are not implemented in the default theme. You can extend the theme to implement them. | - |
spacing | SystemProps["mx"] | The left and right margin applied to the separator | - |
variant | string | Variants for Breadcrumb are not implemented in the default theme. You can extend the theme to implement them. | - |
BreadcrumbItem Props#
Name | Type | Description | Default |
---|---|---|---|
isCurrentPage | boolean | - | |
isLastChild | boolean | - | |
separator | string | React.ReactElement | The visual separator between each breadcrumb item | - |
spacing | SystemProps["mx"] | The left and right margin applied to the separator | - |
BreadcrumbLink Props#
The BreadcrumbLink composes the Link component so you can use all Link props.
Name | Type | Description | Default |
---|---|---|---|
isCurrentPage | boolean | - |
BreadcrumbSeparator Props#
The BreadcrumbSeparator composes the Box component so you can use all Box props.