fix: disable link navigation and align breadcrumb actions and date focus

This commit is contained in:
maoyingjie
2026-10-29 09:03:52 +08:00
parent 680a592e7b
commit 68d45c66f9
27 changed files with 983 additions and 44 deletions
+32 -18
View File
@@ -127,19 +127,33 @@ Breadcrumbs 组件使用以下 CSS 类([查看源码样式](https://github.com
### Breadcrumbs
| 属性 | 类型 | 默认值 | 描述 |
| ------------ | --------------------------- | --------------- | ------------------------------------------------ |
| `aria-label` | `string` | `'Breadcrumbs'` | 面包屑列表的可访问名称。 |
| `isDisabled` | `boolean` | `false` | 是否禁用所有面包屑链接。 |
| `as` | `string` | `'ol'` | 自定义根元素标签;对应上游 `render` 的元素替换。 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定)。 |
| 默认插槽 | - | - | `BreadcrumbsItem` 列表。 |
| `#separator` | - | 默认右箭头图标 | 自定义各项之间的分隔符。 |
| 属性 | 类型 | 默认值 | 描述 |
| ------------ | --------------------------- | ------------------------ | ------------------------------------------------ |
| `aria-label` | `string` | 随 ConfigProvider locale | 面包屑列表的可访问名称,显式值优先。 |
| `isDisabled` | `boolean` | `false` | 是否禁用所有面包屑链接。 |
| `as` | `string` | `'ol'` | 自定义根元素标签;对应上游 `render` 的元素替换。 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定)。 |
| 默认插槽 | - | - | `BreadcrumbsItem` 列表。 |
| `#separator` | - | 默认右箭头图标 | 自定义各项之间的分隔符。 |
根元素同时接收其余 `$attrs`(`data-*`、`id`、`style`、事件等);`aria-label` 为空字符串时回退为 `Breadcrumbs`。`isDisabled` 通过既有禁用作用域传给内部 `Link`,不复制禁用逻辑。
根元素同时接收其余 `$attrs`(`data-*`、`id`、`style`、事件等);`aria-label` 未传或为空字符串时按当前 `ConfigProvider` locale 本地化(默认 en-US 的 Breadcrumbs、zh-CN 的“导航栏”)。`isDisabled` 通过既有禁用作用域传给内部 `Link`,不复制禁用逻辑。
### action 事件
`@action="onAction"` 在非当前、未禁用项被点击或通过 Enter 激活后触发一次。事件参数为项的 `id`(若提供),否则为 Vue `key`,均未提供时使用从 0 开始的位置索引。数字 `0`、字符串 `"0"` 与空字符串分别保留,不做真值回退。调用方 `@click.prevent` 或 `stopImmediatePropagation()` 可以取消该 action;事件本身不替代 href 的浏览器导航。
```vue
<Breadcrumbs @action="(key) => console.log(key)">
<BreadcrumbsItem :id="0">首页</BreadcrumbsItem>
<BreadcrumbsItem id="">产品</BreadcrumbsItem>
<BreadcrumbsItem>当前页</BreadcrumbsItem>
</Breadcrumbs>
```
### BreadcrumbsItem
`id?: string | number` 指定 action 身份,同时透传为 li 的 DOM id;请保持 DOM id 唯一。未传时从 Vue key(或位置索引)取得事件身份。
| 属性 | 类型 | 默认值 | 描述 |
| ------------ | --------------------------- | ------- | -------------------------------------------------------------------------------- |
| `href` | `string` | - | 链接 URL;未提供时渲染不可导航的 `span[role="link"]`,当前项与禁用项也不可导航。 |
@@ -151,22 +165,22 @@ Breadcrumbs 组件使用以下 CSS 类([查看源码样式](https://github.com
| `class` | `string \| Array \| Object` | - | 附加 CSS 类;同时合并到 `li` 与内部链接。 |
| 默认插槽 | `{ isCurrent, isDisabled }` | - | 项内容;可用作用域状态渲染条件内容。 |
`li` 根节点接收除事件处理器外的 `$attrs`;`onClick`、`onKeydown`、`onFocus` 等事件绑定到真实链接,从而复用 `Link` 的禁用拦截与事件顺序。`isLast` 和 `separatorSlot` 由 `Breadcrumbs` 自动注入,不列入公开 `BreadcrumbsItemProps` 类型或 API 表,调用方无需设置。
`li` 根节点接收除事件处理器外的 `$attrs`;`onClick`、`onKeydown`、`onFocus` 等事件绑定到真实链接,从而复用 `Link` 的禁用拦截与事件顺序。`isLast`、`separatorSlot` 和 `itemKey` 由 `Breadcrumbs` 自动注入,不列入公开 `BreadcrumbsItemProps` 类型或 API 表,调用方无需设置。
### 上游差异
| 上游 React 能力 | Vue 实现 |
| ----------------------------- | ------------------------------------------ |
| `Breadcrumbs.Item` 对象子部件 | 独立具名导出 `BreadcrumbsItem` |
| `separator: ReactNode` | `#separator` 插槽,默认图标从基线 SVG 移植 |
| `render` 函数 | `as` 更换元素,属性直接透传 |
| `className` / `children` | `class` / 默认插槽 |
| `onAction` | 未提供;使用链接原生行为或 `@click` |
| 上游 React 能力 | Vue 实现 |
| ----------------------------- | --------------------------------------------- |
| `Breadcrumbs.Item` 对象子部件 | 独立具名导出 `BreadcrumbsItem` |
| `separator: ReactNode` | `#separator` 插槽,默认图标从基线 SVG 移植 |
| `render` 函数 | `as` 更换元素,属性直接透传 |
| `className` / `children` | `class` / 默认插槽 |
| `onAction` | `@action(key)`,取消的点击与禁用/当前项不触发 |
## 无障碍
- 根元素是 `ol`,默认带 `aria-label="Breadcrumbs"`。固定基线的 React Aria Components `Breadcrumbs` 实际渲染 `ol` 而不是 `nav`;中文文档中的“导航地标”描述与源码 DOM 不完全一致,本实现以固定提交源码为准。需要独立导航地标时,可由应用在外层使用 `<nav>`。
- 默认名称是英文常量,不随 locale 自动本地化;需要本地化时显式传入 `aria-label`。
- 默认名称随 ConfigProvider locale 动态更新;显式 `aria-label` 优先,未收录的语言回退英文。
- 最后一项自动附加 `aria-current="page"`,并以 `role="link"`、`aria-disabled="true"`、`tabindex="-1"` 的 `span` 呈现,不可 Tab 聚焦或激活。
- 带 `href` 的可导航非当前项使用原生 `a`,支持标准 Tab、Enter 与浏览器链接行为;未提供 `href` 的非当前项、禁用的非当前项与当前项均以 `span[role="link"]` 呈现。禁用/当前项带 `aria-disabled="true"`、`tabindex="-1"`,不保留 `href`,点击被拦截;未禁用的无 `href` 项保留 `tabindex="0"`。RAC 的禁用 span 省略 `tabindex`,Vue Link 保留 `-1` 供程序化聚焦,两者都不能通过 Tab 聚焦。
- 分隔符默认标记为 `aria-hidden="true"` 与 `role="presentation"`,不进入可访问名称。