alpha

Breadcrumbs

Breadcrumbs display a heirarchy of links to the current page or resource in an application.

installyarn add react-aria-components
version1.0.0-alpha.6
usageimport {Breadcrumbs} from 'react-aria-components'

Example#


import {Breadcrumbs, Item, Link} from 'react-aria-components';

<Breadcrumbs>
  <Item><Link><a href="/">Home</a></Link></Item>
  <Item><Link><a href="/react-aria">React Aria</a></Link></Item>
  <Item><Link>useBreadcrumbs</Link></Item>
</Breadcrumbs>
import {
  Breadcrumbs,
  Item,
  Link
} from 'react-aria-components';

<Breadcrumbs>
  <Item>
    <Link>
      <a href="/">Home</a>
    </Link>
  </Item>
  <Item>
    <Link>
      <a href="/react-aria">React Aria</a>
    </Link>
  </Item>
  <Item>
    <Link>useBreadcrumbs</Link>
  </Item>
</Breadcrumbs>
import {
  Breadcrumbs,
  Item,
  Link
} from 'react-aria-components';

<Breadcrumbs>
  <Item>
    <Link>
      <a href="/">
        Home
      </a>
    </Link>
  </Item>
  <Item>
    <Link>
      <a href="/react-aria">
        React Aria
      </a>
    </Link>
  </Item>
  <Item>
    <Link>
      useBreadcrumbs
    </Link>
  </Item>
</Breadcrumbs>
Show CSS
.react-aria-Breadcrumbs {
  & ol {
    display: flex;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 18px;
  }

  .react-aria-Heading {
    margin: 0;
    font-size: 1em;
  }

  .react-aria-Item:not(:last-child)::after {
    content: '›';
    content: '›' / '';
    alt: ' ';
    padding: 0 5px;
  }
}

.react-aria-Link {
  --focus-ring-color: slateblue;
  --text-color: var(--spectrum-global-color-gray-800);
  --text-color-current: var(--spectrum-global-color-gray-900);
  --text-color-disabled: gray;

  color: var(--text-color);
  outline: none;
  position: relative;
  text-decoration: none;
  cursor: pointer;

  &[data-hovered] {
    text-decoration: underline;
  }

  &[data-current] {
    color: var(--text-color-current);
    font-weight: bold;
  }

  &[data-focus-visible]:after {
    content: '';
    position: absolute;
    inset: -2px -4px;
    border-radius: 6px;
    border: 2px solid var(--focus-ring-color);
  }

  &[data-disabled] {
    cursor: default;

    &:not([data-current]) {
      color: var(--text-color-disabled);
    }
  }
}

@media (forced-colors: active) {
  .react-aria-Link {
    --focus-ring-color: Highlight;
    --text-color: LinkText;
    --text-color-current: CanvasText;
    --text-color-disabled: GrayText;
  }
}
.react-aria-Breadcrumbs {
  & ol {
    display: flex;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 18px;
  }

  .react-aria-Heading {
    margin: 0;
    font-size: 1em;
  }

  .react-aria-Item:not(:last-child)::after {
    content: '›';
    content: '›' / '';
    alt: ' ';
    padding: 0 5px;
  }
}

.react-aria-Link {
  --focus-ring-color: slateblue;
  --text-color: var(--spectrum-global-color-gray-800);
  --text-color-current: var(--spectrum-global-color-gray-900);
  --text-color-disabled: gray;

  color: var(--text-color);
  outline: none;
  position: relative;
  text-decoration: none;
  cursor: pointer;

  &[data-hovered] {
    text-decoration: underline;
  }

  &[data-current] {
    color: var(--text-color-current);
    font-weight: bold;
  }

  &[data-focus-visible]:after {
    content: '';
    position: absolute;
    inset: -2px -4px;
    border-radius: 6px;
    border: 2px solid var(--focus-ring-color);
  }

  &[data-disabled] {
    cursor: default;

    &:not([data-current]) {
      color: var(--text-color-disabled);
    }
  }
}

