From 68d45c66f98eeebd5872448b839ed387bf65f0f0 Mon Sep 17 00:00:00 2001 From: maoyingjie Date: Thu, 29 Oct 2026 09:03:52 +0800 Subject: [PATCH] fix: disable link navigation and align breadcrumb actions and date focus --- apps/docs/components/breadcrumbs.md | 50 +++-- apps/docs/components/date-picker.md | 2 +- apps/docs/components/date-range-picker.md | 2 +- apps/docs/components/link.md | 4 +- apps/playground/src/App.vue | 7 + docs/compatibility.md | 5 + docs/tasks/ACTIVE.md | 2 + docs/tasks/HD-06-LINK-FOCUS.md | 8 +- docs/upstream.md | 5 + packages/vue/LICENSE.react-aria | 201 ++++++++++++++++++ packages/vue/package.json | 3 +- .../components/breadcrumbs/Breadcrumbs.vue | 13 +- .../breadcrumbs/BreadcrumbsItem.vue | 26 +++ .../vue/src/components/breadcrumbs/context.ts | 4 + .../vue/src/components/breadcrumbs/locale.ts | 55 +++++ .../date-picker/DatePickerTrigger.vue | 6 +- .../DateRangePickerTrigger.vue | 6 +- packages/vue/src/components/link/Link.vue | 30 ++- .../vue/src/components/link/LinkPrimitive.ts | 55 +++++ packages/vue/src/types.ts | 2 +- tests/date-picker-demos.test.ts | 32 +++ tests/fixtures/link-focus.vue | 66 ++++++ tests/package/client-checks.json | 15 ++ tests/package/link-focus-contract.ts | 26 +++ tests/surface-link-spinner.test.ts | 119 ++++++++++- tests/typography-empty-breadcrumbs.test.ts | 82 +++++++ third-party/REACT-ARIA-LICENSE | 201 ++++++++++++++++++ 27 files changed, 983 insertions(+), 44 deletions(-) create mode 100644 packages/vue/LICENSE.react-aria create mode 100644 packages/vue/src/components/breadcrumbs/context.ts create mode 100644 packages/vue/src/components/breadcrumbs/locale.ts create mode 100644 packages/vue/src/components/link/LinkPrimitive.ts create mode 100644 tests/fixtures/link-focus.vue create mode 100644 tests/package/link-focus-contract.ts create mode 100644 third-party/REACT-ARIA-LICENSE diff --git a/apps/docs/components/breadcrumbs.md b/apps/docs/components/breadcrumbs.md index c04e4a1..2610644 100644 --- a/apps/docs/components/breadcrumbs.md +++ b/apps/docs/components/breadcrumbs.md @@ -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 + + 首页 + 产品 + 当前页 + +``` ### 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 不完全一致,本实现以固定提交源码为准。需要独立导航地标时,可由应用在外层使用 `