# Breadcrumb

> 展示当前内容的层级位置，用真实链接返回上级，长路径可显式折叠。

网页来源：/components/breadcrumb

版本：@quirekit/ui 0.3.1；源码修订：d79a6b48d00e+worktree。此文档对应当前源码构建，接入方式以开始使用为准。

接入前置：[开始使用](/raw/components/getting-started.md)（Vue、样式、主题与图标 Provider）。

## 基本用法

`items` 按根到当前页排列，每项提供稳定 `key` 和可读 `label`。最后一项标记为当前页；有 `href` 时是链接，没有时为静态文字。

### 示例：breadcrumb/basic

文件：`basic.vue`

```vue
<script setup lang="ts">
import { QuireBreadcrumb } from '@quirekit/ui/vue';
const items = [{ key: 'home', label: '工作空间', href: '#breadcrumb-destination' }, { key: 'docs', label: '团队文档', href: '#breadcrumb-destination' }, { key: 'current', label: '项目说明' }];
</script>
<template>
  <div data-breadcrumb-basic class="grid min-w-0 gap-qk-group p-qk-surface">
    <QuireBreadcrumb :items="items" aria-label="项目位置" />
    <QuireBreadcrumb :items="[{ key: 'current', label: '当前页也可以是链接', href: '#breadcrumb-destination' }]" aria-label="单层位置" />
    <p id="breadcrumb-destination" class="m-0 text-qk-text-secondary">链接使用真实 href。最后一项标识当前位置，没有 href 时仅为文字。</p>
  </div>
</template>
```

## 禁用与空路径

`disabled` 保留文字，移除链接与 Tab 停靠；空数组不显示导航。`ariaLabel` 为同页不同路径提供可区分的名称。

### 示例：breadcrumb/states

文件：`states.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireBreadcrumb, QuireSwitch } from '@quirekit/ui/vue';
const empty = ref(false);
const items = [{ key: 'root', label: '工作空间', href: '#breadcrumb-destination' }, { key: 'locked', label: '受限归档', href: '#breadcrumb-locked', disabled: true }, { key: 'group', label: '静态分类', href: '' }, { key: 'current', label: '只读摘要' }];
</script>
<template>
  <div data-breadcrumb-states class="grid min-w-0 gap-qk-group p-qk-surface">
    <QuireSwitch v-model:checked="empty" label="没有路径数据" />
    <QuireBreadcrumb :items="empty ? [] : items" aria-label="归档位置" />
    <QuireBreadcrumb :items="empty ? [] : items" :max-items="3" aria-label="折叠的只读分类" />
    <p class="m-0 text-qk-text-secondary">{{ empty ? '空数组不创建空导航。' : '受限归档保留名称但不提供链接；静态分类没有跳转行为。' }}</p>
  </div>
</template>
```

## 内容与分隔符

`item`、`leading`、`trailing` 自定义静态内容，`separator` 替换分隔符。插槽接收原始 `index` 和 `current`；不要在链接内嵌套另一个按钮或链接。

### 示例：breadcrumb/content

文件：`content.vue`

```vue
<script setup lang="ts">
import { QuireBreadcrumb, QuireTag } from '@quirekit/ui/vue';
const items = [{ key: 'root', label: '知识库', href: '#breadcrumb-destination' }, { key: 'current', label: '共享规范' }];
</script>
<template>
  <div data-breadcrumb-content class="grid min-w-0 gap-qk-group p-qk-surface">
    <QuireBreadcrumb :items="items" aria-label="带图文的路径">
      <template #leading="{ index }"><span aria-hidden="true">{{ index === 0 ? '◇' : '▤' }}</span></template>
      <template #trailing="{ current }"><QuireTag v-if="current" size="xs">共享</QuireTag></template>
      <template #separator><span>/</span></template>
    </QuireBreadcrumb>
    <QuireBreadcrumb :items="items" aria-label="自定义文字路径">
      <template #item="{ item, index }"><span>{{ index + 1 }}. {{ item.label }}</span></template>
    </QuireBreadcrumb>
    <QuireBreadcrumb :items="[{ key: 'guide', label: '使用指南（新标签页）', href: '/components/getting-started/', target: '_blank' }, { key: 'current', label: '面包屑导航' }]" aria-label="文档路径" />
  </div>
</template>
```

## 折叠层级

`maxItems` 限制可见项数量（含折叠入口，最小 3），保留根与末端层级。默认完整展示并换行；展开入口的名称跟随 [Locale Provider](/raw/components/locale-provider.md) 的语言。Escape 关闭并返回入口，路径更新会关闭旧列表。

### 示例：breadcrumb/overflow