@media (forced-colors: active) {
  .react-aria-Link {
    --focus-ring-color: Highlight;
    --text-color: LinkText;
    --text-color-current: CanvasText;
    --text-color-disabled: GrayText;
  }
}
.react-aria-Breadcrumbs {
  & ol {
    display: flex;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 18px;
  }

  .react-aria-Heading {
    margin: 0;
    font-size: 1em;
  }

  .react-aria-Item:not(:last-child)::after {
    content: '›';
    content: '›' / '';
    alt: ' ';
    padding: 0 5px;
  }
}

.react-aria-Link {
  --focus-ring-color: slateblue;
  --text-color: var(--spectrum-global-color-gray-800);
  --text-color-current: var(--spectrum-global-color-gray-900);
  --text-color-disabled: gray;

  color: var(--text-color);
  outline: none;
  position: relative;
  text-decoration: none;
  cursor: pointer;

  &[data-hovered] {
    text-decoration: underline;
  }

  &[data-current] {
    color: var(--text-color-current);
    font-weight: bold;
  }

  &[data-focus-visible]:after {
    content: '';
    position: absolute;
    inset: -2px -4px;
    border-radius: 6px;
    border: 2px solid var(--focus-ring-color);
  }

  &[data-disabled] {
    cursor: default;

    &:not([data-current]) {
      color: var(--text-color-disabled);
    }
  }
}

@media (forced-colors: active) {
  .react-aria-Link {
    --focus-ring-color: Highlight;
    --text-color: LinkText;
    --text-color-current: CanvasText;
    --text-color-disabled: GrayText;
  }
}

Features#


Breadcrumbs provide a list of links to parent pages of the current page in hierarchical order. Breadcrumbs helps implement these in an accessible way.

  • Flexible – Support for navigation links, JavaScript handled links, or custom element types (e.g. router links).
  • Accessible – Implemented as a navigation landmark with an ordered list of links. Optional support for using breadcrumbs as a heading is available as well.
  • Styleable – Hover, press, and keyboard focus states are provided for easy styling. These states only apply when interacting with an appropriate input device, unlike CSS pseudo classes.

Anatomy#


TrendSub ItemJanuary 2019 AssetsBreadcrumb itemSeparatorCurrent pageNavigation

Breadcrumbs consist of a navigation landmark element and a list of links, typically with a visual separator icon between each item. The last link represents the current page in the hierarchy, with the previous links representing the parent pages of the current page. Each of these parent links can be clicked, tapped, or triggered via the Enter key to navigate to that page. Optionally, breadcrumbs can be used in place of a page title, in which case the last breadcrumb acts as a heading.

Concepts#

Breadcrumbs makes use of the following concepts:

Composed components#

Breadcrumbs uses the following components, which may also be used standalone or reused in other components.

Link
A link allows a user to navigate to another page.

Props#


NameTypeDescription
isDisabledbooleanWhether the breadcrumbs are disabled.
childrenReactNode( (item: T )) => ReactNodeThe contents of the collection.
itemsIterable<T>Item objects in the collection.
classNamestringThe CSS className for the element.
styleCSSPropertiesThe inline style for the element.
Events
NameTypeDescription
onAction( (key: Key )) => voidHandler that is called when a breadcrumb is clicked.
Layout
NameTypeDescription
slotstringA slot name for the component. Slots allow the component to receive props from a parent component.
Accessibility
NameTypeDescription
idstringThe element's unique identifier. See MDN.
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.

Styling#


React Aria components can be styled in many ways, including using CSS classes, inline styles, utility classes (e.g. Tailwind), CSS-in-JS (e.g. Styled Components), etc. By default, all components include a builtin className attribute which can be targeted using CSS selectors. These follow the react-aria-ComponentName naming convention.

.react-aria-Breadcrumbs {
  /* ... */
}
.react-aria-Breadcrumbs {
  /* ... */
}
.react-aria-Breadcrumbs {
  /* ... */
}

