<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-breadcrumb-item/usage/ in the magma monorepo.
-->

# mds-breadcrumb-item - examples

> The API of this component: [`AGENTS.md`](AGENTS.md).

Correct and idiomatic ways to use the `<mds-breadcrumb-item>` component, ordered from most common to most specialized. The examples assume a working knowledge of the shared component rules in [`agents/conventions.md`](../../../../agents/conventions.md).

#### Basic Breadcrumb Trail

The canonical form. Place `<mds-breadcrumb-item>` elements as direct children of [`<mds-breadcrumb>`](../mds-breadcrumb/AGENTS.md). Use the `label` prop for each step's text.

```html
<mds-breadcrumb>
  <mds-breadcrumb-item label="Home"></mds-breadcrumb-item>
  <mds-breadcrumb-item label="Archivio"></mds-breadcrumb-item>
  <mds-breadcrumb-item label="Dettaglio documento"></mds-breadcrumb-item>
</mds-breadcrumb>
```

#### Seeding the Active Depth with `selected`

Set `selected` on the item that represents the user's current location on first render. The parent [`<mds-breadcrumb>`](../mds-breadcrumb/AGENTS.md) takes over selection management after that; do not set `selected` on more than one item at a time.

```html
<mds-breadcrumb>
  <mds-breadcrumb-item label="Home"></mds-breadcrumb-item>
  <mds-breadcrumb-item label="Archivio"></mds-breadcrumb-item>
  <mds-breadcrumb-item label="Documenti" selected></mds-breadcrumb-item>
</mds-breadcrumb>
```

#### Listening for Navigation Changes

Listen to `mdsBreadcrumbItemSelect` on the item, or to `mdsBreadcrumbChange`, which the parent [`<mds-breadcrumb>`](../mds-breadcrumb/AGENTS.md) emits after updating the selection, to react when the user navigates to a different depth.

```html
<mds-breadcrumb id="nav">
  <mds-breadcrumb-item label="Home"></mds-breadcrumb-item>
  <mds-breadcrumb-item label="Pratiche"></mds-breadcrumb-item>
  <mds-breadcrumb-item label="Dettaglio" selected></mds-breadcrumb-item>
</mds-breadcrumb>

<script>
  document.querySelector('#nav').addEventListener('mdsBreadcrumbChange', (e) => {
    console.log('profondita selezionata:', e.detail.id);
  });
</script>
```

#### Styling the Arrow Separator

`mds-breadcrumb-item` has no public CSS custom property, and the separator icon exposes no part: it takes the subtle text color of the theme, so it keeps working in dark mode and high-contrast modes with no override. Restyle the button of the item instead, through its `button` part.

#### Styling Button States

Restyle the button through the `button` part: it is the item's `<mds-button>`, so it takes the public `--mds-button-*` custom properties. Target the hover state with `:hover` on the part and the selected one with the item's `selected` attribute, and use semantic color roles wrapped in `rgb(var(--magma-<role>))` so dark mode keeps working.

```css
.sidebar-nav mds-breadcrumb-item::part(button) {
  --mds-button-color: rgb(var(--magma-text-muted));
}
.sidebar-nav mds-breadcrumb-item::part(button):hover {
  --mds-button-color: rgb(var(--magma-text-default));
}
.sidebar-nav mds-breadcrumb-item[selected]::part(button) {
  --mds-button-background: rgb(var(--magma-accent-surface-subtle));
  --mds-button-color: rgb(var(--magma-accent-fg));
}
```

#### Styling the Internal Button via `::part(button)`

The internal `<mds-button>` is exposed as `::part(button)`. Use it for what the item does not expose - for example to adjust padding or border radius for a product-specific surface.

```css
.compact-nav mds-breadcrumb-item::part(button) {
  --mds-button-radius: var(--magma-radius-sm);
}
```