文件：`overflow.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireBreadcrumb, QuireSwitch, type QuireKitBreadcrumbItem } from '@quirekit/ui/vue';
const expanded = ref(false);
const items: QuireKitBreadcrumbItem[] = [
  { key: 'root', label: '工作空间', href: '#breadcrumb-destination' },
  { key: 'team', label: '产品团队', href: '#breadcrumb-destination' },
  { key: 'project', label: '知识库重构项目', href: '#breadcrumb-destination' },
  { key: 'archive', label: '受限旧版资料', disabled: true },
  { key: 'design', label: '设计评审', href: '#breadcrumb-destination' },
  { key: 'current', label: '交互说明' }
];
</script>
<template>
  <div data-breadcrumb-overflow class="grid min-w-0 gap-qk-group p-qk-surface">
    <QuireSwitch v-model:checked="expanded" label="显示完整层级" />
    <QuireBreadcrumb :items="items" :max-items="expanded ? undefined : 3" aria-label="项目文件路径">
      <template #item="{ item, index }"><span>{{ index + 1 }}. {{ item.label }}</span></template>
    </QuireBreadcrumb>
    <p class="m-0 text-qk-text-secondary">折叠后保留根与当前页。打开中间层级后用 Tab 访问真实链接，Escape 返回省略号按钮。</p>
  </div>
</template>
```

## 接入路由

`navigate(item, event)` 通知链接点击。接入客户端路由时，仅拦截普通同窗口点击，保留修饰键和新标签页行为；更新内容后由页面安排目的区域焦点。此示例模拟切换并支持恢复。

### 示例：breadcrumb/navigation

文件：`navigation.vue`

```vue
<script setup lang="ts">
import { nextTick, ref } from 'vue';
import { QuireBreadcrumb, QuireButton, type QuireKitBreadcrumbItem } from '@quirekit/ui/vue';
const paths: QuireKitBreadcrumbItem[] = [{ key: 'root', label: '文档中心', href: '#root' }, { key: 'team', label: '设计团队', href: '#team' }, { key: 'folder', label: '交互规范', href: '#folder' }, { key: 'page', label: '导航说明', href: '#page' }];
const items = ref(paths);
const result = ref('尚未切换位置');
const output = ref<HTMLOutputElement>();
/**
 * Simulates a client router while retaining native modified-click behavior.
 * @param item - Destination owned by this demo's hierarchy.
 * @param event - Browser click retained by the public component.
 */
async function navigate(item: QuireKitBreadcrumbItem, event: MouseEvent): Promise<void> {
  if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || (item.target && item.target !== '_self')) return;
  event.preventDefault();
  items.value = paths.slice(0, paths.findIndex(entry => entry.key === item.key) + 1);
  result.value = `当前位置：${item.label}`;
  // The host moves focus to the destination after replacing the old path.
  await nextTick(); output.value?.focus();
}
</script>
<template>
  <div data-breadcrumb-navigation class="grid min-w-0 gap-qk-group p-qk-surface">
    <QuireBreadcrumb :items="items" :max-items="3" aria-label="宿主控制的路径" @navigate="navigate" />
    <output ref="output" role="status" tabindex="-1">{{ result }}</output>
    <QuireButton @click="items = paths; result = '已恢复完整路径'">恢复完整路径</QuireButton>
    <p class="m-0 text-qk-text-secondary">宿主接管普通导航并更新路径；内容替换后，焦点交给当前位置说明。</p>
  </div>
</template>
```

## 长路径与阅读方向

长名称可以换行；方向跟随语言环境。普通链接使用 Tab 和 Enter，不采用菜单式方向键导航。折叠列表仍可访问完整路径。

### 示例：breadcrumb/long-content

文件：`long-content.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireBreadcrumb, QuireSwitch } from '@quirekit/ui/vue';
const rtl = ref(false);
const items = [{ key: 'root', label: '项目空间', href: '#breadcrumb-destination' }, { key: 'team', label: '跨团队共享的设计资源与阅读体验研究', href: '#breadcrumb-destination' }, { key: 'folder', label: '非常长的目录名称用于检查窄屏中是否保留完整阅读内容', href: '#breadcrumb-destination' }, { key: 'current', label: 'LongUnbrokenDocumentNameForNarrowScreenAndKeyboardReview' }];
</script>
<template>
  <div data-breadcrumb-long class="grid min-w-0 gap-qk-group p-qk-surface">
    <QuireSwitch v-model:checked="rtl" label="从右向左阅读路径" />
    <div :dir="rtl ? 'rtl' : 'ltr'" class="grid min-w-0 gap-qk-group">
      <QuireBreadcrumb :items="items" aria-label="完整长路径" />
      <QuireBreadcrumb :items="items" :max-items="3" aria-label="紧凑长路径" />
    </div>
  </div>
</template>
```

## API

### QuireBreadcrumb

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| items | 是 | — | Ordered locations; the final item is the current page. |
| ariaLabel | 否 | — | Accessible navigation landmark name; defaults to the language pack. |
| maxItems | 否 | — | Visible entries including overflow; values below three are clamped to three. |

**items**

```ts
readonly QuireKitBreadcrumbItem[]
```