A custom className can also be specified on any component. This overrides the default className provided by React Aria with your own.

<Breadcrumbs className="my-breadcrumbs">
  {/* ... */}
</Breadcrumbs>
<Breadcrumbs className="my-breadcrumbs">
  {/* ... */}
</Breadcrumbs>
<Breadcrumbs className="my-breadcrumbs">
  {/* ... */}
</Breadcrumbs>

In addition, some components support multiple UI states (e.g. focused, placeholder, readonly, etc.). React Aria components expose states using data attributes, which you can target in CSS selectors. For example:

.react-aria-Link[data-current] {
  /* ... */
}
.react-aria-Link[data-current] {
  /* ... */
}
.react-aria-Link[data-current] {
  /* ... */
}

The className and style props also accept functions which receive states for styling. This lets you dynamically determine the classes or styles to apply, which is useful when using utility CSS libraries like Tailwind.

<Link
  className={({ isCurrent }) => isCurrent ? 'bg-gray-700' : 'bg-gray-600'}
/>
<Link
  className={({ isCurrent }) =>
    isCurrent ? 'bg-gray-700' : 'bg-gray-600'}
/>
<Link
  className={(
    { isCurrent }
  ) =>
    isCurrent
      ? 'bg-gray-700'
      : 'bg-gray-600'}
/>

The states, selectors, and render props for all components used in Breadcrumbs are documented below.

Breadcrumbs can be targed with the .react-aria-Breadcrumbs CSS selector, or by overriding with a custom className. It is rendered as a <nav> element, and contains an <ol> element representing the list of items. This additional element can be targed with the ol selector.

.react-aria-Breadcrumbs {
  & ol {
    /* ... */
  }
}
.react-aria-Breadcrumbs {
  & ol {
    /* ... */
  }
}
.react-aria-Breadcrumbs {
  & ol {
    /* ... */
  }
}

Item#

An Item can be targeted with the .react-aria-Item CSS selector, or by overriding with a custom className. It is rendered as an <li> element, and should contain a <Link> or <Heading>. It may also include another element such as a separator icon.

A Link can be targeted with the .react-aria-Link CSS selector, or by overriding with a custom className. It clones its only child element (e.g. <a>) and adds additional props, which should be passed through to the underlying DOM node. If only text is provided, it is rendered as a <span>. Links support the following states and render props:

NameCSS SelectorDescription
isCurrent[data-current]Whether the link is the current item within a list.
isHovered[data-hovered]Whether the link is currently hovered with a mouse.
isPressed[data-pressed]Whether the link is currently in a pressed state.
isFocused[data-focused]Whether the link is focused, either via a mouse or keyboard.
isFocusVisible[data-focus-visible]Whether the link is keyboard focused.
isDisabled[data-disabled]Whether the link is disabled.

Usage#


Dynamic collections#

Breadcrumbs follows the Collection Components API, accepting both static and dynamic collections. The examples above show static collections, which can be used when the full list of options is known ahead of time. Dynamic collections, as shown below, can be used when the options come from an external data source such as an API call, or update over time.

As seen below, an iterable list of options is passed to the Breadcrumbs using the items prop. A function provided as children of the <Breadcrumbs> is called to render each item. When a breadcrumb is pressed, the onAction event is triggered and the breadcrumbs array is updated.

