# Breadcrumbs

## Usage

Import `Breadcrumbs` and `BreadcrumbItem` from their dedicated entry.

```vue
<script setup lang="ts">
import { BreadcrumbItem, Breadcrumbs } from '@astryx-vue/core/Breadcrumbs'
</script>

<template>
  <Breadcrumbs>
    <BreadcrumbItem href="/">
      Home
    </BreadcrumbItem>
    <BreadcrumbItem href="/components">
      Components
    </BreadcrumbItem>
    <BreadcrumbItem is-current>
      Breadcrumbs
    </BreadcrumbItem>
  </Breadcrumbs>
</template>
```

A crumb in the middle of the trail can open a menu for sibling destinations. A short list is a menu array. Checkbox and radio rows go in the menu slot on that crumb, and the slot replaces the array. Those rows are exported from the breadcrumbs entry and are the same components the menu uses, so a choice opens and closes the same way.

### Anatomy

- **Trail**: The ordered list of links from root to current page.
- **Item**: A single step in the trail. Renders as a link or plain text for the current page.
- **Separator**: The character between items. Defaults to "/" but can be customized.
- **Icon**: An optional icon before an item label, like a home icon on the first item.

## Best practices

| Guidance | Practice |
| --- | --- |
| Recommended | Use semantic `<nav>` and `<ol>` markup so screen readers can identify the path. |
| Recommended | Use `is-current` for the current page and render it as a `<span>` with `aria-current="page"`. |
| Recommended | Keep separators decorative with `aria-hidden="true"`. |
| Don't | Use overly long labels that wrap awkwardly on small screens. |
| Don't | Make the current page a clickable link; this creates circular navigation. |

## Examples

### Separators

Swap the default slash for a chevron, an arrow, or a dot when the page calls for a different separator.

```vue
<script setup lang="ts">
import { BreadcrumbItem, Breadcrumbs } from '@astryx-vue/core/Breadcrumbs'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'

const separators = [
  { char: '›', label: 'Chevron' },
  { char: '→', label: 'Arrow' },
  { char: '·', label: 'Dot' },
]
</script>

<template>
  <VStack :gap="4">
    <VStack v-for="item in separators" :key="item.label" :gap="1">
      <Text color="secondary" type="supporting">
        {{ item.label }}
      </Text>
      <Breadcrumbs :separator="item.char">
        <BreadcrumbItem href="/">
          Home
        </BreadcrumbItem>
        <BreadcrumbItem href="/docs">
          Docs
        </BreadcrumbItem>
        <BreadcrumbItem is-current>
          API Reference
        </BreadcrumbItem>
      </Breadcrumbs>
    </VStack>
  </VStack>
</template>
```

### Deep path

A five-level trail for a deeply nested page, with a home icon on the root.

```vue
<script setup lang="ts">
import { BreadcrumbItem, Breadcrumbs } from '@astryx-vue/core/Breadcrumbs'
</script>

<template>
  <Breadcrumbs>
    <BreadcrumbItem href="/">
      <template #startIcon>
        <span class="i-heroicons-home css-icon css-icon--sm" />
      </template>
      Home
    </BreadcrumbItem>
    <BreadcrumbItem href="/products">
      Products
    </BreadcrumbItem>
    <BreadcrumbItem href="/products/electronics">
      Electronics
    </BreadcrumbItem>
    <BreadcrumbItem href="/products/electronics/phones">
      Phones
    </BreadcrumbItem>
    <BreadcrumbItem is-current>
      iPhone 15 Pro
    </BreadcrumbItem>
  </Breadcrumbs>
</template>
```

### Menu item

A crumb in the middle of the trail opens a menu for switching between sibling destinations.

```vue
<script setup lang="ts">
import { BreadcrumbItem, Breadcrumbs } from '@astryx-vue/core/Breadcrumbs'

const teamMenu = [
  { label: 'Design' },
  { label: 'Engineering' },
  { type: 'divider' as const },
  { label: 'Data' },
]
</script>

<template>
  <Breadcrumbs>
    <BreadcrumbItem href="/">
      Home
    </BreadcrumbItem>
    <BreadcrumbItem :menu="teamMenu">
      Teams
    </BreadcrumbItem>
    <BreadcrumbItem is-current>
      Overview
    </BreadcrumbItem>
  </Breadcrumbs>
</template>
```

### Choose a team

This crumb uses the menu slot for a radio group. Choosing a team renames the crumb.