```ts
readonly ({
  /** Stable, unique identity; labels and URLs may change independently. */
  key: string;
  /** Readable location name, including when its icon is customized. */
  label: string;
  /** Actual browser destination; omitted values render static text. */
  href?: undefined | string;
  /** Native browsing context, such as _blank. */
  target?: string | undefined;
  /** Native link relationship; new-window links default to noopener noreferrer. */
  rel?: string | undefined;
  /** Keeps this location readable while removing navigation and tab focus. */
  disabled?: boolean | undefined;
})[]
```

**ariaLabel**

```ts
string | undefined
```

```ts
undefined | string
```

**maxItems**

```ts
number | undefined
```

```ts
undefined | number
```

#### Events

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| navigate | 否 | — |  |

**navigate**

```ts
[item: QuireKitBreadcrumbItem, event: MouseEvent]
```

#### Slots

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| item | 否 | — | Static item content; does not replace native link semantics. |
| leading | 否 | — | Static icon or context preceding the label. |
| trailing | 否 | — | Static metadata following the label. |
| separator | 否 | — | Decorative separator; hidden from assistive technology. |

**item**

```ts
QuireKitBreadcrumbSlotProps
```

```ts
{
  /** Original location from the supplied hierarchy. */
  item: {
    /** Stable, unique identity; labels and URLs may change independently. */
    key: string;
    /** Readable location name, including when its icon is customized. */
    label: string;
    /** Actual browser destination; omitted values render static text. */
    href?: undefined | string;
    /** Native browsing context, such as _blank. */
    target?: string | undefined;
    /** Native link relationship; new-window links default to noopener noreferrer. */
    rel?: string | undefined;
    /** Keeps this location readable while removing navigation and tab focus. */
    disabled?: boolean | undefined;
  };
  /** Index in the original, uncollapsed path. */
  index: number;
  /** Whether this is the final location. */
  current: boolean;
}
```

**leading**

```ts
QuireKitBreadcrumbSlotProps
```

```ts
{
  /** Original location from the supplied hierarchy. */
  item: {
    /** Stable, unique identity; labels and URLs may change independently. */
    key: string;
    /** Readable location name, including when its icon is customized. */
    label: string;
    /** Actual browser destination; omitted values render static text. */
    href?: undefined | string;
    /** Native browsing context, such as _blank. */
    target?: string | undefined;
    /** Native link relationship; new-window links default to noopener noreferrer. */
    rel?: string | undefined;
    /** Keeps this location readable while removing navigation and tab focus. */
    disabled?: boolean | undefined;
  };
  /** Index in the original, uncollapsed path. */
  index: number;
  /** Whether this is the final location. */
  current: boolean;
}
```

**trailing**

```ts
QuireKitBreadcrumbSlotProps
```

```ts
{
  /** Original location from the supplied hierarchy. */
  item: {
    /** Stable, unique identity; labels and URLs may change independently. */
    key: string;
    /** Readable location name, including when its icon is customized. */
    label: string;
    /** Actual browser destination; omitted values render static text. */
    href?: undefined | string;
    /** Native browsing context, such as _blank. */
    target?: string | undefined;
    /** Native link relationship; new-window links default to noopener noreferrer. */
    rel?: string | undefined;
    /** Keeps this location readable while removing navigation and tab focus. */
    disabled?: boolean | undefined;
  };
  /** Index in the original, uncollapsed path. */
  index: number;
  /** Whether this is the final location. */
  current: boolean;
}
```

**separator**

```ts
any
```

#### 公开实例成员

无。

#### 相关类型

```ts
type QuireKitBreadcrumbItem = {
  /** Stable, unique identity; labels and URLs may change independently. */
  key: string;
  /** Readable location name, including when its icon is customized. */
  label: string;
  /** Actual browser destination; omitted values render static text. */
  href?: undefined | string;
  /** Native browsing context, such as _blank. */
  target?: string | undefined;
  /** Native link relationship; new-window links default to noopener noreferrer. */
  rel?: string | undefined;
  /** Keeps this location readable while removing navigation and tab focus. */
  disabled?: boolean | undefined;
};
```

```ts
type QuireKitBreadcrumbSlotProps = {
  /** Original location from the supplied hierarchy. */
  item: {
    /** Stable, unique identity; labels and URLs may change independently. */
    key: string;
    /** Readable location name, including when its icon is customized. */
    label: string;
    /** Actual browser destination; omitted values render static text. */
    href?: string | undefined;
    /** Native browsing context, such as _blank. */
    target?: string | undefined;
    /** Native link relationship; new-window links default to noopener noreferrer. */
    rel?: string | undefined;
    /** Keeps this location readable while removing navigation and tab focus. */
    disabled?: boolean | undefined;
  };
  /** Index in the original, uncollapsed path. */
  index: number;
  /** Whether this is the final location. */
  current: boolean;
};
```