function Example() {
  let [breadcrumbs, setBreadcrumbs] = React.useState([
    {id: 1, label: 'Home'},
    {id: 2, label: 'Trendy'},
    {id: 3, label: 'March 2022 Assets'}
  ]);

  let navigate = (id: React.Key) => {
    let i = breadcrumbs.findIndex(item => item.id === id);
    setBreadcrumbs(breadcrumbs.slice(0, i + 1));
  };

  return (
    <Breadcrumbs items={breadcrumbs} onAction={navigate}>
      {item => <Item><Link>{item.label}</Link></Item>}
    </Breadcrumbs>
  );
}
function Example() {
  let [breadcrumbs, setBreadcrumbs] = React.useState([
    {id: 1, label: 'Home'},
    {id: 2, label: 'Trendy'},
    {id: 3, label: 'March 2022 Assets'}
  ]);

  let navigate = (id: React.Key) => {
    let i = breadcrumbs.findIndex(item => item.id === id);
    setBreadcrumbs(breadcrumbs.slice(0, i + 1));
  };

  return (
    <Breadcrumbs items={breadcrumbs} onAction={navigate}>
      {item => <Item><Link>{item.label}</Link></Item>}
    </Breadcrumbs>
  );
}
function Example() {
  let [
    breadcrumbs,
    setBreadcrumbs
  ] = React.useState([
    {
      id: 1,
      label: 'Home'
    },
    {
      id: 2,
      label: 'Trendy'
    },
    {
      id: 3,
      label:
        'March 2022 Assets'
    }
  ]);

  let navigate = (
    id: React.Key
  ) => {
    let i = breadcrumbs
      .findIndex(
        (item) =>
          item.id === id
      );
    setBreadcrumbs(
      breadcrumbs.slice(
        0,
        i + 1
      )
    );
  };

  return (
    <Breadcrumbs
      items={breadcrumbs}
      onAction={navigate}
    >
      {(item) => (
        <Item>
          <Link>
            {item.label}
          </Link>
        </Item>
      )}
    </Breadcrumbs>
  );
}

Heading#

The last breadcrumb may be used as a heading for the page by placing a <Heading> element within the <Item> instead of a <Link>. By default, this is an h3 element, but this can be changed with the level prop on the Heading.

import {Heading} from 'react-aria-components';

<Breadcrumbs>
  <Item><Link><a href="/">Home</a></Link></Item>
  <Item><Link><a href="/react-aria">React Aria</a></Link></Item>
  <Item><Heading>useBreadcrumbs</Heading></Item>
</Breadcrumbs>
import {Heading} from 'react-aria-components';

<Breadcrumbs>
  <Item>
    <Link>
      <a href="/">Home</a>
    </Link>
  </Item>
  <Item>
    <Link>
      <a href="/react-aria">React Aria</a>
    </Link>
  </Item>
  <Item>
    <Heading>useBreadcrumbs</Heading>
  </Item>
</Breadcrumbs>
import {Heading} from 'react-aria-components';

<Breadcrumbs>
  <Item>
    <Link>
      <a href="/">
        Home
      </a>
    </Link>
  </Item>
  <Item>
    <Link>
      <a href="/react-aria">
        React Aria
      </a>
    </Link>
  </Item>
  <Item>
    <Heading>
      useBreadcrumbs
    </Heading>
  </Item>
</Breadcrumbs>

The <Link> component can wrap a custom link element provided by a router like React Router.

import {Link as RouterLink} from 'react-router-dom';

<Breadcrumbs>
  <Item><Link><RouterLink to="/foo">Foo</RouterLink></Link></Item>
  <Item><Link>Bar</Link></Item>
</Breadcrumbs>
import {Link as RouterLink} from 'react-router-dom';

<Breadcrumbs>
  <Item>
    <Link>
      <RouterLink to="/foo">Foo</RouterLink>
    </Link>
  </Item>
  <Item>
    <Link>Bar</Link>
  </Item>
</Breadcrumbs>
import {Link as RouterLink} from 'react-router-dom';

<Breadcrumbs>
  <Item>
    <Link>
      <RouterLink to="/foo">
        Foo
      </RouterLink>
    </Link>
  </Item>
  <Item>
    <Link>Bar</Link>
  </Item>
</Breadcrumbs>

Separator icons#

The above examples use the CSS :after pseudo class to add separators between each item. These may also be DOM elements instead, e.g. SVG icons. Be sure that they have aria-hidden="true" so they are hidden from assistive technologies.

import ChevronIcon from '@spectrum-icons/workflow/ChevronDoubleRight';