```vue
<script setup lang="ts">
import { BreadcrumbItem, BreadcrumbMenuRadioGroup, BreadcrumbMenuRadioItem, Breadcrumbs } from '@astryx-vue/core/Breadcrumbs'
import { Icon } from '@astryx-vue/core/Icon'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
import { computed, ref } from 'vue'

const team = ref('design')
const teamLabel = computed(() => team.value === 'design' ? 'Design' : team.value === 'engineering' ? 'Engineering' : 'Data')
</script>

<template>
  <VStack :gap="3">
    <Breadcrumbs>
      <BreadcrumbItem href="/">
        <template #startIcon>
          <Icon name="carbon:home" />
        </template>
        Home
      </BreadcrumbItem>
      <BreadcrumbItem>
        {{ teamLabel }}
        <template #menu>
          <BreadcrumbMenuRadioGroup v-model="team" label="Team">
            <BreadcrumbMenuRadioItem value="design" label="Design" />
            <BreadcrumbMenuRadioItem value="engineering" label="Engineering" />
            <BreadcrumbMenuRadioItem value="data" label="Data" />
          </BreadcrumbMenuRadioGroup>
        </template>
      </BreadcrumbItem>
      <BreadcrumbItem is-current>
        Overview
      </BreadcrumbItem>
    </Breadcrumbs>
    <Text color="secondary" type="supporting">
      Current team: {{ teamLabel }}
    </Text>
  </VStack>
</template>
```

### Variants

The default trail next to the supporting variant, which stays quieter in a dense admin page.

```vue
<script setup lang="ts">
import { BreadcrumbItem, Breadcrumbs } from '@astryx-vue/core/Breadcrumbs'
import { VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
</script>

<template>
  <VStack :gap="4">
    <VStack :gap="1">
      <Text color="secondary" type="supporting">
        Default
      </Text>
      <Breadcrumbs>
        <BreadcrumbItem href="/">
          Home
        </BreadcrumbItem>
        <BreadcrumbItem href="/projects">
          Projects
        </BreadcrumbItem>
        <BreadcrumbItem is-current>
          My Project
        </BreadcrumbItem>
      </Breadcrumbs>
    </VStack>
    <VStack :gap="1">
      <Text color="secondary" type="supporting">
        Supporting
      </Text>
      <Breadcrumbs variant="supporting">
        <BreadcrumbItem href="/">
          Home
        </BreadcrumbItem>
        <BreadcrumbItem href="/projects">
          Projects
        </BreadcrumbItem>
        <BreadcrumbItem is-current>
          My Project
        </BreadcrumbItem>
      </Breadcrumbs>
    </VStack>
  </VStack>
</template>
```

### Icons

Icons before the labels make the root and the settings section recognizable at a glance.

```vue
<script setup lang="ts">
import { BreadcrumbItem, Breadcrumbs } from '@astryx-vue/core/Breadcrumbs'
</script>

<template>
  <Breadcrumbs>
    <BreadcrumbItem href="/">
      <template #startIcon>
        <span class="i-heroicons-home css-icon css-icon--sm" />
      </template>
      Home
    </BreadcrumbItem>
    <BreadcrumbItem href="/settings">
      <template #startIcon>
        <span class="i-heroicons-cog-6-tooth css-icon css-icon--sm" />
      </template>
      Settings
    </BreadcrumbItem>
    <BreadcrumbItem is-current>
      Profile
    </BreadcrumbItem>
  </Breadcrumbs>
</template>
```

## Breadcrumbs Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `separator` | `string` | `'/'` | Decorative separator between items. |
| `variant` | `BreadcrumbsVariant` | `'default'` | Visual variant. Optional: default, supporting. |
| `label` | `string` | `'Breadcrumb'` | Accessible label for the nav landmark. |

## Breadcrumbs Slots

| Name | Description |
| --- | --- |
| `default` | List of `BreadcrumbItem` elements. |

## BreadcrumbItem Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `href` | `string` | - | Link URL. Renders as a button when omitted. |
| `as` | `string \| Component` | `'a'` | Link root component, such as a router link. Used instead of `a` for items that have an `href` and are not current. |
| `isCurrent` | `boolean` | — | Whether this is the current page. `true` renders a `<span>` with `aria-current="page"`; a current crumb can still open a menu. When omitted and no item is `true`, the last item on the page becomes current: it stays a link and gains `aria-current="page"` and the current style. `false` opts the item out of that detection. |
| `menu` | `BreadcrumbMenuOption[]` | - | Turns the crumb into a menu trigger. The array matches the dropdown menu's data entries, including checkbox rows and radio groups. Mutually exclusive with a link, which is ignored when a menu is set. Ignored when the menu slot is used. |
| `menuSize` | `'sm' \| 'md' \| 'lg'` | `sm` on the supporting variant, otherwise `md` | Size of the menu rows. |

## BreadcrumbItem Slots

| Name | Description |
| --- | --- |
| `default` | Breadcrumb label text. |
| `startIcon` | Icon rendered before the label. The built-in icon component can go here. |
| `menu` | Menu content written by hand, including checkbox and radio rows. The components are `BreadcrumbMenuCheckboxItem`, `BreadcrumbMenuRadioGroup`, and `BreadcrumbMenuRadioItem`. When this slot is set, the `menu` array is not used. |

## BreadcrumbItem Events

| Name | Description |
| --- | --- |
| `click` | Emitted when clicked. Not emitted for the current page. |