<Breadcrumbs>
  <Item className="my-item">
    <Link><a href="/">Home</a></Link>
    <ChevronIcon size="S" />
  </Item>
  <Item><Link>React Aria</Link></Item>
</Breadcrumbs>
import ChevronIcon from '@spectrum-icons/workflow/ChevronDoubleRight';

<Breadcrumbs>
  <Item className="my-item">
    <Link>
      <a href="/">Home</a>
    </Link>
    <ChevronIcon size="S" />
  </Item>
  <Item>
    <Link>React Aria</Link>
  </Item>
</Breadcrumbs>
import ChevronIcon from '@spectrum-icons/workflow/ChevronDoubleRight';

<Breadcrumbs>
  <Item className="my-item">
    <Link>
      <a href="/">
        Home
      </a>
    </Link>
    <ChevronIcon size="S" />
  </Item>
  <Item>
    <Link>
      React Aria
    </Link>
  </Item>
</Breadcrumbs>
Show CSS
.my-item svg {
  vertical-align: middle;
  padding: 0 5px;
  margin-top: -2px;
}
.my-item svg {
  vertical-align: middle;
  padding: 0 5px;
  margin-top: -2px;
}
.my-item svg {
  vertical-align: middle;
  padding: 0 5px;
  margin-top: -2px;
}

Disabled#

Breadcrumbs can be disabled using the isDisabled prop. This indicates that navigation is not currently available. When a breadcrumb is disabled, onPress will not be triggered, navigation will not occur, and links will be marked as aria-disabled for assistive technologies.

<Breadcrumbs isDisabled>
  <Item><Link><a href="/">Home</a></Link></Item>
  <Item><Link><a href="/react-aria">React Aria</a></Link></Item>
  <Item><Link>useBreadcrumbs</Link></Item>
</Breadcrumbs>
<Breadcrumbs isDisabled>
  <Item>
    <Link>
      <a href="/">Home</a>
    </Link>
  </Item>
  <Item>
    <Link>
      <a href="/react-aria">React Aria</a>
    </Link>
  </Item>
  <Item>
    <Link>useBreadcrumbs</Link>
  </Item>
</Breadcrumbs>
<Breadcrumbs
  isDisabled
>
  <Item>
    <Link>
      <a href="/">
        Home
      </a>
    </Link>
  </Item>
  <Item>
    <Link>
      <a href="/react-aria">
        React Aria
      </a>
    </Link>
  </Item>
  <Item>
    <Link>
      useBreadcrumbs
    </Link>
  </Item>
</Breadcrumbs>

Individual breadcrumbs can also be disabled by passing the isDisabled prop to the <Link> element:

<Breadcrumbs>
  <Item><Link><a href="/">Home</a></Link></Item>
  <Item><Link isDisabled><a href="/react-aria">React Aria</a></Link></Item>
  <Item><Link>useBreadcrumbs</Link></Item>
</Breadcrumbs>
<Breadcrumbs>
  <Item>
    <Link>
      <a href="/">Home</a>
    </Link>
  </Item>
  <Item>
    <Link isDisabled>
      <a href="/react-aria">React Aria</a>
    </Link>
  </Item>
  <Item>
    <Link>useBreadcrumbs</Link>
  </Item>
</Breadcrumbs>
<Breadcrumbs>
  <Item>
    <Link>
      <a href="/">
        Home
      </a>
    </Link>
  </Item>
  <Item>
    <Link isDisabled>
      <a href="/react-aria">
        React Aria
      </a>
    </Link>
  </Item>
  <Item>
    <Link>
      useBreadcrumbs
    </Link>
  </Item>
</Breadcrumbs>

Advanced customization#


Contexts#

All React Aria Components export a corresponding context that can be used to send props to them from a parent element. This enables you to build your own compositional APIs similar to those found in React Aria Components itself. You can send any prop or ref via context that you could pass to the corresponding component. The local props and ref on the component are merged with the ones passed via context, with the local props taking precedence (following the rules documented in mergeProps).

ComponentContextPropsRef
BreadcrumbsBreadcrumbsContextBreadcrumbsPropsHTMLElement

This example shows a Router component that accepts Breadcrumbs and Link elements as children, and tracks a history stack. When a link is clicked, it is pushed to the stack and automatically updates the breadcrumbs. When a breadcrumb is clicked, the stack is popped to that location.

import type {PressEvent} from 'react-aria-components';
import {BreadcrumbsContext, LinkContext} from 'react-aria-components';

interface RouterItem {
  id: number,
  label: string
}

function Router({children}) {
  let [items, setItems] = React.useState<RouterItem[]>([
    {id: 0, label: 'Home'},
    {id: 1, label: 'React Aria'},
  ]);

  // Pop stack when a breadcrumb item is clicked.
  let onAction = (id: React.Key) => {
    let i = items.findIndex(item => item.id === id);
    setItems(items.slice(0, i + 1));
  };

  // Push stack when a link is clicked.
  let onPress = (e: PressEvent) => {
    let label = e.target.textContent;
    setItems(items.concat({id: items.length, label}));
  };

  return (
    <BreadcrumbsContext.Provider value={{items, onAction}}>      <LinkContext.Provider value={{onPress}}>
        {children}
      </LinkContext.Provider>
    </BreadcrumbsContext.Provider>
  );
}
import type {PressEvent} from 'react-aria-components';
import {
  BreadcrumbsContext,
  LinkContext
} from 'react-aria-components';

interface RouterItem {
  id: number;
  label: string;
}

function Router({ children }) {
  let [items, setItems] = React.useState<RouterItem[]>([
    { id: 0, label: 'Home' },
    { id: 1, label: 'React Aria' }
  ]);

  // Pop stack when a breadcrumb item is clicked.
  let onAction = (id: React.Key) => {
    let i = items.findIndex((item) => item.id === id);
    setItems(items.slice(0, i + 1));
  };

  // Push stack when a link is clicked.
  let onPress = (e: PressEvent) => {
    let label = e.target.textContent;
    setItems(items.concat({ id: items.length, label }));
  };

  return (
    <BreadcrumbsContext.Provider
      value={{ items, onAction }}
    >      <LinkContext.Provider value={{ onPress }}>
        {children}
      </LinkContext.Provider>
    </BreadcrumbsContext.Provider>
  );
}
import type {PressEvent} from 'react-aria-components';
import {
  BreadcrumbsContext,
  LinkContext
} from 'react-aria-components';

interface RouterItem {
  id: number;
  label: string;
}

function Router(
  { children }
) {
  let [items, setItems] =
    React.useState<
      RouterItem[]
    >([
      {
        id: 0,
        label: 'Home'
      },
      {
        id: 1,
        label:
          'React Aria'
      }
    ]);

  // Pop stack when a breadcrumb item is clicked.
  let onAction = (
    id: React.Key
  ) => {
    let i = items
      .findIndex(
        (item) =>
          item.id === id
      );
    setItems(
      items.slice(
        0,
        i + 1
      )
    );
  };

  // Push stack when a link is clicked.
  let onPress = (
    e: PressEvent
  ) => {
    let label =
      e.target
        .textContent;
    setItems(
      items.concat({
        id: items.length,
        label
      })
    );
  };

  return (
    <BreadcrumbsContext.Provider
      value={{
        items,
        onAction
      }}
    >      <LinkContext.Provider
        value={{
          onPress
        }}
      >
        {children}
      </LinkContext.Provider>
    </BreadcrumbsContext.Provider>
  );
}

Note: LinkContext only affects links outside Breadcrumbs because Breadcrumbs also provides a value for LinkContext which overrides an outer provider. See custom children below for more details.

Now when you place Breadcrumbs inside a Router, it automatically has access to the location history via context.

<Router>
  <Breadcrumbs>
    {(item: RouterItem) => <Item><Link>{item.label}</Link></Item>}
  </Breadcrumbs>
  <ul>
    <li><Link>Breadcrumbs</Link></li>
    <li><Link>Button</Link></li>
    <li><Link>Calendar</Link></li>
  </ul>
</Router>
<Router>
  <Breadcrumbs>
    {(item: RouterItem) => (
      <Item>
        <Link>{item.label}</Link>
      </Item>
    )}
  </Breadcrumbs>
  <ul>
    <li>
      <Link>Breadcrumbs</Link>
    </li>
    <li>
      <Link>Button</Link>
    </li>
    <li>
      <Link>Calendar</Link>
    </li>
  </ul>
</Router>
<Router>
  <Breadcrumbs>
    {(
      item: RouterItem
    ) => (
      <Item>
        <Link>
          {item.label}
        </Link>
      </Item>
    )}
  </Breadcrumbs>
  <ul>
    <li>
      <Link>
        Breadcrumbs
      </Link>
    </li>
    <li>
      <Link>
        Button
      </Link>
    </li>
    <li>
      <Link>
        Calendar
      </Link>
    </li>
  </ul>
</Router>

Custom children#

Breadcrumbs passes props to its child components, such as the links, via their associated contexts. These contexts are exported so you can also consume them in your own custom components. This enables you to reuse existing components from your app or component library together with React Aria Components.

ComponentContextPropsRef
LinkLinkContextLinkPropsHTMLAnchorElement
HeadingHeadingContextHeadingPropsHTMLHeadingElement

This example consumes from HeadingContext in an existing styled heading component to make it compatible with React Aria Components. The useContextProps hook merges the local props and ref with the ones provided via context by Breadcrumbs.

import type {HeadingProps} from 'react-aria-components';
import {HeadingContext, useContextProps} from 'react-aria-components';

const MyCustomHeading = React.forwardRef(
  (props: HeadingProps, ref: React.ForwardedRef<HTMLHeadingElement>) => {
    // Merge the local props and ref with the ones provided via context.
    [props, ref] = useContextProps(props, ref, HeadingContext);
    // ... your existing Heading component
    return <h2 {...props} ref={ref} />;
  }
);
import type {HeadingProps} from 'react-aria-components';
import {
  HeadingContext,
  useContextProps
} from 'react-aria-components';

const MyCustomHeading = React.forwardRef(
  (
    props: HeadingProps,
    ref: React.ForwardedRef<HTMLHeadingElement>
  ) => {
    // Merge the local props and ref with the ones provided via context.
    [props, ref] = useContextProps(
      props,
      ref,
      HeadingContext
    );
    // ... your existing Heading component
    return <h2 {...props} ref={ref} />;
  }
);
import type {HeadingProps} from 'react-aria-components';
import {
  HeadingContext,
  useContextProps
} from 'react-aria-components';

const MyCustomHeading =
  React.forwardRef(
    (
      props:
        HeadingProps,
      ref:
        React.ForwardedRef<
          HTMLHeadingElement
        >
    ) => {
      // Merge the local props and ref with the ones provided via context.
      [props, ref] =
        useContextProps(
          props,
          ref,
          HeadingContext
        );
      // ... your existing Heading component
      return (
        <h2
          {...props}
          ref={ref}
        />
      );
    }
  );

Now you can use MyCustomHeading within Breadcrumbs, in place of the builtin React Aria Components Heading.

<Breadcrumbs>
  {/* ... */}
  <Item><MyCustomHeading>Custom heading</MyCustomHeading></Item></Breadcrumbs>
<Breadcrumbs>
  {/* ... */}
  <Item>
    <MyCustomHeading>Custom heading</MyCustomHeading>
  </Item></Breadcrumbs>
<Breadcrumbs>
  {/* ... */}
  <Item>
    <MyCustomHeading>
      Custom heading
    </MyCustomHeading>
  </Item></Breadcrumbs>

Hooks#

If you need to customize things further, such as customizing the DOM structure, you can drop down to the lower level Hook-based API. See useBreadcrumbs for more details.