Compare commits
26 Commits
35b602e5b9
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 2eb787a0bb | |||
| 6d9e3f31cf | |||
| 5a00e25a25 | |||
| 9f7eb1fa8d | |||
| ae27fb28d1 | |||
| ee37e66d37 | |||
| 9e8d89e48d | |||
| dd4f04c200 | |||
| aa881d21d5 | |||
| bf6cf0f8d1 | |||
| d1528569a8 | |||
| c8d54abefb | |||
| c34faccd70 | |||
| c019768e6a | |||
| 86d76a0675 | |||
| 658dfbb7d9 | |||
| aac93db658 | |||
| 2d7e3d4e1e | |||
| 27cc62e36f | |||
| 68d45c66f9 | |||
| 680a592e7b | |||
| 0b303476c2 | |||
| dc859fb8ae | |||
| 4bfc2ef170 | |||
| 652cf854be | |||
| 28b0b3f0b6 |
@@ -127,9 +127,7 @@ html {
|
||||
gap: 12px;
|
||||
height: 100%;
|
||||
}
|
||||
/* Section tabs keep their text treatment on hover; selection controls color. */
|
||||
.docs-nav-sections nav .hv-link,
|
||||
.docs-nav-sections nav .hv-link:is(:hover, [data-hovered="true"]) {
|
||||
.docs-nav-sections nav .hv-link {
|
||||
text-decoration: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
@@ -146,6 +144,11 @@ html {
|
||||
border-color: var(--accent);
|
||||
color: var(--foreground);
|
||||
}
|
||||
@media (hover: hover) {
|
||||
.docs-nav-sections nav .hv-link:is(:hover, [data-hovered="true"]) {
|
||||
color: var(--foreground);
|
||||
}
|
||||
}
|
||||
.docs-theme-wide {
|
||||
padding: 2px;
|
||||
border-radius: 999px;
|
||||
@@ -474,6 +477,7 @@ html {
|
||||
margin-left: auto;
|
||||
}
|
||||
.search-trigger .hv-kbd {
|
||||
color: inherit;
|
||||
height: 20px;
|
||||
line-height: 20px;
|
||||
font-size: 14px;
|
||||
@@ -485,6 +489,11 @@ html {
|
||||
box-shadow: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
@media (hover: hover) {
|
||||
.search-trigger:is(:hover, [data-hovered="true"]) {
|
||||
color: var(--foreground);
|
||||
}
|
||||
}
|
||||
.dark .search-trigger {
|
||||
background: color-mix(
|
||||
in oklab,
|
||||
@@ -720,8 +729,7 @@ html {
|
||||
.docs-nav-sections nav {
|
||||
gap: 20px;
|
||||
}
|
||||
.docs-nav-sections nav .hv-link,
|
||||
.docs-nav-sections nav .hv-link:is(:hover, [data-hovered="true"]) {
|
||||
.docs-nav-sections nav .hv-link {
|
||||
font-size: 13px;
|
||||
padding-bottom: 6px;
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ Autocomplete 组件支持两种视觉变体:
|
||||
::: warning
|
||||
多选模式下,上游 `Autocomplete.Value` 会把每个选中项在 `ListBox.Item` 中的 children 复制到触发器中,并以符合当前语言环境的分隔符连接:仅包含文本的选项显示为纯文本,但复选框、头像等可见内容会随每个选中项各出现一次;函数形式的 children 也始终以 `isSelected: false` 调用。
|
||||
|
||||
本库不复制子树,而是给 `AutocompleteValue` 的作用域插槽提供 `selectedItems`(`{ key, textValue }[]`)与 `selectedText`(纯文本),因此不存在上述重复渲染问题,但函数形式的插槽同样不携带 `isSelected`。
|
||||
本库不复制子树,而是给 `AutocompleteValue` 的作用域插槽提供 `selectedItems`(`{ key, textValue, item? }[]`,`item` 为根 `items` 中的源数据项)、`selectedItem`(首个选中项)与 `selectedText`(纯文本),调用方可直接用源数据组合头像、可移除标签等丰富展示,因此不存在上述重复渲染问题,但函数形式的插槽同样不携带 `isSelected`。
|
||||
:::
|
||||
|
||||
如需以纯文本显示选中值,请使用 `selectedText`:
|
||||
@@ -437,15 +437,17 @@ Autocomplete 组件使用以下 CSS 类([查看源码样式](https://github.co
|
||||
| `isPlaceholder` | `boolean` | 是否没有选中项 |
|
||||
| `defaultChildren` | `string`(上游为 `ReactNode`) | 缺省文本(选中项文本以逗号连接,否则占位符) |
|
||||
| `selectedText` | `string` | 选中项 `textValue` 的连接文本 |
|
||||
| `selectedItems` | `Array<{ key, textValue }>` | 选中项 |
|
||||
| `selectedItems` | `Array<{ key, textValue, item? }>` | 选中项;`item` 为根 `items` 中的源数据项(集合自发现的项没有) |
|
||||
| `selectedItem` | `{ key, textValue, item? } \| null` | 首个选中项(单选即所选项),便于单选组合 |
|
||||
|
||||
上游 `state.selectedItems`(节点)在本库中是上表的 `selectedItems`(数据);不复制 item 子树,见「多选」说明。
|
||||
上游 `state.selectedItems`(节点)在本库中是上表的 `selectedItems`(数据,条目携带源数据 `item`);不复制 item 子树,见「多选」说明。
|
||||
|
||||
### 过滤函数(`useFilter` 替代)
|
||||
|
||||
上游页面导出的 `useFilter` hook(`contains` / `startsWith` / `endsWith` 与 `sensitivity`)在本库没有对应导出。替代方式:
|
||||
|
||||
- `AutocompleteFilter` 的默认谓词等价于 `useFilter({ sensitivity: "base" }).contains`:按 `ConfigProvider` 的 locale 折叠大小写与变音符号,`cafe` 能命中 `Café`
|
||||
- 调用方自行过滤数据时(虚拟化、异步数据源),可从包根导入 `createBaseContains`(与默认谓词同一实现)保持语义一致:`const { locale } = useLocale(); const contains = createBaseContains(locale.value)`
|
||||
- 需要 `startsWith` / `endsWith` 等语义时,直接给 `:filter="(text, input) => …"` 传函数
|
||||
- 数据源或调用方已过滤时(异步、虚拟化示例),传 `:filter="() => true"` 避免二次过滤
|
||||
|
||||
|
||||
@@ -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"`,不进入可访问名称。
|
||||
|
||||
@@ -133,6 +133,8 @@ import {
|
||||
|
||||
<ComponentPreview name="combo-box-asynchronous-loading" />
|
||||
|
||||
示例的本地数据源模拟固定源的 SWAPI 请求状态机(搜索过滤、游标分页、加载中、滚动到底自动增量加载、取消旧请求与过期响应保护、失败重试);与 SWAPI 的差异是数据为固定 12 条本地角色、延迟为模拟值,失败由「模拟加载失败」开关注入。加载行位于 ListBox 之外(固定源为 `ListBoxLoadMoreItem` 行内哨兵),自动触发语义一致。
|
||||
|
||||
### 默认选中项
|
||||
|
||||
<ComponentPreview name="combo-box-default-selected-key" />
|
||||
@@ -314,7 +316,7 @@ ComboBox 组件使用以下 CSS 类([查看源码样式](https://github.com/he
|
||||
| `placeholder` | `string` | `'Select an item'` | `ComboBoxValue` 的缺省占位文本(上游根上没有该 prop,由 `ComboBoxValue` 的 placeholder 表达) |
|
||||
| `as` | `string` | `'div'` | 自定义根元素标签 |
|
||||
| `as-child` | `boolean` | `false` | 使用唯一子元素作为根节点并合并属性 |
|
||||
| 默认插槽 | `{ isOpen, inputValue, selectedKey, selectedKeys }` | - | 组件内容;作用域提供当前状态 |
|
||||
| 默认插槽 | `{ isOpen, inputValue, selectedKey, selectedKeys, selectedItem }` | - | 组件内容;作用域提供当前状态 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
事件:
|
||||
@@ -334,7 +336,7 @@ ComboBox 组件使用以下 CSS 类([查看源码样式](https://github.com/he
|
||||
|
||||
### 作用域插槽与渲染状态
|
||||
|
||||
默认插槽提供 `{ isOpen, inputValue, selectedKey, selectedKeys }`。上游的 `Render Props` 表格里还有 `state` 与 `selectedItem`:本库不暴露 React Aria 的 state 对象,选中项数据可从 `records`/`selectedKeys` 派生(示例见 `@update:model-value` 与 `ComboBoxValue` 的作用域插槽),该差异不另设等价 prop。
|
||||
默认插槽提供 `{ isOpen, inputValue, selectedKey, selectedKeys, selectedItem }`。上游的 `Render Props` 表格里还有 `state` 与 `selectedItem`:`selectedItem` 以作用域数据补齐(根 `items` 中与单选 key 匹配的源数据项;多选或自定义值时为 `null`,`ComboBoxValue` 的 `selectedItems` 条目也携带同源 `item`),调用方可直接用自己的数据对象组合展示,无需按键反查;本库不暴露 React Aria 的 state 对象,该差异不另设等价 prop。
|
||||
|
||||
### ComboBoxInputGroup
|
||||
|
||||
@@ -350,7 +352,7 @@ ComboBox 组件使用以下 CSS 类([查看源码样式](https://github.com/he
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------- | ---------------------------------- | -------------------- | ----------------------------- |
|
||||
| `placeholder` | `string`(上游为 `ReactNode`) | 根上的 `placeholder` | 未选中任何项时的占位文本 |
|
||||
| 默认插槽 | `{ isPlaceholder, selectedItems }` | - | 自定义已选值展示 |
|
||||
| 默认插槽 | `{ isPlaceholder, selectedItems }` | - | 自定义已选值展示;`selectedItems` 条目为 `{ key, textValue, item? }`(`item` 为根 `items` 中的源数据项) |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
### ComboBoxTrigger
|
||||
|
||||
@@ -187,7 +187,7 @@ DatePicker 支持与真实 Vue/Reka 状态同步的 data 属性与伪状态:
|
||||
|
||||
- **Open**:触发器上 `[data-open="true"]`
|
||||
- **Disabled**:触发器上 `[data-disabled="true"]` 或 `[aria-disabled="true"]`
|
||||
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`。当前 `data-focus-visible` 在任何聚焦时置位(含鼠标点击聚焦),与键盘专属焦点环语义不完全一致;修复列入 HD 队列(HD-06-LINK-FOCUS)
|
||||
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`。聚焦时按真实 DOM 的 `:focus-visible` 判定,鼠标与键盘路径区分;关闭弹层恢复焦点时同样遵循浏览器判定
|
||||
- **Hover**:触发器上 `:hover`
|
||||
- **Invalid**:根容器上 `[data-invalid="true"]` 或 `[aria-invalid="true"]`
|
||||
- **Read only**:根容器上 `[data-readonly="true"]`
|
||||
|
||||
@@ -199,7 +199,7 @@ DateRangePicker 支持与真实 Vue/Reka 状态同步的 data 属性与伪状态
|
||||
|
||||
- **Open**:触发器上 `[data-open="true"]`
|
||||
- **Disabled**:触发器上 `[data-disabled="true"]` 或 `[aria-disabled="true"]`
|
||||
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`。当前 `data-focus-visible` 在任何聚焦时置位(含鼠标点击聚焦),与键盘专属焦点环语义不完全一致;修复列入 HD 队列(HD-06-LINK-FOCUS)
|
||||
- **Focus visible**:触发器上 `:focus-visible` 或 `[data-focus-visible="true"]`。聚焦时按真实 DOM 的 `:focus-visible` 判定,鼠标与键盘路径区分;关闭弹层恢复焦点时同样遵循浏览器判定
|
||||
- **Hover**:触发器上 `:hover`
|
||||
- **Invalid**:根容器上 `[data-invalid="true"]` 或 `[aria-invalid="true"]`
|
||||
- **Read only**:根容器上 `[data-readonly="true"]`
|
||||
|
||||
@@ -83,6 +83,8 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
|
||||
|
||||
Description 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/description.css)):
|
||||
|
||||
> 变体映射 `descriptionVariants` 从 `@heroui-vue/styles` 公开(`@heroui-vue/components` 再导出同一函数与 `DescriptionVariants` 类型);组件渲染的类名由该映射生成。
|
||||
|
||||
#### 基础类 [!toc]
|
||||
|
||||
- `.hv-description` - 基础描述样式,使用 `muted` 文本颜色
|
||||
|
||||
@@ -370,6 +370,7 @@ Dropdown 使用 Menu、MenuItem 与 MenuSection 作为底层组件。以下类
|
||||
| Slots / Props | 说明 |
|
||||
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| 默认插槽 | 第一个子节点是触发条目,其余子节点渲染进子菜单内容 |
|
||||
| `delay` | 悬停展开延迟(毫秒),默认 `200`(与固定源 `useSubmenuTrigger` 一致);键盘展开立即生效并取消挂起的悬停展开,指针离开取消 |
|
||||
| `class`/ARIA | 合并到触发条目元素上 |
|
||||
| 面板参数 | 嵌套 `DropdownPopover` 的 `offset`/`crossOffset`/`shouldFlip`/`containerPadding`/`loop`/`to`、`class`/`style`/`id`/`data-*`/ARIA 与事件都会传给子菜单面板;`isKeyboardDismissDisabled` 为真时 Esc 既不关子层也不关父层,`shouldCloseOnInteractOutside` 返回 `false` 时外部交互不关闭 |
|
||||
|
||||
@@ -408,7 +409,7 @@ Dropdown 组件实现 ARIA 菜单模式,并提供:
|
||||
- 部件导出为具名组件(`DropdownRoot` / `DropdownTrigger` / …),触发器需要显式包裹,官方是把 `Button` 直接放在 `Dropdown` 下。
|
||||
- `Selection`/`Set` 改为 `MenuKey[]`;`onAction`/`onSelectionChange`/`onClose` 改为 Vue 事件;`isOpen`/`onOpenChange` 改为 `open` + `v-model:open`。
|
||||
- 官方 `items` + 渲染函数的数据驱动集合用 `v-for` 表达;`renderEmptyState` 对应 `empty` 插槽。不提供 React Collection 对象模型。
|
||||
- 子菜单悬停展开延迟由底层固定为 100ms,未暴露官方 `delay`(默认 200ms);子菜单面板的 `side`/`align` 由底层固定,只有偏移与碰撞参数可调。
|
||||
- 子菜单悬停展开延迟由 `DropdownSubmenuTrigger` 的 `delay` 配置(默认 200ms,与固定源 `useSubmenuTrigger` 一致):底层 Reka 的固定 100ms 悬停计时被重定为该延迟,键盘展开立即生效并取消挂起的悬停展开,指针离开取消;子菜单面板的 `side`/`align` 由底层固定(贴父项向右、RTL 反向),只有偏移与碰撞参数可调。
|
||||
- `DropdownTrigger` 的作用域插槽只提供 `{ isOpen }`,`DropdownPopover` 只提供 `{ isEntering, isExiting, placement }`;官方 Button/Popover 的完整 render props 未全部覆盖。
|
||||
- `DropdownRoot` 额外渲染一层 `.hv-dropdown` 包裹元素(官方该类没有 DOM 宿主),承载根级 class、style、id、ARIA、data 属性与原生事件。作为 `ButtonGroup` 直接子级时仍保留该容器,接缝样式按容器在组内的位置适配内部触发按钮;根级属性与捕获事件的行为不变。
|
||||
- 条目 `id` 是业务 key,DOM id 为实例级;官方把 key 直接作为 DOM id(Vue 端避免数字 `0` 与字符串 `"0"` 冲突)。
|
||||
|
||||
@@ -178,6 +178,8 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
|
||||
|
||||
FieldError 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/field-error.css)):
|
||||
|
||||
> 变体映射 `fieldErrorVariants` 从 `@heroui-vue/styles` 公开(`@heroui-vue/components` 再导出同一函数与 `FieldErrorVariants` 类型);组件渲染的类名由该映射生成。
|
||||
|
||||
#### 基础类 [!toc]
|
||||
|
||||
- `.hv-field-error` - 基础错误样式,danger 色
|
||||
@@ -210,3 +212,7 @@ FieldError 组件通过以下方式确保无障碍性:
|
||||
## 相关组件
|
||||
|
||||
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [TextArea 多行文本框](./textarea)
|
||||
|
||||
### validationDetails
|
||||
|
||||
作用域插槽还提供 `validationDetails?: ValidityState`。TextField/SearchField 使用真实控件的原生快照,OTP 可显式传入详情(优先)或读取其提交代理快照;其他尚未接入详情的字段为 undefined。可读取 `valueMissing`、`patternMismatch`、`typeMismatch`、`customError` 等原生标志,而不复制字段状态。详情本身不替代 `isInvalid` 或错误文本。
|
||||
|
||||
@@ -82,7 +82,7 @@ InputOTP 组件支持两种视觉变体:
|
||||
|
||||
<ComponentPreview name="input-otp-on-complete" />
|
||||
|
||||
`@complete` 在**首次填满**时触发一次;替换已满值、重复同值或父级同步同一值不会重复触发。示例使用模拟验证(定时器),不发送真实验证码。
|
||||
`@complete` 在已接受值**从未满变为满值**时触发一次;替换已满值、重复同值或父级同步同一值不会重复触发。示例使用模拟验证(定时器),不发送真实验证码。
|
||||
|
||||
### 表单示例
|
||||
|
||||
@@ -94,7 +94,7 @@ InputOTP 组件支持两种视觉变体:
|
||||
|
||||
<ComponentPreview name="input-otp-with-pattern" />
|
||||
|
||||
`pattern` 过滤单字符输入,可使用导出的正则常量。
|
||||
`pattern` 检查整个候选字符串,可使用导出的正则常量;不匹配时拒绝整次编辑。
|
||||
|
||||
### 表单验证
|
||||
|
||||
@@ -177,25 +177,29 @@ InputOTP 组件使用以下 CSS 类([查看源码样式](https://github.com/he
|
||||
|
||||
### InputOTP / InputOTPRoot
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------ | -------------------------- | ----------- | ---------------------------------------------------------------- |
|
||||
| `modelValue` | `string` | - | 受控字符串值;下标对应槽位 |
|
||||
| `defaultValue` | `string` | `''` | 非受控初始值 |
|
||||
| `maxLength` | `number` | 必填 | 槽位数量 / 最大长度 |
|
||||
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 外观变体 |
|
||||
| `isDisabled` | `boolean` | `false` | 禁用 |
|
||||
| `isInvalid` | `boolean` | `false` | 无效展示状态 |
|
||||
| `validationErrors` | `string[]` | `[]` | 校验错误消息 |
|
||||
| `inputClassName` | `string` | - | 附加到真实 input 的类 |
|
||||
| `name` | `string` | - | 表单字段名(隐藏 input 提交一份完整值) |
|
||||
| `required` | `boolean` | `false` | 原生必填 |
|
||||
| `pattern` | `string \| RegExp` | - | 字符过滤正则 |
|
||||
| `mask` | `boolean` | `false` | 密码样式(Reka `mask`) |
|
||||
| `otp` | `boolean` | `false` | 一次性验证码自动填充(`autocomplete="one-time-code"`) |
|
||||
| `placeholder` | `string` | `''` | 空位占位符 |
|
||||
| `id` | `string` | 自动 | 提交桥 id;真实输入派生为 id-slot-index,内部 Label 自动关联首格 |
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------- | ------------------------------- | ------------ | ---------------------------------------------------------------- |
|
||||
| `modelValue` | `string` | - | 受控字符串值;下标对应槽位 |
|
||||
| `defaultValue` | `string` | `''` | 非受控初始值 |
|
||||
| `maxLength` | `number` | 必填 | 槽位数量 / 最大长度 |
|
||||
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 外观变体 |
|
||||
| `isDisabled` | `boolean` | `false` | 禁用 |
|
||||
| `isInvalid` | `boolean` | `false` | 无效展示状态 |
|
||||
| `validationErrors` | `string[]` | `[]` | 校验错误消息 |
|
||||
| `autoFocus` | `boolean` | `false` | 挂载后聚焦真实 input |
|
||||
| `pasteTransformer` | `(text: string) => string` | - | 粘贴转换先于正则检查 |
|
||||
| `textAlign` | `'left' \| 'center' \| 'right'` | `'left'` | 真实 input 对齐 |
|
||||
| `validationDetails` | `ValidityState` | 原生代理快照 | 显式校验标志优先,供 FieldError 读取 |
|
||||
| `inputClassName` | `string` | - | 附加到真实 input 的类 |
|
||||
| `name` | `string` | - | 表单字段名(隐藏 input 提交一份完整值) |
|
||||
| `required` | `boolean` | `false` | 原生必填 |
|
||||
| `pattern` | `string \| RegExp` | - | 整个候选字符串的正则判定 |
|
||||
| `mask` | `boolean` | `false` | 密码样式(Reka `mask`) |
|
||||
| `otp` | `boolean` | `false` | 一次性验证码自动填充(`autocomplete="one-time-code"`) |
|
||||
| `placeholder` | `string` | `''` | 空位占位符 |
|
||||
| `id` | `string` | 自动 | 提交桥 id;真实输入派生为 id-slot-index,内部 Label 自动关联首格 |
|
||||
|
||||
事件:`update:modelValue` / `change`(字符串)、`complete`(首次填满)。
|
||||
事件:`update:modelValue` / `change`(字符串)、`complete`(已接受值从未满变满)。
|
||||
|
||||
### InputOTPGroup / InputOTPSeparator
|
||||
|
||||
@@ -213,17 +217,17 @@ InputOTP 组件使用以下 CSS 类([查看源码样式](https://github.com/he
|
||||
|
||||
### 上游差异
|
||||
|
||||
| 上游 React 能力 | Vue 实现 |
|
||||
| ------------------------------------ | ------------------------------------------------------------------------------------- |
|
||||
| `input-otp` 单隐藏 input | Reka PinInput 多 input + 隐藏提交 input |
|
||||
| `value` / `onChange` 字符串 | `v-model` / `update:modelValue` / `change` |
|
||||
| `onComplete` 跨过长度阈值 | `complete` 仅在首次填满触发 |
|
||||
| `pattern` 整串校验 | 单字符过滤(同样接受导出常量) |
|
||||
| `render` / `OTPInputContext` | 具名插槽部件;槽位状态经上下文 |
|
||||
| `pushPasswordManagerStrategy` | 未提供;`otp` 覆盖 one-time-code 自动填充 |
|
||||
| `validationDetails`(ValidityState) | 未提供;校验结果为 `string \| string[]` 文本 |
|
||||
| `textAlign` / `pasteTransformer` | 未提供(能力缺口,见 HD 队列后续能力卡) |
|
||||
| `autoFocus` / `containerClassName` | 未提供专门 prop;`containerClassName` 被上游公共类型显式 Omit,`autoFocus` 属能力缺口 |
|
||||
| 上游 React 能力 | Vue 实现 |
|
||||
| ------------------------------------ | ------------------------------------------------------------------------- |
|
||||
| `input-otp` 单隐藏 input | Reka PinInput 多 input + 隐藏提交 input |
|
||||
| `value` / `onChange` 字符串 | `v-model` / `update:modelValue` / `change` |
|
||||
| `onComplete` 跨过长度阈值 | `complete` 在已接受值从未满变满时触发;满值替换不重复触发 |
|
||||
| `pattern` 整串校验 | 整个候选字符串按 pattern 检查,拒绝整次不匹配编辑 |
|
||||
| `render` / `OTPInputContext` | 具名插槽部件;槽位状态经上下文 |
|
||||
| `pushPasswordManagerStrategy` | 未提供;`otp` 覆盖 one-time-code 自动填充 |
|
||||
| `validationDetails`(ValidityState) | 作为 prop 传入并通过共享 FieldError 插槽暴露;缺省读取原生校验代理 |
|
||||
| `textAlign` / `pasteTransformer` | 均已提供;转换后的整值再做 pattern 检查 |
|
||||
| `autoFocus` / `containerClassName` | 提供 autoFocus;containerClassName 被上游公共类型显式 Omit,不新增该 prop |
|
||||
|
||||
## 字段与表单
|
||||
|
||||
@@ -243,3 +247,16 @@ Slot 的 keydown/paste 用户处理器在底座编辑前的 capture 边界协调
|
||||
## 相关组件
|
||||
|
||||
[Input 输入框](./input) · [Form 表单](./form) · [Surface 表面](./surface)
|
||||
|
||||
## 粘贴、对齐与完成事件
|
||||
|
||||
- `autoFocus?: boolean`:挂载后聚焦真实槽输入;保留 PinInput 的焦点导航。
|
||||
- `pasteTransformer?: (pastedText: string) => string`:先转换剪贴板文本,再限制到 maxLength 并检查整个候选字符串。例如 `text => text.replaceAll('-', '')` 可接收带分隔符的验证码。不匹配的编辑整次拒绝,不从非法文本中悄悄筛出部分字符;空字符串始终可清空。
|
||||
- `textAlign?: 'left' | 'center' | 'right'`(默认 left):用于各真实透明 input 的文字/选区对齐,视觉 slot 仍按移植 CSS 居中。多 input 结构不伪装为单 input。
|
||||
- `validationDetails?: ValidityState`:传入全部原生 validity 标志,由 FieldError 的作用域插槽读取;显式值优先于校验代理快照。它本身不改变 isInvalid;错误文本和无效状态沿用已有字段协议。
|
||||
|
||||
`complete` 只跟随已接受值从长度不足变为 maxLength 的变化:父级拒绝满值提案不会触发;满值替换或重复相同值不触发;清空/删除后重新填满会再次触发。父级主动设置的已接受值也遵循同一阈值规则。禁用/只读不运行粘贴转换或编辑。
|
||||
|
||||
保留 PinInput 编辑约定:一份完整代码的粘贴从首格替换,短粘贴从当前格替换;完成后焦点位于末格或下一待填格,当前格字符可选择。单 input 的任意跨格文本选区与密码管理器徽标避让不承诺等价;`pushPasswordManagerStrategy` 未提供。`containerClassName` 在固定上游公共类型中已 Omit,不新增。
|
||||
|
||||
`validationErrors` 显式数组由调用方管理;Form 下同名服务端错误在有效编辑提案或 reset 时忽略当前响应,新响应会重新显示。原生 required/错误通过现有提交代理和共享 FieldError 关联;受控 reset 保留父值、非受控恢复 defaultValue,取消 reset 不改变值。
|
||||
|
||||
@@ -88,6 +88,8 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
|
||||
|
||||
Label 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/label.css)):
|
||||
|
||||
> 变体映射 `labelVariants` 从 `@heroui-vue/styles` 公开(`@heroui-vue/components` 再导出同一函数与 `LabelVariants` 类型);组件渲染的类名由该映射生成,状态修饰类随 `isDisabled` / `isInvalid` / `isRequired` 输出。
|
||||
|
||||
#### 基础类 [!toc]
|
||||
|
||||
- `.hv-label` — 基础标签文本样式
|
||||
|
||||
@@ -132,14 +132,14 @@ Link 使用以下 CSS 类:
|
||||
| `target` | `string` | — | 在何处打开链接文档;省略时使用浏览器同窗口默认行为,不输出 target 属性 |
|
||||
| `rel` | `string` | - | 当前文档与链接文档的关系 |
|
||||
| `download` | `boolean \| string` | - | 触发下载而非导航;`true` 渲染 `download`,`false`/未传省略属性 |
|
||||
| `isDisabled` | `boolean` | `false` | 禁用指针与键盘交互;保留可聚焦与 `aria-disabled` |
|
||||
| `isDisabled` | `boolean` | `false` | 禁用激活,移除导航/下载属性;保留 `aria-disabled` 与程序化聚焦 |
|
||||
| `asChild` | `boolean` | `false` | 合并到默认插槽唯一元素,并补充 `role="link"` 与 `tabindex="0"` |
|
||||
| `autoFocus` | `boolean` | - | 挂载后聚焦真实 DOM 根元素(含 asChild) |
|
||||
| `class` | `string` | - | 与默认样式合并的自定义类 |
|
||||
|
||||
默认插槽渲染链接内部内容。作用域插槽提供 `isDisabled`、`isHovered`、`isPressed`、`isFocused`、`isFocusVisible`。`@click` 等 DOM 事件通过 attrs 透传;`isDisabled` 时阻止激活(含 Vue 合并后的监听器数组)。React Aria 的 `onPress` / `PressEvent` 由原生 `click` 适配,不等价。
|
||||
|
||||
`asChild` 适用于 `<a>`、`RouterLink` 等已具备导航能力的元素,以及需要自定义外观的 `span`/`div`:非原生可激活元素会获得 `role="link"`、`tabindex="0"`,Enter 触发一次激活(与点击同一 `click` 路径)。自定义元素上的 `href` 不会由浏览器直接导航,请用 `a` / 路由组件作为 asChild 目标,或在 `@click` 中自行处理跳转。禁用时仍可聚焦以便读出 `aria-disabled`,但不会激活。
|
||||
`asChild` 适用于 `<a>`、`RouterLink` 等已具备导航能力的元素,以及需要自定义外观的 `span`/`div`:非原生可激活元素会获得 `role="link"`、`tabindex="0"`,Enter 触发一次激活(与点击同一 `click` 路径)。自定义元素上的 `href` 不会由浏览器直接导航,请用 `a` / 路由组件作为 asChild 目标,或在 `@click` 中自行处理跳转。禁用时移除根元素的 `href`、`target`、`download`,包括 asChild 子元素自带的对应属性;`tabindex="-1"` 排除 Tab 顺序,仍可通过暴露的 `focus()` 程序化聚焦。重新启用后恢复属性,保留用户处理器和子元素 ref。自定义路由组件应把合并后的属性透传到真实根元素,不应自行覆盖禁用态的导航属性。
|
||||
|
||||
### LinkIcon
|
||||
|
||||
|
||||
@@ -77,10 +77,27 @@ import {
|
||||
|
||||
ListBox 通过 `virtualized` 仅渲染视口附近的行,高效展示大数据集。下面保留基线的 1000 条数据、50px 固定行高和 400px 视口。完整数据传给 `items`,首字母导航、全选和范围选择使用完整集合。
|
||||
|
||||
Vue 使用现有 VueUse 虚拟列表适配,不导出 React 的 `Virtualizer` / `ListLayout`。当前支持竖向固定行高列表;可变行高、虚拟分组标题和拖放布局尚未支持。
|
||||
Vue 使用与 Table 共用的虚拟行几何与 ResizeObserver 测量适配,不导出 React 的 `Virtualizer` / `ListLayout`;布局参数在 ListBox 上直接提供(见下文 ListLayout 映射)。支持竖向固定与可变行高、数据驱动的虚拟分组标题(`items` 项的 `heading` 字段)、`#loader` 加载行以及 `gap` / `padding` 行流布局。拖放布局(放置指示线)在 Vue 侧没有对应实现,`dropIndicatorThickness` 不提供(见 ListLayout 映射记录)。滚动容器自动探测:列表自身可滚时绑定自身,否则绑定最近的滚动祖先(例如弹层整体滚动并配 sticky 搜索框的 Autocomplete)。
|
||||
|
||||
<ComponentPreview name="list-box-virtualization" />
|
||||
|
||||
#### ListLayout 映射
|
||||
|
||||
不导出 React Aria 的 `ListLayout` 实例;等价布局参数直接在 ListBox 上提供,单位均为 px。固定源布局默认 rowHeight 48、headingHeight 48、loaderHeight 48、gap 0、padding 0;Vue ListBox 沿用数据模式 rowHeight 默认 50,其余对应默认保持。上游三个虚拟化示例的显式值(Table 42、ListBox/Autocomplete 50)是示例传值而非布局默认值,示例保持原值不机械统一。
|
||||
|
||||
| ListLayout 参数 | Vue 对应 | 更新语义 |
|
||||
| --- | --- | --- |
|
||||
| `rowHeight` | `rowHeight`(number 或 `(index) => number \| undefined`) | 每次布局重读;响应式高度变化无需重挂载。 |
|
||||
| `estimatedRowHeight` | `estimatedRowHeight` | 函数行高返回 `undefined` 时先估算(数据模式默认 50),挂载后按自然内容测量并修正。 |
|
||||
| `headingHeight` | `headingHeight`(number 或函数) | 按条目索引指定标题高度;返回 `undefined` 开启自然测量。非虚拟分组仍用 `ListBoxSection`。 |
|
||||
| `estimatedHeadingHeight` | `estimatedHeadingHeight` | `headingHeight` 函数返回 `undefined` 时使用的初始估算(默认 48);随后测量真实标题。 |
|
||||
| `loaderHeight` | `loaderHeight` + `#loader` 插槽 | `#loader` 存在时渲染为行流末尾的内容行。 |
|
||||
| `dropIndicatorThickness` | 不提供 | Vue 侧 ListBox/Table 没有拖放实现,无放置指示线可度量;不补空参数冒充能力。 |
|
||||
| `gap` | `gap` | 内容行之间的间距,计入较早一行的行占位;padding 行不计。 |
|
||||
| `padding` | `padding` | 行流两端的占位行,不计 gap。 |
|
||||
|
||||
虚拟分组标题是数据驱动的(`items` 项的 `heading` 字段);动态过滤与异步追加后,条目按逻辑 `id` 保持身份、选择与键盘导航,`aria-posinset` / `aria-setsize` 始终相对完整可见集合计算,窗口外未挂载的行不丢失身份。
|
||||
|
||||
### 自定义勾选图标
|
||||
|
||||
<ComponentPreview name="list-box-custom-check-icon" />
|
||||
@@ -163,10 +180,16 @@ Vue 使用 `as` 修改原生标签,普通和作用域插槽组合内容;状
|
||||
| `loop` | `boolean` | `false` | 方向键到边界后循环。 |
|
||||
| `variant` | `"default" \| "danger"` | `"default"` | 视觉变体。 |
|
||||
| `as` | `string` | `"div"` | 根原生标签。 |
|
||||
| `items` | `readonly T[]`,`T extends ListBoxDataItem` | — | 数据集合,具备唯一的 `id`;作用域插槽接收 `item` 和 `index`。 |
|
||||
| `virtualized` | `boolean` | `false` | 开启竖向固定行高虚拟列表,必须提供 `items`。 |
|
||||
| `rowHeight` | `number` | `50` | 每行高度(px),必须为正数。 |
|
||||
| `overscan` | `number` | `5` | 视口外额外渲染的行数,初始化时确定。 |
|
||||
| `items` | `readonly T[]`,`T extends ListBoxDataItem` | — | 数据集合,具备唯一的 `id`;作用域插槽接收 `item` 和 `index`。虚拟模式下可选 `heading` 字段在其行前渲染分组标题行(仅 `headingHeight` 计高,不参与选择与 `aria-posinset` 索引)。 |
|
||||
| `virtualized` | `boolean` | `false` | 开启竖向虚拟列表,必须提供 `items`。 |
|
||||
| `rowHeight` | `number \| (index: number) => number \| undefined` | `50` | 每行高度(px)。函数映射行索引到可变行高,返回 `undefined` 时先估算再按自然内容测量;响应式高度无需重挂载。 |
|
||||
| `estimatedRowHeight` | `number` | `rowHeight` 数值或 `50` | 可变行高函数返回 `undefined` 时的回退高度(px)。 |
|
||||
| `headingHeight` | `number \| (index: number) => number \| undefined` | `48` | 虚拟分组标题行高度(px)。 |
|
||||
| `estimatedHeadingHeight` | `number` | `48` | 未知标题挂载前的估算(px),自然测量后修正。 |
|
||||
| `loaderHeight` | `number` | `48` | `#loader` 加载行高度(px)。 |
|
||||
| `gap` | `number` | `0` | 内容行(条目/标题/加载行)之间的间距(px);padding 行不计 gap。 |
|
||||
| `padding` | `number` | `0` | 列表内边距(px),渲染为行流两端的占位行。 |
|
||||
| `overscan` | `number` | `5` | 视口外额外渲染的行数,初始化时确定。 |
|
||||
| `aria-label` / `aria-labelledby` | `string` | — | 根列表框的可访问名称。 |
|
||||
| `class` / `style` / DOM 事件 | Vue 原生属性 | — | 透传到根 role=listbox 节点,类增量合并。 |
|
||||
|
||||
@@ -182,6 +205,7 @@ Vue 使用 `as` 修改原生标签,普通和作用域插槽组合内容;状
|
||||
| --------------- | ------------------------------------- | -------------------------------------------- |
|
||||
| 默认插槽 | 数据模式 `{ item: T, index: number }` | 静态部件模式直接放置 Item / Section。 |
|
||||
| `empty` | 无 | items 为空时的内容。 |
|
||||
| `loader` | 无 | 虚拟行流末尾的加载行(如「加载更多」),按 `loaderHeight` 计高。 |
|
||||
| `focus(key?)` | `ListBoxKey?` | 聚焦根或指定可用项;虚拟项先滚动到可见范围。 |
|
||||
| `selectAll()` | 无 | 多选模式下提出全选,跳过禁用项。 |
|
||||
| `element` | `HTMLElement` | 根元素引用。 |
|
||||
@@ -238,3 +262,10 @@ node SSR 输出选中状态、名称和描述;虚拟列表首屏为滚动容
|
||||
## 相关组件
|
||||
|
||||
[Select 选择器](./select) · [ComboBox 组合框](./combo-box) · [Avatar 头像](./avatar)
|
||||
|
||||
|
||||
### 未知高度与滚动容器
|
||||
|
||||
`row-height` 或 `heading-height` 函数返回 `undefined` 时,先按对应 estimated 高度建立窗口,挂载后使用 ResizeObserver 测量自然内容。显式数字高度由调用方保证适合内容;不要同时给未知高度条目强制固定 CSS 高度。`gap` 是内容行之间的空白,不计入条目自己的内容高度;标题、条目和加载行均参与行流,padding 在两端。
|
||||
|
||||
测量缓存按保留类型的逻辑 key 存储,数字 `0` 与字符串 `"0"` 不会串用。容器宽度改变后重测可见内容、失效窗口外的旧宽度缓存;测量修正会保持当前滚动锚点。父滚动容器在空集合时也按 overflow 配置绑定,异步追加不需要重挂载;支持列表自滚与 Autocomplete sticky 搜索框的整体滚动。PageUp/PageDown 使用可见视口和实际行偏移计算目标。`overscan` 可响应式更新。
|
||||
|
||||
@@ -217,6 +217,7 @@ SearchField 与 TextField 共用文本字段内核、表单策略和 ID 协议
|
||||
|
||||
| 属性 | 类型 | 默认值 | 描述 |
|
||||
| ------------------------------------- | -------------------------------------------------------------------- | ---------------------- | ------------------------------------------------- |
|
||||
| `validationErrors` | `string \| string[]` | - | 字段级外部错误,与 Form 同名错误合并 |
|
||||
| `modelValue` / `defaultValue` | `string` | - | 受控值 / 非受控初始值 |
|
||||
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 根与 Group 的视觉变体 |
|
||||
| `fullWidth` | `boolean` | `false` | 根与 Group 全宽 |
|
||||
@@ -232,7 +233,7 @@ SearchField 与 TextField 共用文本字段内核、表单策略和 ID 协议
|
||||
| `class` / `style` | Vue class / style 绑定 | - | 根节点属性;ARIA 下发到输入 |
|
||||
| 默认插槽 | 作用域插槽 | - | 字段部件及状态 |
|
||||
|
||||
服务端错误通过 Form 的 validationErrors 按 name 映射;不提供 SearchField 独立 validationErrors 数组。validate 暂不接受 Promise;FieldError 无完整 React Aria validationDetails。
|
||||
字段级 `validationErrors`(字符串或数组)与 Form 按 name 提供的错误共同接入;`validate` 暂不接受 Promise。FieldError 可读取真实控件的 `validationDetails`(ValidityState 快照)。
|
||||
|
||||
### 事件与暴露
|
||||
|
||||
@@ -270,3 +271,11 @@ SearchField 与 TextField 共用文本字段内核、表单策略和 ID 协议
|
||||
## 相关组件
|
||||
|
||||
[Label 标签](./label) · [Description 描述](./description) · [FieldError 字段错误](./field-error)
|
||||
|
||||
## 字段级错误与焦点
|
||||
|
||||
`autoFocus?: boolean` 在挂载后聚焦真实 input/textarea(禁用控件不聚焦),不落到字段 div。默认插槽提供 `value`、`isFocusWithin`、`isFocusVisible`、`validationErrors` 和 `validationDetails`;根的 `data-focus-within` / `data-focus-visible` 与实际组内焦点和浏览器判定同步。
|
||||
|
||||
`validationErrors?: string | string[]` 用于字段级外部错误;显示顺序为字段错误、Form 中该 name 的错误、已触发的 validate/原生错误,字段与 Form 的重复消息去重。native 策略下外部错误写入真实控件的 customValidity,aria 策略只显示语义错误。`isInvalid` 仍只控制展示,不单独设置 customValidity。
|
||||
|
||||
改变值的输入事件会忽略当前字段错误响应与 Form 错误响应,reset 也会清除它们;新数组/对象引用视为新响应,重新显示。相同响应引用的原地修改不用于重新投递已忽略的错误。字段级响应只影响当前字段,Form 的其他字段错误保留。FieldError 的 `validationDetails` 是只读的原生 ValidityState 标志快照,不是第二套字段值。
|
||||
|
||||
@@ -182,6 +182,8 @@ SwitchGroup 组件使用以下 CSS 类([查看源码样式](https://github.com
|
||||
- `.hv-switch-group--horizontal` - 横向布局
|
||||
- `.hv-switch-group--vertical` - 纵向布局(默认)
|
||||
|
||||
> 变体映射 `switchGroupVariants` 从 `@heroui-vue/styles` 公开(`@heroui-vue/components` 再导出同一函数与 `SwitchGroupVariants` 类型),提供 `base` / `items` 两个槽;组件渲染的类名由该映射生成。
|
||||
|
||||
### 交互状态
|
||||
|
||||
该 Switch 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制:
|
||||
|
||||
@@ -60,6 +60,8 @@ import {
|
||||
|
||||
在 `TableColumn` 上使用 `allows-sorting` 属性可启用列排序。在 `TableContent` 上使用 `sort-descriptor` 与 `update:sort-descriptor` 管理排序状态。将标签包裹在 `TableSortableColumnHeader` 中,并传入列的 `sort-direction` 以渲染默认升序/降序指示器。
|
||||
|
||||
列头是唯一的排序入口:点击、Enter、Space 各触发一次排序(`TableSortableColumnHeader` 的触发按钮承担键盘焦点,点击经冒泡汇入列的单一排序路径)。焦点环显示在列头 `th` 上(基线位置):触发按钮把真实 `:focus-visible` 状态转发到 `th` 的 `[data-focus-visible]` 钩子,按钮自身的 UA 轮廓在列内被抑制。
|
||||
|
||||
<ComponentPreview name="table-sorting" minHeight="380px" />
|
||||
|
||||
### 选择
|
||||
@@ -82,7 +84,7 @@ import {
|
||||
|
||||
### 列宽调整
|
||||
|
||||
将表格包裹在 `TableResizableContainer` 中,并在每个可调整宽度的列内添加 `TableColumnResizer`。列可用 `default-width="1fr"` 表示弹性初始宽度(映射为原生 `width: auto`,共享剩余空间;不实现 RAC 的 fr 权重比例)。
|
||||
将表格包裹在 `TableResizableContainer` 中,并在每个可调整宽度的列内添加 `TableColumnResizer`。列可用 `default-width="Nfr"` 表示按权重分配剩余宽度(与固定源一致):数字为 px、`N%` 为百分比,`Nfr` 列共享扣除固定/百分比列后的剩余宽度并按权重比例分配;未显式设置宽度的列在存在 `fr` 列时按 `1fr` 参与分配。`min-width` / `max-width` 对每列份额生效(超出时按 flex 语义冻结违规列并把余量再分配),容器缩放会重新分配、拖动后的列冻结为其像素宽度,RTL 下几何一致、拖动方向相反。
|
||||
|
||||
<ComponentPreview name="table-column-resizing" minHeight="420px" />
|
||||
|
||||
@@ -94,7 +96,7 @@ import {
|
||||
|
||||
### 虚拟滚动
|
||||
|
||||
仅渲染视口内可见行,从而高效展示大数据集。本库使用固定行高窗口替代 React Aria `Virtualizer`。
|
||||
仅渲染视口内可见行,从而高效展示大数据集。本库以 `useVirtualRows` 行几何组合式替代 React Aria `Virtualizer`,支持固定与可变行高、`gap` / `padding` 与加载行预留(见下文 TableLayout 映射)。示例保留基线的 42px 显式行高、300px 视口与外层滚动容器:原生 `<table>` 不能作为滚动容器(`height` 是最小高度且 `overflow` 需要确定高度,实测 300px 被内容撑到 45036px),而固定源滚动的是虚拟网格元素;列宽用 `minWidth`(fr 语义由 TableContent 列布局承担),长文本按列宽截断。
|
||||
|
||||
<ComponentPreview name="table-virtualization" minHeight="380px" />
|
||||
|
||||
@@ -223,25 +225,25 @@ Table 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制
|
||||
|
||||
### TableColumn
|
||||
|
||||
| Prop / 事件 | 类型 | 默认值 | 描述 |
|
||||
| ------------------------------- | ------------------ | ------- | --------------------------------------------------------------------- |
|
||||
| `as` | `string` | `'th'` | 列头标签,scope=col |
|
||||
| `id` | `string` | — | 排序与树形列 id |
|
||||
| `allowsSorting` / `isRowHeader` | `boolean` | `false` | 排序列 / 对应正文单元格为 th[scope=row] |
|
||||
| `width` / `defaultWidth` | `number \| string` | — | 受控宽度 / 非受控初始宽度;数字为 px,`Nfr` 为弹性 auto(非权重比例) |
|
||||
| `minWidth` / `maxWidth` | `number` | — | 宽度上下限,优先于 Resizer 的缺省边界 |
|
||||
| `update:width` | `number` | — | 拖动/键盘提出的宽度,可使用 v-model:width |
|
||||
| 默认插槽 | 内容 | — | 列标签及排序、调整手柄 |
|
||||
| Prop / 事件 | 类型 | 默认值 | 描述 |
|
||||
| ------------------------------- | ------------------ | ------- | ---------------------------------------------------------------------------------------------------------------------- |
|
||||
| `as` | `string` | `'th'` | 列头标签,scope=col |
|
||||
| `id` | `string` | — | 排序与树形列 id |
|
||||
| `allowsSorting` / `isRowHeader` | `boolean` | `false` | 排序列 / 对应正文单元格为 th[scope=row] |
|
||||
| `width` / `defaultWidth` | `number \| string` | — | 受控宽度 / 非受控初始宽度;数字为 px,`N%` 为百分比,`Nfr` 按权重分配剩余宽度(存在 fr 列时未设宽度的列按 `1fr` 参与) |
|
||||
| `minWidth` / `maxWidth` | `number` | — | 宽度上下限,优先于 Resizer 的缺省边界 |
|
||||
| `update:width` | `number` | — | 拖动/键盘提出的宽度,可使用 v-model:width |
|
||||
| 默认插槽 | 内容 | — | 列标签及排序、调整手柄 |
|
||||
|
||||
### TableBody
|
||||
|
||||
| Prop / 插槽 | 类型 | 默认值 | 描述 |
|
||||
| ----------- | ------------------ | --------- | --------------------------------------------------------------------------- |
|
||||
| `as` | `string` | `'tbody'` | 正文根 |
|
||||
| `empty` | `boolean` | 自动判断 | 为 `true` 时强制空状态;省略时若默认插槽未渲染任何行则视为空 |
|
||||
| `colspan` | `number \| string` | `1` | 空状态单元格跨列数 |
|
||||
| 默认插槽 | 行内容 | — | 动态行使用 v-for |
|
||||
| `#empty` | 空状态 | — | 空数据时渲染;包在 `role="presentation"` 行内,不参与选择、行计数与键盘导航 |
|
||||
| Prop / 插槽 | 类型 | 默认值 | 描述 |
|
||||
| ----------- | ------------------ | -------------------- | -------------------------------------------------------------------------------------------- |
|
||||
| `as` | `string` | `'tbody'` | 正文根 |
|
||||
| `empty` | `boolean` | 自动判断 | 为 `true` 时强制空状态;省略时若默认插槽未渲染任何行则视为空 |
|
||||
| `colspan` | `number \| string` | 自动(实际叶子列数) | 空状态单元格跨列数;缺省跨全部实际叶子列(含选择列与包装渲染的列,随列增减更新),显式值优先 |
|
||||
| 默认插槽 | 行内容 | — | 动态行使用 v-for |
|
||||
| `#empty` | 空状态 | — | 空数据时渲染;包在 `role="presentation"` 行内,不参与选择、行计数与键盘导航 |
|
||||
|
||||
### TableRow
|
||||
|
||||
@@ -249,6 +251,7 @@ Table 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制
|
||||
| --------------- | ---------- | ------- | ------------------------------ |
|
||||
| `as` | `string` | `'tr'` | 行标签 |
|
||||
| `rowKey` | `TableKey` | 必填 | 稳定逻辑 key;代替 React 的 id |
|
||||
| `height` | `number` | — | 精确虚拟行高(px);省略保留自然高度,未知行使用 measureRow 测量。 |
|
||||
| `isDisabled` | `boolean` | `false` | 行禁用,不抢子控件事件 |
|
||||
| `level` | `number` | — | 树形行层级,从 1 开始 |
|
||||
| `hasChildItems` | `boolean` | `false` | 是否有树子项 |
|
||||
@@ -330,7 +333,19 @@ Table 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制
|
||||
|
||||
### TableLayout 与 Vue 虚拟滚动
|
||||
|
||||
未导出 React Aria TableLayout 类。示例使用固定 42px 行高、300px 滚动视口和 overscan 窗口(对齐上游 `layoutOptions.rowHeight/headingHeight = 42`),按完整 rowKeys 处理键盘请求;aria-rowcount 包括表头,aria-rowindex 为逻辑位置。仅当前窗口挂载。可变高度、拖放指标与 RAC 虚拟布局扩展暂不支持,不能把固定行高示例用于多行自动换高的数据。TanStack 示例使用可选 table-core 数据模型(含 `getPaginationRowModel`),库运行时不依赖它。
|
||||
未导出 React Aria TableLayout 类;行几何由公共组合式 `useVirtualRows` / `bindVirtualRows` 提供(共享测量与行几何,不引入选择状态内核:选择、身份与焦点仍归集合/表格模型)。示例使用固定 42px 行高、300px 滚动视口和 overscan 窗口(对齐上游 `layoutOptions.rowHeight/headingHeight = 42`;42 是示例显式值,布局默认 48),按完整 rowKeys 处理键盘请求;aria-rowcount 包括表头,aria-rowindex 为逻辑位置。仅当前窗口挂载。TanStack 示例使用可选 table-core 数据模型(含 `getPaginationRowModel`),库运行时不依赖它。
|
||||
|
||||
| `useVirtualRows` 选项 | 类型 | 默认值 | 描述 |
|
||||
| --- | --- | --- | --- |
|
||||
| `count` | `MaybeRefOrGetter<number>` | — | 表体行数;getter 响应式更新行流。 |
|
||||
| `rowHeight` | `number \| (index: number) => number \| undefined` | — | 行高(px);函数映射行索引到可变行高,返回 `undefined` 回退 `estimatedRowHeight`。每次布局重读。 |
|
||||
| `estimatedRowHeight` | `number \| (index: number) => number` | `48` | 未知行挂载前的估算高度(px),测量后修正。 |
|
||||
| `loaderHeight` | `number` | `0` | 行流末尾的加载行预留(px),在最后一行的 gap 之后、尾部 padding 之前;计入 `totalHeight` 与 `window.padBottom`。 |
|
||||
| `gap` | `number` | `0` | 行之间的间距(px),计入较早一行的 `rowExtentOf`;padding 不计 gap。 |
|
||||
| `padding` | `number` | `0` | 列表内边距(px),计入行流两端(`padTop` 含头部、`padBottom` 含尾部)。 |
|
||||
| `overscan` | `number` | `8` | 视口外额外渲染的行数。 |
|
||||
|
||||
`window` 提供 `start` / `end` / `padTop` / `padBottom`(渲染 `<tr>` 占位的 spacer 高度,padTop + 已渲染行占位(含 gap)+ padBottom 恒等于 `totalHeight`),`scrollToIndex` 按行偏移滚动并夹在行流内,`bindVirtualRows` 把窗口更新绑定到滚动容器(滚动与容器缩放)。TableHeader 始终挂载,表头高度通过实际 DOM 行流起点测量,不增加一个脱离真实表头的估算参数;可用 TableHeader 的 style 设置高度(本例 42px)。`dropIndicatorThickness` 同 ListBox——Vue 侧无拖放实现,不提供空参数。
|
||||
|
||||
## 无障碍
|
||||
|
||||
@@ -339,3 +354,20 @@ Table 同时支持 CSS 伪类与 data 属性,以提供更灵活的状态控制
|
||||
## 相关组件
|
||||
|
||||
[Pagination 分页](./pagination) · [Checkbox 复选框](./checkbox) · [Chip 标签](./chip)
|
||||
|
||||
|
||||
### 自然测量与精确行高
|
||||
|
||||
`useVirtualRows` 只管理布局几何,选择与键盘身份仍由 TableContent 的完整 `rowKeys` 管理。新增能力:
|
||||
|
||||
| API | 说明 |
|
||||
| --- | --- |
|
||||
| `keys?: MaybeRefOrGetter<readonly (string \| number)[]>` | 与行索引对应的稳定身份,保留数字/字符串类型;缺省按索引缓存。 |
|
||||
| `measureRow(index, element)` | 绑定自然高度行的 DOM/组件 ref。rowHeight 函数返回 undefined 时,先估算,再观察真实行高。 |
|
||||
| `resetMeasurements()` | 调用方批量替换窗口外内容后,主动失效旧尺寸缓存。 |
|
||||
| `bindVirtualRows(rows, viewport, { content?, scrollPaddingStart? })` | content 是行流原点,表格默认识别真实 tbody;sticky 遮挡高度可传数字或 getter。绑定负责 scroll、resize 和清理。 |
|
||||
| `TableRow.height?: number` | 显式虚拟行高度(px)。内部保留原生 th/td,并用内容盒承接 padding,避免 42px 行被原生单元格最小内容撑成 45px;省略时保留原有自然布局。 |
|
||||
|
||||
未知高度行使用 `:ref="el => rows.measureRow(index, el)"`,并省略 `TableRow.height`;已知高度行传 `:height="height"`。已知行高不应小于需要展示的内容。`gap` 属于行间距:Table 消费方可用不参与导航的 presentation spacer 行渲染;加载行在行流尾部预留中渲染,不要重复叠加高度。示例保留原生滚动 div,移除额外 table-fixed/ellipsis 限制,42px 的模型与实际行高一致。
|
||||
|
||||
滚动定位会计入 tbody/表头原点及 sticky 遮挡;未知目标挂载测量后会进一步校准。宽度变化会重测自然行并失效窗口外旧尺寸;测量修正保持滚动锚点。使用组合式函数时应处于 Vue setup/effectScope 中,以随组件清理测量观察器。
|
||||
|
||||
@@ -133,6 +133,8 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
|
||||
|
||||
- `.hv-textfield` – 根容器,样式极少(`flex flex-col gap-1`)
|
||||
|
||||
> 变体映射 `textFieldVariants` 从 `@heroui-vue/styles` 公开(`@heroui-vue/components` 再导出同一函数与 `TextFieldVariants` 类型);`full-width` 输出 `.hv-textfield--full-width`,组件根类名由该映射生成。
|
||||
|
||||
> **提示:** 子组件([Label](/components/label)、[Input](/components/input)、[TextArea](/components/textarea)、[Description](/components/description)、[FieldError](/components/field-error))各自拥有 CSS 类与样式,定制方式请参见对应文档。
|
||||
|
||||
### 交互状态
|
||||
@@ -151,6 +153,8 @@ TextField 会根据状态自动管理以下 data 属性:
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------------------------------- | -------------------------------------------------------------------- | -------------------------- | -------------------------------------------------- |
|
||||
| 默认插槽 | `Component` | - | 子组件(Label、Input、Description、FieldError 等) |
|
||||
| `validationErrors` | `string \| string[]` | - | 字段级外部错误,与 Form 同名错误合并 |
|
||||
| `autoFocus` | `boolean` | `false` | 挂载后聚焦真实文本控件 |
|
||||
| `modelValue` | `string` | - | 当前值(受控;`v-model`) |
|
||||
| `defaultValue` | `string` | - | 默认值(非受控) |
|
||||
| `name` | `string` | - | 用于 HTML 表单提交的 input 名称 |
|
||||
@@ -170,7 +174,7 @@ TextField 会根据状态自动管理以下 data 属性:
|
||||
| `form` | `string` | - | 关联外部 form 的 id(下发到真实控件) |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
值使用 `v-model`(`update:modelValue`)。受控值由父级决定,拒绝更新时恢复实际 DOM 值。`name`、原生约束、`autoComplete` / `inputMode` / `form` 与 ARIA 落在真实 `input`/`textarea` 上。服务端/外部错误通过 Form 的 `validation-errors`(按 name 映射)接入,不是 TextField 的 `validationErrors` 数组。
|
||||
值使用 `v-model`(`update:modelValue`)。受控值由父级决定,拒绝更新时恢复实际 DOM 值。`name`、原生约束、`autoComplete` / `inputMode` / `form` 与 ARIA 落在真实 `input`/`textarea` 上。服务端/外部错误既可由字段 `validationErrors`(字符串或数组)传入,也可由 Form 的 `validation-errors` 按 name 映射。
|
||||
|
||||
### 事件
|
||||
|
||||
@@ -232,8 +236,16 @@ const hasError = ref(false);
|
||||
| `isInvalid` | `boolean` | 是否无效 |
|
||||
| `validationErrors` | `string[]` | 当前错误列表 |
|
||||
|
||||
与上游 `TextFieldRenderProps` 的差异:Vue 使用作用域插槽而非 render prop;无 `isFocusWithin` / `isFocusVisible`(聚焦状态由控件自身管理)。
|
||||
Vue 使用类型可解析的作用域插槽;`TextFieldRenderProps` 包含 `value`、`isFocusWithin`、`isFocusVisible` 与 `validationDetails`。组内焦点移动保持 focus-within,移出整个字段才清除。
|
||||
|
||||
## 相关组件
|
||||
|
||||
[Input 输入框](./input) · [TextArea 多行文本框](./textarea) · [Fieldset 字段组](./fieldset)
|
||||
|
||||
## 字段级错误与焦点
|
||||
|
||||
`autoFocus?: boolean` 在挂载后聚焦真实 input/textarea(禁用控件不聚焦),不落到字段 div。默认插槽提供 `value`、`isFocusWithin`、`isFocusVisible`、`validationErrors` 和 `validationDetails`;根的 `data-focus-within` / `data-focus-visible` 与实际组内焦点和浏览器判定同步。
|
||||
|
||||
`validationErrors?: string | string[]` 用于字段级外部错误;显示顺序为字段错误、Form 中该 name 的错误、已触发的 validate/原生错误,字段与 Form 的重复消息去重。native 策略下外部错误写入真实控件的 customValidity,aria 策略只显示语义错误。`isInvalid` 仍只控制展示,不单独设置 customValidity。
|
||||
|
||||
改变值的输入事件会忽略当前字段错误响应与 Form 错误响应,reset 也会清除它们;新数组/对象引用视为新响应,重新显示。相同响应引用的原地修改不用于重新投递已忽略的错误。字段级响应只影响当前字段,Form 的其他字段错误保留。FieldError 的 `validationDetails` 是只读的原生 ValidityState 标志快照,不是第二套字段值。
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
createBaseContains,
|
||||
Description,
|
||||
EmptyState,
|
||||
Label,
|
||||
@@ -20,6 +21,7 @@ import {
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldSearchIcon,
|
||||
useLocale,
|
||||
type ListBoxKey,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
@@ -97,15 +99,19 @@ const allUsers = generateUsers(1000);
|
||||
const selectedKey = ref<ListBoxKey | null>(null);
|
||||
const searchQuery = ref("");
|
||||
|
||||
// 与 AutocompleteFilter 默认谓词共用同一实现(locale 敏感、大小写与变音折叠,
|
||||
// 例如 cafe 能匹配 Café);本示例自行过滤以驱动虚拟滚动,故关闭集合二次过滤。
|
||||
const { locale } = useLocale();
|
||||
const contains = computed(() => createBaseContains(locale.value));
|
||||
|
||||
const filteredUsers = computed(() => {
|
||||
const query = searchQuery.value.trim().toLocaleLowerCase();
|
||||
const query = searchQuery.value.trim();
|
||||
|
||||
if (!query) return allUsers;
|
||||
|
||||
return allUsers.filter(
|
||||
(user) =>
|
||||
user.name.toLocaleLowerCase().includes(query) ||
|
||||
user.email.toLocaleLowerCase().includes(query),
|
||||
contains.value(user.name, query) || contains.value(user.email, query),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -150,12 +156,10 @@ const keepResults = () => true;
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
</SearchField>
|
||||
<ListBox
|
||||
:items="filteredUsers"
|
||||
class="max-h-[320px] overflow-y-auto"
|
||||
:row-height="50"
|
||||
virtualized
|
||||
>
|
||||
<!-- The popover scrolls as a whole (pinned layout): the virtual
|
||||
window binds to that scrolling ancestor, keeping the search
|
||||
field sticky at its top. -->
|
||||
<ListBox :items="filteredUsers" :row-height="50" virtualized>
|
||||
<template #default="{ item }">
|
||||
<ListBoxItem :id="item.id" :text-value="item.name" class="h-full">
|
||||
<div class="flex flex-col">
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
<!-- 适配:源示例请求 SWAPI,这里用本地异步源演示相同状态(取消旧请求、加载中、增量加载)。 -->
|
||||
<!-- 适配说明:固定源此例请求 SWAPI(swapi.py4e.com/api/people,useAsyncList 游标分页 + 行内 ListBoxLoadMoreItem 哨兵)。
|
||||
本示例改用本地异步源模拟同一状态机:搜索过滤、游标分页、加载中、滚动到底自动增量加载、
|
||||
取消旧请求与过期响应保护、失败重试。与 SWAPI 的差异:数据为固定 12 条本地角色(非 82 条远端人员),
|
||||
网络延迟为固定 300ms 模拟(不可观测 DNS/网络错误),失败由「模拟加载失败」开关注入。
|
||||
加载行位于 ListBox 之外(基线为 ListBoxLoadMoreItem 的行内加载行),自动触发语义一致。 -->
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref } from "vue";
|
||||
import { useIntersectionObserver } from "@vueuse/core";
|
||||
import {
|
||||
Button,
|
||||
ComboBox,
|
||||
@@ -39,12 +44,18 @@ const characters: Character[] = [
|
||||
{ id: "Boba Fett", name: "Boba Fett" },
|
||||
];
|
||||
|
||||
const simulateFailure = ref(false);
|
||||
const inputValue = ref("");
|
||||
const items = ref<Character[]>([]);
|
||||
const loading = ref(false);
|
||||
const loadingMore = ref(false);
|
||||
const error = ref(false);
|
||||
const hasMore = ref(false);
|
||||
const sentinel = ref<HTMLElement>();
|
||||
const sentinelVisible = ref(false);
|
||||
let controller: AbortController | undefined;
|
||||
/** Monotonic request token: stale responses are dropped even without abort. */
|
||||
let sequence = 0;
|
||||
|
||||
function matches(query: string) {
|
||||
const text = query.trim().toLocaleLowerCase();
|
||||
@@ -54,39 +65,53 @@ function matches(query: string) {
|
||||
);
|
||||
}
|
||||
|
||||
function mockPage(query: string, offset: number, signal: AbortSignal) {
|
||||
return new Promise<Character[]>((resolve, reject) => {
|
||||
const timer = setTimeout(() => {
|
||||
if (simulateFailure.value) {
|
||||
reject(new Error("模拟加载失败"));
|
||||
return;
|
||||
}
|
||||
resolve(matches(query).slice(offset, offset + PAGE_SIZE));
|
||||
}, PAGE_DELAY);
|
||||
|
||||
signal.addEventListener(
|
||||
"abort",
|
||||
() => {
|
||||
clearTimeout(timer);
|
||||
reject(new DOMException("Aborted", "AbortError"));
|
||||
},
|
||||
{ once: true },
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
async function load(query: string, offset: number, append: boolean) {
|
||||
controller?.abort();
|
||||
const current = new AbortController();
|
||||
const token = ++sequence;
|
||||
|
||||
controller = current;
|
||||
error.value = false;
|
||||
if (append) loadingMore.value = true;
|
||||
else loading.value = true;
|
||||
|
||||
try {
|
||||
const page = await new Promise<Character[]>((resolve, reject) => {
|
||||
const timer = setTimeout(() => {
|
||||
resolve(matches(query).slice(offset, offset + PAGE_SIZE));
|
||||
}, PAGE_DELAY);
|
||||
const page = await mockPage(query, offset, current.signal);
|
||||
|
||||
current.signal.addEventListener(
|
||||
"abort",
|
||||
() => {
|
||||
clearTimeout(timer);
|
||||
reject(new DOMException("Aborted", "AbortError"));
|
||||
},
|
||||
{ once: true },
|
||||
);
|
||||
});
|
||||
|
||||
if (current.signal.aborted) return;
|
||||
// A newer request superseded this one: drop the stale response.
|
||||
if (current.signal.aborted || token !== sequence) return;
|
||||
|
||||
items.value = append ? [...items.value, ...page] : page;
|
||||
hasMore.value = offset + page.length < matches(query).length;
|
||||
} catch {
|
||||
if (current.signal.aborted) return;
|
||||
if (current.signal.aborted || token !== sequence) return;
|
||||
|
||||
items.value = [];
|
||||
hasMore.value = false;
|
||||
error.value = true;
|
||||
if (!append) {
|
||||
items.value = [];
|
||||
hasMore.value = false;
|
||||
}
|
||||
} finally {
|
||||
// A newer request owns the flags once it has taken over the controller.
|
||||
if (controller === current) {
|
||||
@@ -94,6 +119,11 @@ async function load(query: string, offset: number, append: boolean) {
|
||||
loadingMore.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Chain-fill: the fresh page may leave the sentinel inside the viewport, in
|
||||
// which case scrolling is not needed to request the next one.
|
||||
if (sentinelVisible.value && hasMore.value && !error.value)
|
||||
queueMicrotask(() => maybeLoadMore());
|
||||
}
|
||||
|
||||
function handleInputChange(next: string) {
|
||||
@@ -101,11 +131,25 @@ function handleInputChange(next: string) {
|
||||
void load(next, 0, false);
|
||||
}
|
||||
|
||||
function loadMore() {
|
||||
if (loading.value || loadingMore.value || !hasMore.value) return;
|
||||
function maybeLoadMore() {
|
||||
if (loading.value || loadingMore.value || error.value || !hasMore.value) return;
|
||||
void load(inputValue.value, items.value.length, true);
|
||||
}
|
||||
|
||||
function retry() {
|
||||
if (loading.value || loadingMore.value) return;
|
||||
void load(inputValue.value, items.value.length, items.value.length > 0);
|
||||
}
|
||||
|
||||
// Scroll-to-bottom auto incremental loading: the sentinel drives the loads and
|
||||
// in-flight requests are never duplicated. When a fresh page does not push the
|
||||
// sentinel out of view, the load chain keeps filling (the pinned
|
||||
// ListBoxLoadMoreItem re-observes per collection change for the same effect).
|
||||
useIntersectionObserver(sentinel, ([entry]) => {
|
||||
sentinelVisible.value = !!entry?.isIntersecting;
|
||||
if (entry?.isIntersecting) maybeLoadMore();
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
void load(inputValue.value, 0, false);
|
||||
});
|
||||
@@ -116,41 +160,50 @@ onBeforeUnmount(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ComboBox
|
||||
allows-empty-collection
|
||||
class="w-[256px]"
|
||||
:input-value="inputValue"
|
||||
@input-change="handleInputChange"
|
||||
>
|
||||
<Label>选择角色</Label>
|
||||
<ComboBoxInputGroup>
|
||||
<Input placeholder="星球大战角色…" />
|
||||
<ComboBoxTrigger />
|
||||
</ComboBoxInputGroup>
|
||||
<ComboBoxPopover>
|
||||
<ListBox :aria-busy="loading || undefined">
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
<div class="flex flex-col gap-2">
|
||||
<ComboBox
|
||||
allows-empty-collection
|
||||
class="w-[256px]"
|
||||
:input-value="inputValue"
|
||||
@input-change="handleInputChange"
|
||||
>
|
||||
<Label>选择角色</Label>
|
||||
<ComboBoxInputGroup>
|
||||
<Input placeholder="星球大战角色…" />
|
||||
<ComboBoxTrigger />
|
||||
</ComboBoxInputGroup>
|
||||
<ComboBoxPopover class="max-h-80">
|
||||
<ListBox :aria-busy="loading || undefined">
|
||||
<ListBoxItem
|
||||
v-for="item in items"
|
||||
:id="item.id"
|
||||
:key="item.id"
|
||||
:text-value="item.name"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState />
|
||||
</template>
|
||||
</ListBox>
|
||||
<div ref="sentinel" aria-hidden="true" class="h-px" />
|
||||
<div
|
||||
v-if="loadingMore || error"
|
||||
class="flex items-center justify-center gap-2 py-2"
|
||||
role="status"
|
||||
>
|
||||
{{ item.name }}
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
<template #empty>
|
||||
<EmptyState />
|
||||
</template>
|
||||
</ListBox>
|
||||
<div v-if="hasMore" class="flex items-center justify-center gap-2 py-2">
|
||||
<template v-if="loadingMore">
|
||||
<Spinner size="sm" />
|
||||
<span class="text-sm text-muted" role="status">加载更多…</span>
|
||||
</template>
|
||||
<Button v-else variant="ghost" size="sm" @click="loadMore">
|
||||
加载更多…
|
||||
</Button>
|
||||
</div>
|
||||
</ComboBoxPopover>
|
||||
</ComboBox>
|
||||
<template v-if="loadingMore">
|
||||
<Spinner size="sm" />
|
||||
<span class="text-sm text-muted">加载更多…</span>
|
||||
</template>
|
||||
<Button v-else variant="ghost" size="sm" @click="retry">重试</Button>
|
||||
</div>
|
||||
</ComboBoxPopover>
|
||||
</ComboBox>
|
||||
<label class="flex items-center gap-2 text-sm text-muted">
|
||||
<input v-model="simulateFailure" type="checkbox" />
|
||||
模拟加载失败(本地数据源注入;SWAPI 场景为真实网络错误)
|
||||
</label>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableScrollContainer,
|
||||
bindVirtualRows,
|
||||
useVirtualRows,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
interface User {
|
||||
@@ -95,96 +97,86 @@ const users = generateUsers(1000);
|
||||
// Matches the fixed upstream Virtualizer layoutOptions (rowHeight/headingHeight 42).
|
||||
const ITEM_HEIGHT = 42;
|
||||
const rowKeys = users.map((user) => user.id);
|
||||
const VIEWPORT = 300;
|
||||
const OVERSCAN = 8;
|
||||
const scrollTop = ref(0);
|
||||
const scrollEl = ref<HTMLElement | null>(null);
|
||||
|
||||
const startIndex = computed(() =>
|
||||
Math.max(0, Math.floor(scrollTop.value / ITEM_HEIGHT) - OVERSCAN),
|
||||
const rows = useVirtualRows({
|
||||
count: () => users.length,
|
||||
rowHeight: ITEM_HEIGHT,
|
||||
overscan: 8,
|
||||
});
|
||||
const rowWindow = rows.window;
|
||||
const scrollRef = ref<HTMLElement | null>(null);
|
||||
const visible = computed(() =>
|
||||
users.slice(rowWindow.value.start, rowWindow.value.end),
|
||||
);
|
||||
const endIndex = computed(() =>
|
||||
Math.min(
|
||||
users.length,
|
||||
Math.ceil((scrollTop.value + VIEWPORT) / ITEM_HEIGHT) + OVERSCAN,
|
||||
),
|
||||
);
|
||||
const visible = computed(() => users.slice(startIndex.value, endIndex.value));
|
||||
const padTop = computed(() => startIndex.value * ITEM_HEIGHT);
|
||||
const padBottom = computed(() => (users.length - endIndex.value) * ITEM_HEIGHT);
|
||||
|
||||
// The scrolling container is the viewport wrapper: a native table cannot be
|
||||
// one (its height is a minimum and overflow needs a definite height — the
|
||||
// pinned source scrolls its virtual grid, a non-table element).
|
||||
const scrollElement = () => scrollRef.value ?? null;
|
||||
function focusRow(_key: string | number, index: number) {
|
||||
const node = scrollEl.value;
|
||||
if (!node) return;
|
||||
const top = index * ITEM_HEIGHT;
|
||||
if (top < node.scrollTop) node.scrollTop = top;
|
||||
else if (top + ITEM_HEIGHT > node.scrollTop + VIEWPORT)
|
||||
node.scrollTop = top + ITEM_HEIGHT - VIEWPORT;
|
||||
scrollTop.value = node.scrollTop;
|
||||
}
|
||||
function onScroll(event: Event) {
|
||||
scrollTop.value = (event.target as HTMLElement).scrollTop;
|
||||
const element = scrollElement();
|
||||
if (element) rows.scrollToIndex(element, index);
|
||||
}
|
||||
let detach: (() => void) | undefined;
|
||||
onMounted(() => {
|
||||
scrollEl.value?.addEventListener("scroll", onScroll, { passive: true });
|
||||
});
|
||||
onUnmounted(() => {
|
||||
scrollEl.value?.removeEventListener("scroll", onScroll);
|
||||
const element = scrollElement();
|
||||
if (element)
|
||||
detach = bindVirtualRows(rows, element, {
|
||||
content: element.querySelector("tbody") ?? undefined,
|
||||
});
|
||||
});
|
||||
onUnmounted(() => detach?.());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Table>
|
||||
<div
|
||||
ref="scrollEl"
|
||||
class="h-[300px] w-full overflow-auto"
|
||||
data-slot="table-virtual-viewport"
|
||||
>
|
||||
<TableContent
|
||||
aria-label="1000 行虚拟化表格"
|
||||
class="min-w-[700px] table-fixed"
|
||||
:row-keys="rowKeys"
|
||||
:aria-rowcount="users.length + 1"
|
||||
@focus-row="focusRow"
|
||||
<TableScrollContainer>
|
||||
<div
|
||||
ref="scrollRef"
|
||||
class="h-[300px] w-full overflow-auto"
|
||||
data-slot="table-virtual-viewport"
|
||||
>
|
||||
<TableHeader aria-rowindex="1" class="h-full w-full">
|
||||
<TableColumn id="name" is-row-header :min-width="160">
|
||||
姓名
|
||||
</TableColumn>
|
||||
<TableColumn id="role" :min-width="220">角色</TableColumn>
|
||||
<TableColumn id="email" :min-width="240">邮箱</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<tr aria-hidden="true" :style="{ height: padTop + 'px' }" />
|
||||
<TableRow
|
||||
v-for="user in visible"
|
||||
:key="user.id"
|
||||
:row-key="user.id"
|
||||
:aria-rowindex="user.id + 1"
|
||||
:style="{ height: ITEM_HEIGHT + 'px' }"
|
||||
>
|
||||
<TableCell
|
||||
class="whitespace-nowrap overflow-hidden text-ellipsis"
|
||||
:style="{ height: ITEM_HEIGHT + 'px' }"
|
||||
<TableContent
|
||||
aria-label="1000 行虚拟化表格"
|
||||
class="min-w-[700px]"
|
||||
:row-keys="rowKeys"
|
||||
:aria-rowcount="users.length + 1"
|
||||
@focus-row="focusRow"
|
||||
>
|
||||
<TableHeader aria-rowindex="1" style="height: 42px" class="w-full">
|
||||
<TableColumn id="name" is-row-header :min-width="160">
|
||||
姓名
|
||||
</TableColumn>
|
||||
<TableColumn id="role" :min-width="220">角色</TableColumn>
|
||||
<TableColumn id="email" :min-width="240">邮箱</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<tr
|
||||
aria-hidden="true"
|
||||
:style="{ height: rowWindow.padTop + 'px' }"
|
||||
/>
|
||||
<TableRow
|
||||
v-for="user in visible"
|
||||
:key="user.id"
|
||||
:row-key="user.id"
|
||||
:aria-rowindex="user.id + 1"
|
||||
:height="ITEM_HEIGHT"
|
||||
>
|
||||
{{ user.name }}
|
||||
</TableCell>
|
||||
<TableCell
|
||||
class="whitespace-nowrap overflow-hidden text-ellipsis"
|
||||
:style="{ height: ITEM_HEIGHT + 'px' }"
|
||||
>
|
||||
{{ user.role }}
|
||||
</TableCell>
|
||||
<TableCell
|
||||
class="whitespace-nowrap overflow-hidden text-ellipsis"
|
||||
:style="{ height: ITEM_HEIGHT + 'px' }"
|
||||
>
|
||||
{{ user.email }}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<tr aria-hidden="true" :style="{ height: padBottom + 'px' }" />
|
||||
</TableBody>
|
||||
</TableContent>
|
||||
</div>
|
||||
<TableCell>
|
||||
{{ user.name }}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{{ user.role }}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{{ user.email }}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<tr
|
||||
aria-hidden="true"
|
||||
:style="{ height: rowWindow.padBottom + 'px' }"
|
||||
/>
|
||||
</TableBody>
|
||||
</TableContent>
|
||||
</div>
|
||||
</TableScrollContainer>
|
||||
</Table>
|
||||
</template>
|
||||
|
||||
@@ -115,6 +115,22 @@ React 的函数式 `className` / `style` 和 render props 不直接用于 Vue。
|
||||
|
||||
库 CSS 使用 `theme, base, components, utilities` 层顺序。需要确保覆盖优先级时,应检查实际层、选择器与导入顺序;无层的应用 CSS 会优先于普通有层规则。Vue scoped 样式触及嵌套部件时使用 `:deep()` 或直接给该部件添加类,不在文档壳中隐藏组件问题。
|
||||
|
||||
库的基础层还提供全局边框色回退(与固定源一致):
|
||||
|
||||
```css
|
||||
*,
|
||||
::after,
|
||||
::before,
|
||||
::backdrop,
|
||||
::file-selector-button {
|
||||
border-color: var(--border, currentColor);
|
||||
}
|
||||
```
|
||||
|
||||
没有显式 `border-color` 的边框默认使用主题的 `--border`(未定义时回退 `currentColor`)。该规则位于 `base` 层且不带 `!important`,组件规则、工具类与调用方 CSS 都能正常覆盖它;显式边框色(包括 `transparent` 的字段边框)不受影响。
|
||||
|
||||
组件与类名的变体映射从 `@heroui-vue/styles` 公开(`buttonVariants`、`labelVariants`、`descriptionVariants`、`fieldErrorVariants`、`textFieldVariants`、`switchGroupVariants` 等),`@heroui-vue/components` 再导出同一组函数与 `*Variants` 类型;组件内部消费的也是这些映射,状态类只有这一处来源。
|
||||
|
||||
## 创建包装组件
|
||||
|
||||
使用公开 Props 类型与 `tv` 扩展变体。包装组件需要显式管理 `$attrs`、插槽、事件和需要公开的方法,不能把 DOM `ref` 当作普通属性传递。
|
||||
|
||||
@@ -3,6 +3,41 @@ import { defineAsyncComponent } from "vue";
|
||||
|
||||
// Keep regression URLs stable; load only the selected harness.
|
||||
const labs = [
|
||||
{
|
||||
key: "field-otp",
|
||||
title: "字段与验证码",
|
||||
component: defineAsyncComponent(
|
||||
() => import("../../../tests/fixtures/field-otp.vue"),
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "link-focus",
|
||||
title: "链接与日期焦点",
|
||||
component: defineAsyncComponent(
|
||||
() => import("../../../tests/fixtures/link-focus.vue"),
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "table-layout",
|
||||
title: "表格列宽与排序焦点",
|
||||
component: defineAsyncComponent(
|
||||
() => import("../../../tests/fixtures/table-layout.vue"),
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "collections-rtl",
|
||||
title: "子菜单延迟与 RTL 定位",
|
||||
component: defineAsyncComponent(
|
||||
() => import("../../../tests/fixtures/collections-rtl.vue"),
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "virtual-rows",
|
||||
title: "虚拟行布局(变高/分组/加载行)",
|
||||
component: defineAsyncComponent(
|
||||
() => import("../../../tests/fixtures/virtual-rows.vue"),
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "button-group-dropdown",
|
||||
title: "按钮组与下拉根属性",
|
||||
|
||||
+31
-4
@@ -72,7 +72,7 @@
|
||||
| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 |
|
||||
| input-otp | 验证中(M32) | Root/Group/Slot/Separator + 3 正则常量;Reka PinInput 底座;字符串+索引数组;reset/Fieldset/Form/ARIA/mask 已接入;11/11 例;自动填充/IME/读屏未真机验证 |
|
||||
| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default |
|
||||
| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 |
|
||||
| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项虚拟化(固定/可变行高、数据驱动分组标题、#loader 加载行、gap/padding、滚动父级探测);拖放布局未支持故无 dropIndicatorThickness;差异见 LISTBOX-01 与 HD-09 |
|
||||
| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| dropdown | 验证中(B01) | Root/Trigger/Popover/Menu/Section/Item/ItemIndicator/SubmenuIndicator/SubmenuTrigger;17/17 基线例;Reka DropdownMenu;数组选择模型 |
|
||||
@@ -85,7 +85,7 @@
|
||||
| select | 验证中(SELECT-01) | 六部件、19/19 例、单/多选、清空、字段/原生提交/SSR/异步;复用 ListBox + Popover,重点浏览器已验,限制见 SELECT-01 |
|
||||
| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress |
|
||||
| slider | 验证中(SLIDER-01) | 六部件、9/9 基线例;原生 range/局部指针适配,单值/范围、受控/reset/SSR/水合;差异见 SLIDER-01 |
|
||||
| table | 验证中(M36 + 保真返修) | 15 部件;选择/排序/原生语义;13 演示;TableBody `#empty` 空状态;全选半选;defaultWidth 的 1fr 按原生 auto 弹性适配,不承诺 fr 比例;虚拟化固定 42px 窗口、TanStack 分页行模型;RAC TableLayout 不导出,见 M36 |
|
||||
| table | 验证中(M36 + 保真返修) | 15 部件;选择/排序/原生语义;13 演示;TableBody `#empty` 空状态;全选半选;defaultWidth 的 1fr 按原生 auto 弹性适配,不承诺 fr 比例;虚拟化 42px 示例窗口经 useVirtualRows 支持可变行高/估算回退/gap/padding/加载行预留;表头按真实 tbody 原点测量;dropIndicatorThickness(拖放)不提供;TanStack 分页行模型;RAC TableLayout 不导出,见 M36 与 HD-09 |
|
||||
| calendar | 已迁移(有已知差异) | 月/周/日、多选、焦点/翻页、国际历法、年份层与 19 预览;局部日期视图/键盘适配,默认历法边界等差异见 DATE-03。 |
|
||||
| range-calendar | 已迁移(客户端,有已知差异) | RangeCalendar/Root、九个具名日历部件、共享六个 CalendarYearPicker 部件;20/20 基线例;点击/键盘/鼠标拖选、受控拒绝、跨月/RTL;触屏长按拖选未实现,见 RANGE-CALENDAR 结果。 |
|
||||
| calendar-year-picker | 已迁移(DATE-03) | 六个独立具名部件、三列年份、窗口/格式/era、覆盖测量、焦点与关闭;不导出 React 上下文。 |
|
||||
@@ -201,13 +201,13 @@ React render 自定义根类型不支持;原生 attrs/具名部件/作用域
|
||||
|
||||
- **Pagination**:组合式 nav 容器(无 total/page 状态机);具名部件含 Link/Previous/Next(原生 button)、Ellipsis、图标默认 SVG。9/9 基线示例。`onPress`→`@click`。详见 [M30](component-notes.md)。
|
||||
- **Header**:集合/分组标题,原生 `<header>`(已核对 RAC 契约)。基线无独立文档/演示;自编 3 例并标注。详见 [M31](component-notes.md)。
|
||||
- **InputOTP**:Reka PinInput 底座;公开字符串 + 内部索引数组(中间空位不左移);complete 仅首次填满。11/11 示例。消费 fieldContextKey,未改共享内核。真实自动填充/IME/读屏未验证。详见 [M32](component-notes.md)。
|
||||
- **InputOTP**:Reka PinInput 底座;公开字符串 + 内部索引数组(中间空位不左移);complete 已按HD-07收口为已接受值从未满变满。11/11 示例。消费 fieldContextKey,未改共享内核。真实自动填充/IME/读屏未验证。详见 [M32](component-notes.md)。
|
||||
|
||||
以上不构成整库完成声明;逐像素、读屏、Nuxt 水合、独立安装仍未验收。
|
||||
|
||||
## M35–M36 Toast / Table 接手收尾(2026-10-24)
|
||||
|
||||
Toast 11/11 与 Table 13/13 预览、各部件 Props、文档和默认源样式已接入。队列隔离/测量/焦点/SSR 与表格导航/范围/逻辑行/响应式列宽已补齐,详见 [最终验收](component-notes.md)。Table 虚拟化为固定行高窗口,不导出 RAC TableLayout,不声称可变行高/拖放/完整 RAC API。读屏、真机、Nuxt 和自动逐像素未验。
|
||||
Toast 11/11 与 Table 13/13 预览、各部件 Props、文档和默认源样式已接入。队列隔离/测量/焦点/SSR 与表格导航/范围/逻辑行/响应式列宽已补齐,详见 [最终验收](component-notes.md)。Table 虚拟化经 useVirtualRows 支持可变行高与布局参数(不导出 RAC TableLayout 实例),拖放与分区表头布局不支持,不声称完整 RAC API。读屏、真机、Nuxt 和自动逐像素未验。
|
||||
|
||||
## DOCS-01 文档架构(2026-10-24)
|
||||
|
||||
@@ -290,3 +290,30 @@ ComboBox/Autocomplete的正式组合、原30项返修和本轮定位/ref/ARIA/lo
|
||||
固定源六篇56章节的实现证据与差异见 [Handbook审计](handbook-audit.md)。修复 data-scrollbar 三模式、八类浮层/Skeleton/Drawer 的减少动效与动态取消动画后的进入标记清理。按需 CSS 子路径、公共 useTheme、局部主题自动跨 Teleport 及 Skeleton 动画变量的局部/动态读取仍未提供;不声明所有组件已完成全部规范的浏览器验收。逐项场景与实际验证见 [任务结果](tasks/results/HANDBOOK-IMPLEMENTATION-AUDIT.md)。
|
||||
|
||||
HD-01(2026-10-28):按钮/切换组与导航示例已恢复固定cn基线;ButtonGroup内Dropdown保留根attrs/事件,以容器位置适配接缝。HD01-R1已关闭;不升级整族API兼容状态,详见[结果](tasks/results/HD-01-BUTTON-NAV-DEMOS.md)。
|
||||
|
||||
## HD-05 styles 导出与全局边框回退(2026-10-28)
|
||||
|
||||
`@heroui-vue/styles` 增量补齐固定源缺失的 5 个 tv 映射与类型:`labelVariants`/`descriptionVariants`/`fieldErrorVariants`/`textFieldVariants`/`switchGroupVariants`(hv- 命名空间,变体集合与默认值与 `heroui/packages/styles/src/components/{label,description,field-error,textfield,switch-group}/*.styles.ts` 逐键一致),`@heroui-vue/components` 再导出同一组函数与 `*Variants` 类型。Label/Description/FieldError/useTextField/SwitchGroup 改为消费同一映射,状态类只保留一处来源,渲染类输出不变(tests/shared-field-styles.test.ts 钉住映射输出与组件输出一致)。恢复 `base` 层全局边框色回退 `border-color: var(--border, currentColor)`(与固定源 base/base.css 同选择器、同层序:preflight 之后);独立 tarball 消费者真实浏览器验证浅/深 `--border`、显式边框色(含字段透明边框)、调用方普通 CSS 覆盖(含与库同选择器的注入规则)与 `--border` 缺失时的 currentColor 回退,CSSOM 确认规则位于 base 层且无 `!important`。`view-transition-name`/`::view-transition` 两条上游全局规则经核查无使用证据(库与文档站均未使用 View Transitions API),不迁移、不建专项。chip `size:"md"`、kbd `variant:"default"` 等效默认类、reduced-motion、Spinner 定尺、Table th 行头、定位补偿与 HD-01~HD-04 成果均未改动。见 [任务结果](tasks/results/HD-05-STYLES.md)。
|
||||
|
||||
## HD-06 链接与日期焦点(2026-10-29)
|
||||
|
||||
禁用 Link 移除 href/target/download,包括 asChild 子节点的导航属性,保持 aria-disabled、tabindex=-1 与暴露的 focus;启用恢复,用户事件取消和子 ref 保留。Breadcrumbs 当前/禁用项原已用 span,不重复改写;新增按 ConfigProvider locale 的默认名称及 @action(key),保持 id/key 的数字0与空串身份,取消的激活不通知 action。两个日期触发器按实际 :focus-visible 更新状态标记,鼠标/Tab/关闭恢复由浏览器判定。证据见 [HD-06结果](tasks/results/HD-06-LINK-FOCUS.md)。
|
||||
|
||||
## HD-07 字段与OTP公共能力(2026-10-29)
|
||||
|
||||
TextField/SearchField共享autoFocus、组内focus状态、字段级validationErrors与Form错误合并;SearchField槽value与文本值同源。FieldError按共享FieldContext可读取ValidityState快照,TextField/SearchField来自真实控件、OTP支持显式validationDetails或原生提交代理。OTP补autoFocus/pasteTransformer/textAlign,整值pattern与accepted complete对照固定input-otp1.5.0:非法整次编辑拒绝、受控拒绝不complete、满值替换不重复、清空重填再通知。PinInput索引空位与单字符串提交保留;视觉槽对齐、跨格选区、密码管理器策略等Vue边界见组件文档及[任务结果](tasks/results/HD-07-FIELD-OTP.md)。
|
||||
|
||||
## HD-08 Table 空状态、排序焦点与列宽(2026-10-29)
|
||||
|
||||
TableBody 空状态默认跨全部实际叶子列(含选择列与包装渲染的 TableColumn,随列增减响应式更新;未测量环境回退 1),显式 `colspan` 仍优先;保持 vnode 级空判定,不执行未知组件 setup/render 探测。排序保持列头单一激活路径:点击、Enter、Space 各一次(真实浏览器三手势逐一计数),触发按钮保留键盘焦点与 API,把真实 `:focus-visible` 转发到 `th` 的 `[data-focus-visible]` 钩子,焦点环回到基线位置(th 内嵌 2px 环,按钮 UA 轮廓在列内抑制),浅深主题均实测;`aria-sort="none"` 对可排序未排序列属基线行为(react-aria useTableColumnHeader 同款),维持不变。`defaultWidth="Nfr"` 按固定源权重语义实现(移植 react-stately TableColumnLayout/TableUtils 的 flex-grow 解析,Apache-2.0):px/百分比固定列先扣、fr 列按权重分享剩余宽度、min/max 以违规冻结+再分配收敛、整数级联取整保证列宽和等于表宽;存在 fr 列时未设宽度的列按 `1fr` 参与并启用 `table-layout: fixed` 精确几何,容器缩放重分配、拖动列冻结为像素宽度、RTL 几何一致且拖动方向相反,未测量环境(jsdom)保持原生宽度。保留原生 `th scope=row`、圆角选择器与 resizer `z-index` 修复;`.table__cell` 的 `text-start font-normal` 经实测确认会阻断调用方祖先继承(祖先 font-bold/text-center 不下传),收窄为 `th.hv-table__cell { text-align: inherit; font-weight: inherit }`:行头保持基线 td 排版同时保留调用方级联。真实浏览器几何/拖动/焦点验证见 [任务结果](tasks/results/HD-08-TABLE.md)。
|
||||
|
||||
## HD-10 异步加载、过滤与触发器语义(2026-10-29)
|
||||
|
||||
ComboBox 异步例补滚动到底自动增量加载(IntersectionObserver 哨兵 + 续载链,等价固定源 ListBoxLoadMoreItem 的集合变更重挂载语义),保留取消旧请求(AbortController)与过期响应保护(单调序号令牌);查询切换不混入旧数据;失败进入错误态并可重试(本地数据源以「模拟加载失败」开关注入失败)。本地数据源与固定源 SWAPI 的差异(12 条本地角色/模拟 300ms 延迟/可注入失败)已在示例注释与 combo-box.md 说明。Select 异步例的 IntersectionObserver 未重复实现,真实网络滚动触发经浏览器验证(20→180 条无重复)。Autocomplete 虚拟化例与默认过滤共用 `createBaseContains`(Intl.Collator base 敏感,大小写与变音折叠,cafe 匹配 Café);该匹配器从包根公开,与默认谓词同一实现。Autocomplete 触发器语义经真实浏览器核实:role=button/tabindex=0 为单一 Tab 停靠点(clear button tabindex=-1)、Tab 离开组合、Enter/Space 打开、Escape 关闭并回焦、Delete/Backspace 清除、组合输入(isComposing/229)不触发;插槽数据补齐组合能力——`AutocompleteValue` 提供 `selectedItem` 与携带源数据 `item` 的 `selectedItems`,`ComboBox` 根插槽补 `selectedItem`(均取自根 `items`,集合自发现项为 undefined),不执行未知组件 setup/render、不复制子组件。Dropdown 子菜单 hover 延迟对齐固定源 `useSubmenuTrigger` 契约:新增 `delay`(默认 200ms),底层 Reka 的固定 100ms 悬停计时经受控 open 门重定为该延迟,键盘展开立即生效并取消挂起悬停、指针离开取消;RTL 定位由 Reka 按方向固定(贴父项向右、RTL 向左),真实浏览器 RTL/LTR 几何与延迟实测见 [任务结果](tasks/results/HD-10-COLLECTIONS.md)。Button/Avatar 触发器布局补偿保留(浏览器证据:补偿规则胜出,inline-flex 经 flex 子项块化显示为 flex,非基线 inline-block)。
|
||||
|
||||
## HD-09 虚拟布局能力(2026-10-29)
|
||||
|
||||
固定源 ListLayout/TableLayout 的布局默认与示例显式传值分别记录:布局行高48,示例Table42、ListBox/Autocomplete50;Vue ListBox沿用数据模式默认50,Table估算缺省48。ListBox支持函数式rowHeight/headingHeight、对应estimated高度、类型保真的实测缓存、分组标题/loader/gap/padding;与Table共用useVirtualRows窗口与测量。父滚动绑定支持空→长集合和sticky遮挡,选择与焦点仍归既有集合模型。TableRow.height提供精确原生行几何,表头始终挂载并按真实tbody原点测量;未知行绑定measureRow后自然测量,容器变宽/变窄重测,测量修正保留锚点。正式表格示例42px模型/DOM一致,保留外层原生滚动div,移除额外table-fixed/ellipsis。无拖放实现,不提供空dropIndicatorThickness。Autocomplete整体滚动高度max-h-[min(400px,70vh)]仍是上游可用空间钳制的近似差异。最终证据见[任务结果](tasks/results/HD-09-VIRTUALIZATION.md)。
|
||||
|
||||
|
||||
HD09-R1:ListBox 与 Table 共用 useVirtualRows 的自然测量、类型保真尺寸缓存、前缀和窗口及滚动锚定。ListBox 补 estimatedHeadingHeight/函数式 headingHeight;父滚动容器支持空→长集合和 sticky 遮挡。TableRow.height 是 Vue 的精确几何适配,保留原生行头,TableHeader 常驻并按真实 tbody 起点测量;不再将表头误称为未实现的分区布局。正式表格示例 42px 模型/DOM 一致,移除多余截断和固定列布局。以任务结果最终验收节覆盖原实施记录中的估算回退和45px边框裁决。
|
||||
|
||||
@@ -22,3 +22,34 @@
|
||||
- [结果](results/HD-04-DOCS.md)逐条核销:范围1过期/虚构文案(input TextField、color-field ColorPicker、header Header.Root与菜单未迁移、radio-group三处Checkbox残留、input-otp虚构data-complete)全部修正并带源码依据;范围2自链接清除、toggle-button禁用选择器改实、Header MenuSection注册说明+集合分组示例(单测+浏览器双证aria-labelledby链路);范围3 button/accordion/card/switch/ColorField.Group/InputOTP补部件API、CSS类、交互状态与真实全局样式示例,input-group补两段用法示例章;范围4 RelatedComponents按固定映射迁移(64页+2补节+7空映射删节,9样本链接实测),RelatedShowcases核实仅2案例、依赖showcase站不迁移不占位;范围5 granularity/visibleYears三处口径统一(以Reka推断与year-picker实现为证),HD-03转交项全部核销(focus-visible归HD-06已如实注明),新示例2个+empty-state去重+回退边界兼容说明;范围6 minHeight/isBgSolid按上游30处补齐(实测生效),tabs-overflow实测保留max-w-full(内部滚动/箭头正常)。全量110文件1630项、typecheck、build:docs通过;未改公开API/styles无需tarball。遗留:RelatedShowcases待showcase站决策;button-toggle.test.ts间歇失败为预存在(基线对照),建议归HD-11排查。
|
||||
|
||||
- HD-04 已验收:复核补修 f9938eea8c48958991294d687697766259482af2,修正文档CSS示例/状态节点并恢复四页相关案例卡片(链接上游React详情,无本地showcase站)。全量110文件1631项、最终docs-shell14项、类型、文档构建通过。按用户授权合入main并push origin/main;工作区释放,下一项HD-05-STYLES未启动,保留5173/5174。
|
||||
|
||||
- HD-05-STYLES已实施待复核,工作区释放;分支task/hd-05-styles,起点35b602e(main tip,含HD-04验收与复核补修f9938ee),实施dc859fb8aeacac7eb3a798676356cb2c387e5d45。
|
||||
- [结果](results/HD-05-STYLES.md)逐条核销:范围1 styles入口增量补 labelVariants/descriptionVariants/fieldErrorVariants/textFieldVariants/switchGroupVariants 五映射与类型(变体/默认值/slot 与固定源逐键一致),Label/Description/FieldError/useTextField/SwitchGroup 改为消费同一映射(类输出不变,映射↔组件一致性单测钉住);范围2 恢复 base 层全局 border-color: var(--border, currentColor) 回退(与固定源同层同序),独立 tarball 消费者真实浏览器验证浅/深、默认边框、显式色(含字段透明边框)、调用方普通/同选择器覆盖、--border 缺失 currentColor 回退,CSSOM 证 base 层无 !important;范围3 view-transition 两规则核查无使用证据,记录无需修改不建专项;范围4 chip/kbd/reduced-motion/Spinner/Table th/定位补偿与 HD-01~HD-04 成果零改动(未恢复日期弹层 w-full 强制规则)。全量111文件1634项、typecheck、build:docs、shared-styles/api-root-aliases/handbook-styles 最终tarball(运行时+类型两种解析)通过;任务卡 checks 重复项已清理并补实际检查。
|
||||
|
||||
- HD-05 已验收:独立复核0b303476c2d682a47157f345fcc0a5ab0a23aa8d,实施dc859fb无功能阻断,仅纠正结果记录CSS特异性表述。全量111文件1634项、类型、文档构建、shared-styles/api-root-aliases/handbook-styles最终tarball及本轮独立消费者5198浅深/覆盖/回退均通过。按用户授权合入main并push origin/main;工作区释放,下一项HD-06-LINK-FOCUS未启动。停止本轮5198,保留原5173/5174及他人5199服务。
|
||||
|
||||
- HD-06-LINK-FOCUS执行中:分支task/hd-06-link-focus,起点680a592e7b95bd52592edc19d1b8654b30b53a1c;本会话亲自实施并按用户授权验收后合并push。范围:Link禁用导航/asChild/ref、日期真实focus-visible、Breadcrumbs locale/action。5173保持,5174原已停止,本轮重新启动用于公开组合浏览器验收。
|
||||
|
||||
- HD-06 已完成验收:实施68d45c66f98eeebd5872448b839ed387bf65f0f0;Link原生/asChild禁用导航及ref/取消语义、Breadcrumbs locale/action、日期真实focus-visible全部核销,见results/HD-06-LINK-FOCUS.md。全量111文件1641项、类型、文档/playground构建、四个最终tarball契约与真实浏览器通过。按用户授权合入main并push origin/main;工作区释放,下一项HD-07-FIELD-OTP未启动,保留5173及本轮重启的5174。
|
||||
|
||||
- HD-07-FIELD-OTP执行中:分支task/hd-07-field-otp,实际起点27cc62e36f16bc16843ccf25f202340eeac38871;本会话亲自补字段focus/autoFocus/错误数组与ValidityState、SearchField槽value,以及OTP autoFocus/pasteTransformer/textAlign和固定1.5.0的pattern/complete契约,完成后按用户授权合并push。
|
||||
|
||||
- HD-07 已完成验收:实施2d7e3d4e1e12403bb90e92e393bc7fb798a5a2ba;字段共享autoFocus/focus/validationErrors/ValidityState、SearchField槽value、OTP四项props与固定1.5.0整值pattern/accepted complete全部核销,见results/HD-07-FIELD-OTP.md。全量111文件1654项、类型、最终docs/playground构建、四组tarball与真实浏览器通过。按用户授权合入main并push origin/main;工作区释放,下一项HD-08未启动,保留5173/5174。
|
||||
|
||||
- HD-08-TABLE已实施待复核,工作区释放;分支task/hd-08-table,起点aac93db65812a273c887709af4bf1a846439d8bb(main tip,含HD-07验收),实施658dfbb7d920255e48e1b9cf99e15e34f11ec640。
|
||||
- [结果](results/HD-08-TABLE.md)逐条核销:范围1空状态默认跨全部实际叶子列(选择列/包装列自注册计数、动态增减响应、显式colspan优先、不探测未知组件);范围2排序点击/Enter/Space保持单次激活(实测1/1/1),真实:focus-visible转发到th的data-focus-visible钩子恢复基线inset焦点环(浅深双主题实测、按钮UA环列内抑制;非删button非补类名),aria-sort="none"核实为基线行为不改;范围3移植react-stately calculateColumnSizes实现Nfr权重分配(固定/百分比先扣、min/max违规冻结再分配、级联取整、table-layout:fixed精确几何、容器缩放重分配、拖动冻结、RTL同几何反向拖动;900/620/1400三档真实浏览器几何逐毫符合约束),未测量环境保持原生宽度;范围4保留th scope=row/圆角/resizer z-index,text-start/font-normal实测确认阻断调用方继承后收窄为th.hv-table__cell{inherit}。全量111文件1657项、typecheck、build:docs、m35-m36(补两CSS标记)/handbook-styles最终tarball通过;fixture落tests/fixtures/table-layout.vue(playground注册)。遗留:虚拟化归HD-09;auto+fr混合口径与拖动中间分布差异已记录。
|
||||
|
||||
- HD-08 已验收:复核86d76a0,集成人补修c019768e6ac45410cd0f403a325ee0de9727e4eb,关闭固定列maxWidth/CSS不一致、无效fr不收敛及补修后的父容器缩小约束问题。全量111文件1658项、类型、最终docs/playground构建、m35-m36/handbook-styles最终tarball和真实浏览器空态/键盘焦点/几何/拖动/RTL通过,见同一结果表。按用户授权合入main并push origin/main;工作区释放,保留5173/5174,下一任务未启动。
|
||||
|
||||
- HD-10-COLLECTIONS已实施待复核,工作区释放;分支task/hd-10-collections,起点c34faccd7051a3c17bc510da05858ca29fdaf1cc(main tip,含HD-08验收与集成补修c019768),实施c8d54abefbf668fe10f2f7f6ab6ecca945a471e3。
|
||||
- [结果](results/HD-10-COLLECTIONS.md)逐条核销:范围1 ComboBox异步例补滚动到底自动增量加载(哨兵+续载链)、防重复/旧请求/过期响应(abort+序号令牌)、失败重试与SWAPI差异注记;Select既有IntersectionObserver真实网络滚动实测(20→180无重复)未重复实现。范围2 createBaseContains公开导出与虚拟化示例/默认过滤共用(cafe匹配Café既有测试钉住)。范围3触发器role/tabindex/删除键/完整焦点模型真实浏览器核实(单停靠、Enter/Space/Escape/Delete/IME/单多选全过,无需修改);插槽数据补齐组合能力(AutocompleteValue selectedItem+items源数据item、ComboBox根 selectedItem,不复制子组件)。范围4子菜单delay对齐固定源契约(默认200ms/自定义600ms/键盘32ms立即/指针离开取消),RTL定位实测向左(LTR向右),顺带移除side/align无效透传;Button/Avatar布局补偿浏览器证明生效后保留。全量111文件1666项、typecheck、build:docs、b02-pickers/api-root-aliases最终tarball(含类型双解析)通过;RTL夹具落tests/fixtures/collections-rtl.vue(playground注册)。
|
||||
|
||||
- HD-10 已验收:复核d152856,集成人补修bf6cf0f8d12fe54a72e5ff524b1b05dbaadcfe86,关闭子菜单delay对点击/禁用的回归并补取消、父关闭清理。全量111文件1672项、类型、最终docs/playground构建、b01-menu-dropdown/b02-pickers/api-root-aliases最终tarball及真实浏览器异步/重试/滚动/RTL/焦点通过,见同一结果表。按用户授权合入main并push origin/main;工作区释放,保留5173/5174,下一项HD-09未启动。
|
||||
|
||||
- DOCS-HEADER-HOVER-PARITY按用户授权集成main:合入4bfc2ef(实现652cf85),未引入分支末尾重复示例提交6049437;集成验证与推送见同一任务结果。
|
||||
|
||||
- HD-09 虚拟布局已实施待复核:分支 task/hd-09-virtualization(起点 dd4f04c,实现 9e8d89e)。ListBox 虚拟行序列(可变行高/heading/loader/gap/padding/滚动父级)、公共 useVirtualRows/bindVirtualRows、autocomplete 弹层整体滚动+sticky 搜索框、dropIndicatorThickness 记录不补;68 项卡内+全量 1683、typecheck、build:docs、virtual-rows/list-box/b02-pickers/api-root-aliases tarball 与真实浏览器几何/键盘/定位验证通过。结果见 docs/tasks/results/HD-09-VIRTUALIZATION.md;5173/5174 保留。
|
||||
|
||||
- HD-09 集成人复核ee37e66,未验收,待HD09-R1;四项布局阻断(估算未实测、Table42/45几何漂移、定位未计表头、父容器空→长绑定失败)见同一结果表。typed key已补修ae27fb28d19f5611d23b5926a961e84e01be0002,定向69项及类型通过;复现夹具保留。工作区交回当前task/hd-09-virtualization继续返修,未合main、未push,保留5173/5174。
|
||||
|
||||
- HD-09 已验收:用户要求继续后由集成人完成R1,主修复5a00e25a25bec484f3f0067545e992fa39ce53d3、动态loader补修6d9e3f31cf0883cce416ce1056f675a65a536ec6;四项阻断与typed key全部关闭,见同一结果文件最终节。全量112文件1688项、类型、最终五组tarball、docs/playground构建及自然测量/宽度变化/定位/sticky/追加过滤/加载行真实浏览器通过。按用户授权合入main并push origin/main;工作区释放,保留5173/5174,下一项未启动。
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<!-- task-metadata
|
||||
{"base":"df954afaced8cea6a49171ebf6594726bb273aa7","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"implemented","requires":["apps/docs/.vitepress/theme/shell.css"],"sources":["apps/docs/src/components/search-dialog.tsx","apps/docs/src/components/fumadocs/ui/search-toggle.tsx"],"checks":["pnpm exec vitest run tests/docs-shell.test.ts"]}
|
||||
-->
|
||||
# DOCS-HEADER-HOVER-PARITY
|
||||
|
||||
用户截图澄清:未选中导航hover文字/图标由muted变foreground,顶部搜索入口文字/图标/快捷键也变foreground;无下划线,当前分区底线不移动。此前将要求理解为颜色不变,现予纠正。仅文档使用处CSS,不更改公共Link/Button/Kbd默认行为或真正SearchField占位符令牌。浅深主题真实hover核对normal/hover,390px字号、选中标记及焦点保留。提交分支,不合main不push;不启动HD-01任务。
|
||||
@@ -1,16 +1,17 @@
|
||||
<!-- task-metadata
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"pending","requires":["docs/tasks/HD-QUEUE.md"],"sources":["packages/styles/src/components/label/label.styles.ts"],"checks":["pnpm typecheck","pnpm typecheck"]}
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"accepted","requires":["docs/tasks/HD-QUEUE.md"],"sources":["packages/styles/src/components/label/label.styles.ts"],"checks":["pnpm typecheck","pnpm exec vitest run tests/shared-field-styles.test.ts","node scripts/check-package.mjs shared-styles"]}
|
||||
-->
|
||||
|
||||
# HD-05-STYLES:styles 导出与全局边框回退
|
||||
|
||||
优先级:P1。证据范围:审计组 02、04、06;总表 2.3/2.4;详见 [清单入口](HD-QUEUE.md) 和其中证据链接。
|
||||
|
||||
## 执行范围
|
||||
|
||||
- [ ] 在现有 styles 入口增量补 labelVariants/descriptionVariants/fieldErrorVariants/textFieldVariants/switchGroupVariants 及必要类型,保留固定源变体和默认值;相关组件复用映射,避免维护两套状态类。
|
||||
- [ ] 补核并恢复上游全局 border-color: var(--border, currentColor) 回退,确认最终 CSS 的层级和覆盖语义;验证独立消费者中的无显式色边框。
|
||||
- [ ] view-transition-name/pointer-events 先核当前站点是否使用该机制;只修实际支持路径中的遮挡,不为未用功能建专项。
|
||||
- [ ] 保留 chip size=md、kbd variant=default 的等效类、reduced-motion、Spinner 定尺、th 行头适配和必要定位补偿。
|
||||
- [x] 在现有 styles 入口增量补 labelVariants/descriptionVariants/fieldErrorVariants/textFieldVariants/switchGroupVariants 及必要类型,保留固定源变体和默认值;相关组件复用映射,避免维护两套状态类。
|
||||
- [x] 补核并恢复上游全局 border-color: var(--border, currentColor) 回退,确认最终 CSS 的层级和覆盖语义;验证独立消费者中的无显式色边框。
|
||||
- [x] view-transition-name/pointer-events 先核当前站点是否使用该机制;只修实际支持路径中的遮挡,不为未用功能建专项。
|
||||
- [x] 保留 chip size=md、kbd variant=default 的等效类、reduced-motion、Spinner 定尺、th 行头适配和必要定位补偿。
|
||||
|
||||
## 用户可见通过条件
|
||||
|
||||
@@ -26,4 +27,3 @@
|
||||
结果写到 `docs/tasks/results/HD-05-STYLES.md`,逐条记录改动或“无需修改”的证据及限制;只在本卡元数据更新状态。核实后无需修改是有效结论,不为凑修复量重写底座。普通实施提交自己的分支,不合 main、不 push、不派发其他会话。
|
||||
|
||||
仅浏览器客户端;不开发或运行 SSR/水合/Nuxt 服务端、逐像素自动对比、完整读屏或真机矩阵专项。
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!-- task-metadata
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"pending","requires":["docs/tasks/HD-QUEUE.md"],"sources":["packages/react/src/components/breadcrumbs/breadcrumbs.tsx"],"checks":["pnpm exec vitest run tests/surface-link-spinner.test.ts tests/date-picker-demos.test.ts tests/date-range-picker-demos.test.ts tests/regressions/navigation-otp/public-contracts.test.ts","pnpm typecheck"]}
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"accepted","requires":["docs/tasks/HD-QUEUE.md"],"sources":["packages/react/src/components/breadcrumbs/breadcrumbs.tsx"],"checks":["pnpm exec vitest run tests/surface-link-spinner.test.ts tests/typography-empty-breadcrumbs.test.ts tests/date-picker-demos.test.ts tests/date-range-picker-demos.test.ts tests/regressions/navigation-otp/public-contracts.test.ts","pnpm typecheck","node scripts/check-package.mjs link-focus api-root-aliases date-picker date-range-picker"]}
|
||||
-->
|
||||
# HD-06-LINK-FOCUS:禁用链接与日期键盘焦点
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
## 执行范围
|
||||
|
||||
- [ ] 修 Link 禁用后仍保留可导航 href 的问题,覆盖 target/download/asChild 与动态禁用;保持事件取消和 attrs/ref 合并。Breadcrumbs 逐项核对,它内部部分路径已使用 span,不能一概判为同一缺陷。
|
||||
- [ ] DatePickerTrigger/DateRangePickerTrigger 使用真实 focus-visible 判定或共享焦点设施;不能 @focus 无条件置 true。
|
||||
- [ ] 补 Breadcrumbs 当前 locale 的默认可访问名称及 Vue action 事件,保留显式 aria-label 优先级和数字0/空key身份。
|
||||
- [x] 修 Link 禁用后仍保留可导航 href 的问题,覆盖 target/download/asChild 与动态禁用;保持事件取消和 attrs/ref 合并。Breadcrumbs 逐项核对,它内部部分路径已使用 span,不能一概判为同一缺陷。
|
||||
- [x] DatePickerTrigger/DateRangePickerTrigger 使用真实 focus-visible 判定或共享焦点设施;不能 @focus 无条件置 true。
|
||||
- [x] 补 Breadcrumbs 当前 locale 的默认可访问名称及 Vue action 事件,保留显式 aria-label 优先级和数字0/空key身份。
|
||||
|
||||
## 用户可见通过条件
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!-- task-metadata
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"pending","requires":["docs/tasks/HD-QUEUE.md"],"sources":["packages/react/src/components/input-otp/input-otp.tsx"],"checks":["pnpm exec vitest run tests/field-foundation.test.ts tests/fieldset-search-field.test.ts tests/input-otp.test.ts tests/regressions/navigation-otp/public-contracts.test.ts","pnpm typecheck"]}
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"accepted","requires":["docs/tasks/HD-QUEUE.md"],"sources":["packages/react/src/components/input-otp/input-otp.tsx"],"checks":["pnpm exec vitest run tests/field-foundation.test.ts tests/fieldset-search-field.test.ts tests/input-otp.test.ts tests/regressions/navigation-otp/public-contracts.test.ts","pnpm typecheck","node scripts/check-package.mjs field-otp m30-m32 shared-styles api-root-aliases"]}
|
||||
-->
|
||||
# HD-07-FIELD-OTP:字段与 OTP 公共能力补齐
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
## 执行范围
|
||||
|
||||
- [ ] 补 TextField 自动聚焦、isFocusWithin/isFocusVisible 与相应 data 状态;支持 TextField/SearchField 字段级 validationErrors 并明确与 Form 错误的合并、清除和优先级;补 SearchField 插槽 value。
|
||||
- [ ] OTP 补 autoFocus、pasteTransformer、textAlign 的等价公共能力;validationDetails/FieldError 的必要校验信息复用现有字段协议,避免另建状态源。
|
||||
- [ ] 对固定 input-otp 依赖核验 pattern 和 complete:满值替换、重复值、清空重填、受控拒绝、粘贴转换后过滤均需行为证据,再修契约。不能仅依据报告把两个不同语义直接替换。
|
||||
- [ ] containerClassName 被上游公共类型 Omit 排除,不补;保留 PinInput、多真实 input、透明覆盖层和字符串/数组转换。密码管理器策略无等价能力时明确记录限制。
|
||||
- [x] 补 TextField 自动聚焦、isFocusWithin/isFocusVisible 与相应 data 状态;支持 TextField/SearchField 字段级 validationErrors 并明确与 Form 错误的合并、清除和优先级;补 SearchField 插槽 value。
|
||||
- [x] OTP 补 autoFocus、pasteTransformer、textAlign 的等价公共能力;validationDetails/FieldError 的必要校验信息复用现有字段协议,避免另建状态源。
|
||||
- [x] 对固定 input-otp 依赖核验 pattern 和 complete:满值替换、重复值、清空重填、受控拒绝、粘贴转换后过滤均需行为证据,再修契约。不能仅依据报告把两个不同语义直接替换。
|
||||
- [x] containerClassName 被上游公共类型 Omit 排除,不补;保留 PinInput、多真实 input、透明覆盖层和字符串/数组转换。密码管理器策略无等价能力时明确记录限制。
|
||||
|
||||
## 用户可见通过条件
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
<!-- task-metadata
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"pending","requires":["docs/tasks/HD-QUEUE.md"],"sources":["packages/react/src/components/table/table.tsx"],"checks":["pnpm exec vitest run tests/table.test.ts tests/regressions/toast-table/sorting-and-actions.test.ts tests/regressions/toast-table/resize-selection.test.ts tests/regressions/toast-table/empty-state-and-labels.test.ts","pnpm typecheck"]}
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"accepted","requires":["docs/tasks/HD-QUEUE.md"],"sources":["packages/react/src/components/table/table.tsx"],"checks":["pnpm exec vitest run tests/table.test.ts tests/regressions/toast-table/sorting-and-actions.test.ts tests/regressions/toast-table/resize-selection.test.ts tests/regressions/toast-table/empty-state-and-labels.test.ts","pnpm typecheck","node scripts/check-package.mjs m35-m36 handbook-styles"]}
|
||||
-->
|
||||
|
||||
# HD-08-TABLE:Table 空状态、排序焦点与列宽
|
||||
|
||||
优先级:P1。证据范围:审计组 02;详见 [清单入口](HD-QUEUE.md) 和其中证据链接。
|
||||
|
||||
## 执行范围
|
||||
|
||||
- [ ] 空状态默认跨实际全部叶子列,显式 colspan 仍优先;覆盖列动态变化、选择列及自定义包装,不能执行未知组件 setup/render 探测。
|
||||
- [ ] 排序交互保留可访问键盘行为并恢复基线焦点环,不能简单删掉 button 或只补一个类名。
|
||||
- [ ] defaultWidth=Nfr 按权重分配剩余宽度,协调固定/百分比/min/max/用户拖动后的宽度;不能继续将 fr 静默转 auto。
|
||||
- [ ] 保留 th scope=row、对应圆角选择器和 resizer z-index 修复;必要时缩小 text-start/font-normal 的适用范围以保留调用方继承。
|
||||
- [x] 空状态默认跨实际全部叶子列,显式 colspan 仍优先;覆盖列动态变化、选择列及自定义包装,不能执行未知组件 setup/render 探测。
|
||||
- [x] 排序交互保留可访问键盘行为并恢复基线焦点环,不能简单删掉 button 或只补一个类名。
|
||||
- [x] defaultWidth=Nfr 按权重分配剩余宽度,协调固定/百分比/min/max/用户拖动后的宽度;不能继续将 fr 静默转 auto。
|
||||
- [x] 保留 th scope=row、对应圆角选择器和 resizer z-index 修复;必要时缩小 text-start/font-normal 的适用范围以保留调用方继承。
|
||||
|
||||
## 用户可见通过条件
|
||||
|
||||
@@ -26,4 +27,3 @@
|
||||
结果写到 `docs/tasks/results/HD-08-TABLE.md`,逐条记录改动或“无需修改”的证据及限制;只在本卡元数据更新状态。核实后无需修改是有效结论,不为凑修复量重写底座。普通实施提交自己的分支,不合 main、不 push、不派发其他会话。
|
||||
|
||||
仅浏览器客户端;不开发或运行 SSR/水合/Nuxt 服务端、逐像素自动对比、完整读屏或真机矩阵专项。
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!-- task-metadata
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"pending","requires":["docs/tasks/HD-QUEUE.md"],"sources":["apps/docs/src/demos/cn/table/virtualization.tsx"],"checks":["pnpm exec vitest run tests/collection-filter-virtual.test.ts tests/table.test.ts tests/collection-state.test.ts","pnpm typecheck"]}
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"accepted","requires":["docs/tasks/HD-QUEUE.md"],"sources":["apps/docs/src/demos/cn/table/virtualization.tsx"],"checks":["pnpm exec vitest run tests/collection-filter-virtual.test.ts tests/table.test.ts tests/collection-state.test.ts","pnpm exec vitest run tests/virtual-rows.test.ts","pnpm typecheck","node scripts/check-package.mjs virtual-rows list-box b02-pickers api-root-aliases m35-m36"]}
|
||||
-->
|
||||
# HD-09-VIRTUALIZATION:Table 与 ListBox 虚拟布局能力
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
## 执行范围
|
||||
|
||||
- [ ] 在现有集合/表格模型上补固定源实际使用的可变行高与估算、分组标题、加载行、gap/padding 能力;公开 Vue API 草案须明确各参数的单位、默认值和更新语义,不要求复制 RAC 类。
|
||||
- [ ] Table 42px 与 ListBox 50px 不统一机械改48:先核固定源示例显式 rowHeight、实际布局默认值和行样式。恢复对应示例的滚动容器、列布局、截断策略及 Autocomplete sticky 搜索框。
|
||||
- [ ] 虚拟分组、动态过滤、异步追加后保持选择、键盘焦点与 aria 索引;不能让窗口外条目丢失逻辑身份。
|
||||
- [ ] dropIndicatorThickness 属于拖放布局契约,先确认支持范围;未支持拖放时记录边界,不补空参数冒充能力。
|
||||
- [x] 在现有集合/表格模型上补固定源实际使用的可变行高与估算、分组标题、加载行、gap/padding 能力;公开 Vue API 草案须明确各参数的单位、默认值和更新语义,不要求复制 RAC 类。
|
||||
- [x] Table 42px 与 ListBox 50px 不统一机械改48:先核固定源示例显式 rowHeight、实际布局默认值和行样式。恢复对应示例的滚动容器、列布局、截断策略及 Autocomplete sticky 搜索框。
|
||||
- [x] 虚拟分组、动态过滤、异步追加后保持选择、键盘焦点与 aria 索引;不能让窗口外条目丢失逻辑身份。
|
||||
- [x] dropIndicatorThickness 属于拖放布局契约,先确认支持范围;未支持拖放时记录边界,不补空参数冒充能力。
|
||||
|
||||
## 用户可见通过条件
|
||||
|
||||
@@ -27,3 +27,17 @@
|
||||
|
||||
仅浏览器客户端;不开发或运行 SSR/水合/Nuxt 服务端、逐像素自动对比、完整读屏或真机矩阵专项。
|
||||
|
||||
|
||||
## HD09-R1:集成人复核返修(2026-10-29)
|
||||
|
||||
复核入口ee37e66;集成人已补修typed key并提供公开复现夹具,提交ae27fb28d19f5611d23b5926a961e84e01be0002。上述执行范围勾选仅保留原实施记录,当前未验收;准确问题与实测数据见同一结果文件末节。继续当前任务分支,不从main重做。
|
||||
|
||||
- [x] R1-01(P1):估算高度须有实际测量/修正路径,处理未知内容和标题高度、宽度变化、缓存失效与滚动锚定。当前undefined→固定回退不能作为已完成的估算能力;128px内容落在56px占位内已重叠。不得仅改称“不支持”核销原任务。
|
||||
- [x] R1-02(P1):统一Table实际行几何与窗口算法;42px模型/45px实测导致渲染行数变化时scrollHeight漂移,不可称为无影响边框差异。核对基线列布局/截断,恢复或用具体布局证据解释;保留原生行头和HD-08成果。
|
||||
- [x] R1-03(P1):scrollToIndex/绑定需要考虑行流在滚动容器中的起点及表头;小于视口的目标行必须完整可见,不能只断言DOM已挂载。夹具定位当前目标底部超出视口36px;同时修正“第150行”按钮的0/1基索引口径。
|
||||
- [x] R1-04(P1):父滚动容器绑定在空→长列表、过滤/追加、布局改变后仍须正确;不要只在root引用变化时查找“当前已溢出”的祖先。现有延后加载场景把10008px列表当视口,200px父容器一次挂载200项。保持sticky搜索与单一焦点模型,覆盖PageUp/Down。
|
||||
- [x] typed key:0与"0"曾均变为item-0,重排触发Duplicate collection key错误;集成人改用既有encodeKey并补状态保持回归。返修不得回退。
|
||||
|
||||
返修后重跑本卡全部范围、相关单测与类型、真实浏览器、最终tarball及必要构建,更新同一结果表。测量/滚动修复后须同时覆盖普通与sticky父容器、长→短→长、异步空→长、估算→实测、容器宽度变化;不以既有整数预设行高夹具代替未知高度验收。不合main、不push,交回复核。
|
||||
|
||||
用户随后授权本会话继续直接修复;R1四项已按下方最终结果节关闭,历史返修说明保留作追溯,最终状态以元数据为准。
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
<!-- task-metadata
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"pending","requires":["docs/tasks/HD-QUEUE.md"],"sources":["apps/docs/src/demos/cn/combo-box/asynchronous-loading.tsx"],"checks":["pnpm exec vitest run tests/autocomplete.test.ts tests/autocomplete-demos.test.ts tests/combo-box.test.ts tests/combo-box-demos.test.ts tests/select.test.ts tests/b01-menu-dropdown.test.ts tests/regressions/collection/picker-public-contracts.test.ts","pnpm typecheck"]}
|
||||
{"base":"db5670f4e1efe0e6ef7433002de5fb0a4a284f84","upstream":"ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960","status":"accepted","requires":["docs/tasks/HD-QUEUE.md"],"sources":["apps/docs/src/demos/cn/combo-box/asynchronous-loading.tsx"],"checks":["pnpm exec vitest run tests/autocomplete.test.ts tests/autocomplete-demos.test.ts tests/combo-box.test.ts tests/combo-box-demos.test.ts tests/select.test.ts tests/b01-menu-dropdown.test.ts tests/regressions/collection/picker-public-contracts.test.ts","pnpm typecheck","node scripts/check-package.mjs b01-menu-dropdown b02-pickers api-root-aliases"]}
|
||||
-->
|
||||
|
||||
# HD-10-COLLECTIONS:异步加载、过滤与触发器语义
|
||||
|
||||
优先级:P1。证据范围:审计组 08;详见 [清单入口](HD-QUEUE.md) 和其中证据链接。
|
||||
|
||||
## 执行范围
|
||||
|
||||
- [ ] ComboBox 异步例补自动增量加载,保留取消旧请求和过期响应保护;明确本地模拟数据与基线 SWAPI 的差异,正常加载路径文案/布局对齐。Select 已有 IntersectionObserver,验证其实际滚动触发而非重复实现。错误重试可保留在异常态,不把重试按钮等同纯手动退化。
|
||||
- [ ] Autocomplete 虚拟化例的 contains 使用 locale 敏感、大小写/变音折叠的等价过滤;与默认过滤共用逻辑。
|
||||
- [ ] 核对 Autocomplete 触发器 role=button/tabindex/Delete/Backspace 的完整键盘与焦点模型,修正不符合等价公开组合的停靠点;selectedItems/selectedItem 用 Vue 插槽数据补齐可组合能力,不执行或复制任意子组件。
|
||||
- [ ] 核对 Dropdown 子菜单固定源实际 delay 和暴露契约,补默认值/配置及 RTL 定位;保留 Button/Avatar 触发器布局补偿,除非浏览器证明其破坏目标效果。
|
||||
- [x] ComboBox 异步例补自动增量加载,保留取消旧请求和过期响应保护;明确本地模拟数据与基线 SWAPI 的差异,正常加载路径文案/布局对齐。Select 已有 IntersectionObserver,验证其实际滚动触发而非重复实现。错误重试可保留在异常态,不把重试按钮等同纯手动退化。
|
||||
- [x] Autocomplete 虚拟化例的 contains 使用 locale 敏感、大小写/变音折叠的等价过滤;与默认过滤共用逻辑。
|
||||
- [x] 核对 Autocomplete 触发器 role=button/tabindex/Delete/Backspace 的完整键盘与焦点模型,修正不符合等价公开组合的停靠点;selectedItems/selectedItem 用 Vue 插槽数据补齐可组合能力,不执行或复制任意子组件。
|
||||
- [x] 核对 Dropdown 子菜单固定源实际 delay 和暴露契约,补默认值/配置及 RTL 定位;保留 Button/Avatar 触发器布局补偿,除非浏览器证明其破坏目标效果。
|
||||
|
||||
## 用户可见通过条件
|
||||
|
||||
@@ -26,4 +27,3 @@
|
||||
结果写到 `docs/tasks/results/HD-10-COLLECTIONS.md`,逐条记录改动或“无需修改”的证据及限制;只在本卡元数据更新状态。核实后无需修改是有效结论,不为凑修复量重写底座。普通实施提交自己的分支,不合 main、不 push、不派发其他会话。
|
||||
|
||||
仅浏览器客户端;不开发或运行 SSR/水合/Nuxt 服务端、逐像素自动对比、完整读屏或真机矩阵专项。
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
| 卡 | 用途 |
|
||||
| ----------------------------------------- | ----------------------------------------------------------- |
|
||||
| [硬差异修复清单](HD-QUEUE.md) | 13张修复/核实任务卡、优先级、审计纠正与验收边界;按用户选择串行执行 |
|
||||
| [DOCS-HEADER-HOVER-PARITY](DOCS-HEADER-HOVER-PARITY.md) | 按用户官方截图纠正导航与搜索入口hover变深 |
|
||||
| [DOCS-NAVIGATION-TEXT-STATE](DOCS-NAVIGATION-TEXT-STATE.md) | 顶部两个分区入口hover文字保持原色/字体 |
|
||||
| [DOCS-CONTROL-STATES](DOCS-CONTROL-STATES.md) | 字段 placeholder 主题与文档控件状态/语义排查 |
|
||||
| [DOCS-NAVIGATION-HOVER](DOCS-NAVIGATION-HOVER.md) | 顶部导航与组件总览悬停样式 |
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# DOCS-HEADER-HOVER-PARITY
|
||||
|
||||
分支task/docs-header-hover-parity;起点df954afaced8cea6a49171ebf6594726bb273aa7;实施652cf854be7b056e6e24606e773ea93f842d22d7。主会话实施/自测,未合main、未push。
|
||||
|
||||
纠正先前对用户意图的误解:用户四张官方截图要求hover变深,之前DOCS-NAVIGATION-TEXT-STATE把“不出现下划线”错误扩展为“文字颜色不变”。新结果覆盖该旧验收目标,旧记录保留追溯。
|
||||
|
||||
仅文档shell.css修改:导航hover/data-hovered改用foreground,图标currentColor跟随;保留无下划线及当前分区底线。顶部搜索Button入口hover也变foreground,内部Kbd设color:inherit使文字/图标/快捷键同步。普通Link/Button/Kbd默认样式不变,实际弹窗SearchField的placeholder主题修复保留。
|
||||
|
||||
真实浏览器5173/components:组件当前选中,快速开始normal为muted .5517,真实hover为foreground .2103,图标同步;hover移开恢复muted;组件aria-current=page及accent底线保持,快速开始底线仍透明,两个链接均无下划线。搜索normal的Button/svg/span/两Kbd均muted .5517,hover五处均foreground .2103。深色重复验证muted .705→foreground .9911,离开恢复;结束恢复跟随系统。390×844悬停两个导航字号仍13px。截图临存/private/tmp/header-nav-hover.png与header-search-hover.png。
|
||||
|
||||
复现:打开/components,移入快速开始,确认字体/图标变为与当前组件同前景色且底线仍仅组件有;移出恢复灰色。移入顶部搜索入口,搜索图标/文字/快捷键同步变深,移出恢复。浅深主题重复。
|
||||
|
||||
pnpm exec vitest run tests/docs-shell.test.ts:13项通过;git diff --check通过。仅文档CSS修改,未重复整库构建/打包。键盘焦点规则未改;未执行SSR/水合/Nuxt或逐像素/完整读屏专项。未启动HD-01,原5173/5174服务保留。
|
||||
|
||||
## main 集成(2026-10-29)
|
||||
|
||||
用户明确授权合main并push。集成前main=aa881d2,origin/main已fetch且与本地一致;合并4bfc2ef(包含实现652cf85),不引入分支后来混入的重复示例提交6049437。唯一冲突ACTIVE保留main所有新任务交接并追加本次记录,其他文件自动合并。全量111文件/1672项、pnpm typecheck、pnpm build:docs均通过,保留既有大chunk提示。未涉及公共包API,未重复产物检查。合并提交含本记录;随后推送origin/main,以远端HEAD核对成功为准。
|
||||
@@ -0,0 +1,83 @@
|
||||
# HD-05-STYLES 结果记录
|
||||
|
||||
- 任务卡:[HD-05-STYLES](../HD-05-STYLES.md);固定上游 `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`heroui/packages/styles/src/components/*/**.styles.ts`、`heroui/packages/styles/base/base.css`、`heroui/packages/styles/index.css`)。
|
||||
- 分支 task/hd-05-styles;起点 35b602e(main tip,含 HD-04 验收与复核补修 f9938ee);实施 dc859fb8aeacac7eb3a798676356cb2c387e5d45(26 文件,styles/vue 包、契约与浏览器夹具、单测、文档与记录源);记录提交为本文件所在提交。主会话实施/自测,未合 main、未 push。
|
||||
- 任务卡 checks 的 `pnpm typecheck` 重复项已清理,替换为 `pnpm typecheck`、`pnpm exec vitest run tests/shared-field-styles.test.ts`、`node scripts/check-package.mjs shared-styles` 三项实际检查(元数据随记录提交)。
|
||||
|
||||
## 范围 1:styles 入口增量补齐五个 tv 映射
|
||||
|
||||
**修改**。`packages/styles/src/index.ts` 增量新增(不改动既有导出):
|
||||
|
||||
| 新导出 | 固定源 | 逐键核对 |
|
||||
| --------------------------------------------- | ------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
||||
| `labelVariants` / `LabelVariants` | `label/label.styles.ts` | base `hv-label`;isDisabled/isInvalid/isRequired(默认全 false)→ `hv-label--disabled/--invalid/--required` |
|
||||
| `descriptionVariants` / `DescriptionVariants` | `description/description.styles.ts` | base-only `hv-description` |
|
||||
| `fieldErrorVariants` / `FieldErrorVariants` | `field-error/field-error.styles.ts` | base-only `hv-field-error` |
|
||||
| `textFieldVariants` / `TextFieldVariants` | `textfield/textfield.styles.ts` | base `hv-textfield`;fullWidth(默认 false)→ `hv-textfield--full-width` |
|
||||
| `switchGroupVariants` / `SwitchGroupVariants` | `switch-group/switch-group.styles.ts` | slots `base`/`items`;orientation(默认 vertical)→ `hv-switch-group--horizontal/--vertical` |
|
||||
|
||||
变体键、默认值、slot 集合与固定源逐键一致(仅 `hv-` 前缀,沿用本库命名约定)。
|
||||
|
||||
**组件复用同一映射(避免两套状态类)**:Label.vue、Description.vue、FieldError.vue、useTextField.ts、SwitchGroup.vue 原先内联写死类名,全部改为消费上述映射(全仓 `hv-label*/hv-description/hv-field-error/hv-textfield*/hv-switch-group*` 字符串仅存于 styles 映射一处)。渲染类输出不变:`tests/shared-field-styles.test.ts` 钉住「映射输出 ↔ 组件实际类输出」逐类相等(Label 双状态、Description、FieldError、SwitchGroup base/items 槽);既有 field-foundation/fieldset-search-field 等类断言未改动并通过。attrs 归属未变(各组件 inheritAttrs 策略与 class 合并路径原样,Description/FieldError/Label 的 `v-bind="attrs"` + `:class` 合并行为不变)。
|
||||
|
||||
**公共类型**:`@heroui-vue/styles` 导出五个 `*Variants` 类型(VariantProps);`@heroui-vue/components` 再导出同一组函数与类型(运行时同函数对象,check-client 断言 `stylesLib[name] === lib[name]`)。
|
||||
|
||||
## 范围 2:全局边框色回退
|
||||
|
||||
**修改**。新增 `packages/styles/base/base.css`(移植 `heroui/packages/styles/base/base.css` 的边框色继承规则,Apache-2.0 来源声明保留),`packages/styles/index.css` 在 `tailwindcss/preflight.css` 之后以 `layer(base)` 导入——与固定源 `@import "./base/base.css" layer(base)` 同层、同相对次序(preflight 的 `border: 0 solid` 先出、回退规则后出,同层平手由次序裁决)。
|
||||
|
||||
层级与覆盖语义:规则在 `base` 层、选择器 `*, ::after, ::before, ::backdrop, ::file-selector-button`(通配选择器为 0-0-0,伪元素为 0-0-1)、无 `!important`;components 层组件规则、utilities 与无层调用方 CSS 均可正常覆盖。
|
||||
|
||||
**独立 tarball 消费者真实浏览器验证**(`shared-styles-consumer-app` 夹具 + Playwright/系统 Chrome,消费者目录为 check-package 打包安装的最终 tarball,无工作区源码/alias;浅深用真实点击 `#theme-toggle` 切换):
|
||||
|
||||
| 场景 | 浅色实值 | 深色实值 | 结论 |
|
||||
| ------------------------------------------------------------------ | --------------------------------------------------- | ---------------------------------------- | ------------------------------------ |
|
||||
| 无显式色边框(`.box`) | `oklch(0.9 0.004 286.32)` = 同元素解析的 `--border` | `oklch(0.28 0.006 286.033)` = `--border` | 默认边框走主题 `--border` 且随主题变 |
|
||||
| 显式 border 颜色(红) | `rgb(200, 0, 0)` | `rgb(200, 0, 0)` | 显式色不受回退影响 |
|
||||
| 组件显式透明边框(`.hv-input-otp__slot` 的 `var(--field-border)`) | `rgba(0, 0, 0, 0)` | `rgba(0, 0, 0, 0)` | 显式声明(含 transparent)不被覆盖 |
|
||||
| 调用方覆盖(普通 CSS、无 `!important`) | `rgb(0, 128, 0)` | `rgb(0, 128, 0)` | 消费者定制生效 |
|
||||
| 调用方**同选择器**注入规则(与库规则完全同选择器) | `rgb(255, 165, 0)` | — | 库规则是低优先级默认,不破坏定制 |
|
||||
| `--border: initial`(缺失回退) | `rgb(0, 0, 255)` = 元素 `color` | 同 | 回退 `currentColor` |
|
||||
|
||||
CSSOM 证据:规则 `*, ::after, ::before, ::backdrop` 值 `var(--border,currentColor)`,`layer=base`、`priority=""`(递归 @layer 遍历取得;截图 hd05-shared-styles-{light,dark}.png 存档)。
|
||||
|
||||
## 范围 3:view-transition-name / pointer-events
|
||||
|
||||
**无需修改**。核查全仓(`packages/`、`apps/docs`、`apps/playground`)与上游 `apps/docs/src`、`packages/react/src`:View Transitions API(`document.startViewTransition`、`view-transition-name`、`::view-transition`)均无使用;唯一提及是 `toast-queue.ts` 注释中的举例文案(两仓相同)。固定源 `base/base.css` 的 `:root { view-transition-name: none }` 与 `::view-transition { pointer-events: none }` 因此不迁移、不建立专项;无「已支持路径中可复现的遮挡」需要修复。若未来引入 View Transitions,应随其能力卡补这两条防御规则。
|
||||
|
||||
## 范围 4:保留的合理适配(未改动)
|
||||
|
||||
git 改动面核对(见提交):chip `size:"md"`、kbd `variant:"default"` 等效默认类、reduced-motion 补强、Spinner `.spinner > svg` 定尺、Table `th` 行头与 resizer `z-index`、dropdown/popover 定位补偿、color-swatch-picker 浅色勾选修正等全部原样;**未**恢复日期弹层的库级 `w-full` 强制视口宽规则(`date-range-picker.css` 零改动)。HD-01~HD-04 成果保留。
|
||||
|
||||
## 检查与验证
|
||||
|
||||
- `node scripts/task-check.mjs HD-05-STYLES`(head 35b602e、最低 base 满足)✅
|
||||
- 卡内 checks(清理重复后):`pnpm typecheck` ✅;`pnpm exec vitest run tests/shared-field-styles.test.ts`(3 项)✅;`node scripts/check-package.mjs shared-styles` ✅
|
||||
- 全量回归 `pnpm exec vitest run`:**111 文件 / 1634 项**(新增 3 项映射↔组件一致性)✅
|
||||
- `pnpm build:docs` ✅(styling.md 与五页 API 文档更新后);prettier ✅
|
||||
- 最终 tarball 验证 `node scripts/check-package.mjs shared-styles api-root-aliases handbook-styles` ✅:
|
||||
- 五个导出从打包产物 `@heroui-vue/components` 与 `@heroui-vue/styles` 均可导入且为同一函数;
|
||||
- `shared-styles-contract.ts` 类型正反例在 nodenext/bundler 两种解析下 strict 通过(含五个 `*Variants` 类型、tv 扩展、`@ts-expect-error` 反例;类型可解析);
|
||||
- 变体输出断言(check-client)覆盖默认/各状态/fullWidth/orientation 组合,与组件实际状态类一致;
|
||||
- CSS 契约含 `border-color:var(--border,currentColor)` 与五个组件类标记。
|
||||
- 独立消费者真实浏览器验证见范围 2 表格(浅/深、默认边框、显式色、覆盖、回退、CSSOM 层级),非 CSS 字符串搜索、非源码 alias。
|
||||
|
||||
## 未完成与限制
|
||||
|
||||
1. `view-transition` 两条上游全局规则未迁移(无使用证据,见范围 3);如后续引入 View Transitions 需随能力卡补。
|
||||
2. 浏览器夹具 `shared-styles-consumer-app` 由 check-package 放入消费者后需按输出命令显式启动 vite(与 b01/b02/color-picker 夹具同一约定);本记录的浏览器证据由该夹具 + Playwright 取得,夹具 README 写明核对清单。
|
||||
3. 无使用 `--border` 之外的全局语义变化;本卡未评估其他上游 base.css 内容(scrollbar 注释块本库已有对应实现)。
|
||||
|
||||
|
||||
## 独立复核与集成验收(2026-10-28)
|
||||
|
||||
- 复核 HEAD `0b303476c2d682a47157f345fcc0a5ab0a23aa8d`,实施 `dc859fb8aeacac7eb3a798676356cb2c387e5d45`,实际基线 `35b602e5b9c67aba97e35b67c7a64ab69d96d4af`。**未发现功能阻断,无需修改实施代码**;仅纠正本记录“所有选择器特异性为0”的表述:通配符0-0-0,伪元素0-0-1,仍为低优先级base默认。
|
||||
- 五个映射的默认值、状态键与slot逐项对固定源;组件的原有字段上下文、attrs/class与事件归属未变。Description/FieldError/Label模板透传路径及useTextField根类复用、SwitchGroup双槽复用均核对。
|
||||
- 独立运行全量 **111文件 / 1634项通过**;`pnpm typecheck`、`pnpm build:docs`通过(仅既有chunk大小提示)。本次未删除、跳过或放宽测试。
|
||||
- 重新运行 `node scripts/check-package.mjs shared-styles api-root-aliases handbook-styles`通过;含最终tarball运行时导出同一性、CSS、五种类型正反例的NodeNext/bundler解析。
|
||||
- 浏览器最终消费者为脚本本轮输出的 `heroui-client-package-sv9jcZ`,入口main.js只从tarball安装包根及发布CSS导入;临时服务5198经lsof确认cwd指向该消费者。5199原由另一消费者占用,未停用、不将其初始读数计入最终证据。
|
||||
- 本轮消费者实测浅/深默认边框:`oklch(0.9 0.004 286.32)` / `oklch(0.28 0.006 286.033)`;两主题显式红色`rgb(200,0,0)`、调用方绿色`rgb(0,128,0)`、缺失token回退蓝色文字`rgb(0,0,255)`均不变,四个OTP槽显式透明边框均保持透明。
|
||||
- 仅在临时消费者样式追加同选择器普通无层规则,默认边框变`rgb(255,165,0)`,显式红色仍保留;CSSOM递归读取确认库规则在base层、值`var(--border,currentColor)`、priority为空。测试后临时追加规则撤回,停止本轮5198服务;保留他人5199与文档5173/playground5174服务。
|
||||
- 全仓再次核对View Transition使用:仅toast-queue注释有`document.startViewTransition`示意,无实际使用路径;本卡不新增相关机制合理。
|
||||
|
||||
结论:**HD-05 accepted**,按用户授权快进合入main并推送origin/main;无本卡未关闭复核项。下一项HD-06-LINK-FOCUS未自动启动。
|
||||
@@ -0,0 +1,39 @@
|
||||
# HD-06-LINK-FOCUS 结果与验收
|
||||
|
||||
- 日期:2026-10-29;本会话亲自实施、验证,用户已授权完成后合并 push。
|
||||
- 分支 `task/hd-06-link-focus`;实际起点 `680a592e7b95bd52592edc19d1b8654b30b53a1c`;实现 **`68d45c66f98eeebd5872448b839ed387bf65f0f0`**。
|
||||
- 固定源 HeroUI `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`。客户端范围,无SSR/水合/Nuxt服务端、逐像素专项。
|
||||
|
||||
## 范围与处理
|
||||
|
||||
| 项 | 核实与处理 | 证据 |
|
||||
| --- | --- | --- |
|
||||
| Link 原生禁用导航 | 原先只取消 click/keydown 且tabindex=-1,仍保留href。禁用时移除href/target/download,保留role=link、aria-disabled、程序化focus;启用后恢复。中键auxclick同样取消。 | 原生与asChild动态禁用回归;真实浏览器左键/中键/Enter后URL和计数不变,右键时节点无导航URL。 |
|
||||
| asChild 子节点属性/ref/事件 | 已安装Reka Slot让子属性优先,还会删除原VNode props.ref,直接给Primitive传空href不足以约束子节点。新增内部LinkPrimitive薄合并:使用Vue mergeProps/cloneVNode保留子ref与启用态处理器;禁用导航属性和tabindex优先于子节点。子捕获监听器早于原Link根门禁,故在合并层增加禁用捕获门禁;普通非激活键仍放行。 | 子原生a(带独立href/target/download/tabIndex)、转发attrs的自定义组件均覆盖;禁用子click捕获不运行,启用恢复一次;父处理器preventDefault保持取消语义,父/子click各一次,原生和组件ref保持。未执行未知组件setup探测。 |
|
||||
| Breadcrumbs 既有禁用路径 | 当前项、禁用项以及无href项原已用span;保留该结构,不把所有Breadcrumbs判为同一href缺陷。 | 既有重排、当前项变中间项、href动态出现、Fieldset禁用回归全部保留通过。 |
|
||||
| Breadcrumbs locale | 新增按ConfigProvider locale动态取得默认名称;显式非空aria-label优先,空值回退本地化。34种标签数据取自固定上游锁定的react-aria 3.52.1,非滚动main文档;en-US Breadcrumbs、zh-CN 导航栏、fr-FR Chemin de navigation。语言/脚本匹配,未收录回退英文。 | 动态en-US→zh-CN→fr-FR、显式名称优先与空值回退测试;浏览器中文“导航栏”切英文“Breadcrumbs”。只移植数据,不引入React运行时。Adobe Apache-2.0许可记录并随组件包发布LICENSE.react-aria。 |
|
||||
| Breadcrumbs action | 新增根@action(key),非当前、未禁用的激活通知一次;id优先于Vue key,无二者则位置索引。数字0、字符串0、空串分别保留。id同时转为li DOM id,文档说明需唯一。用户取消click或stopImmediatePropagation时不通知action;不替代浏览器href导航。 | 点击数字0、Enter激活空串、id字符串0优先于不同Vue key;取消、禁用、当前项不通知。itemKey为内部注入,BreadcrumbsItemProps排除;tarball类型正反例覆盖。 |
|
||||
| 日期触发器focus-visible | 两Trigger的@focus原无条件true;现使用实际currentTarget.matches(':focus-visible'),blur清除,沿用浏览器模态与焦点恢复。 | 两类单测分别模拟匹配false/true/blur;真实鼠标打开时data标记缺省且matches=false,Tab进入时为true,Esc恢复焦点后标记与实际matches=true一致。 |
|
||||
|
||||
## 验证
|
||||
|
||||
- `node scripts/task-check.mjs HD-06-LINK-FOCUS` 前置通过,启动时HEAD680a592;卡内补足Breadcrumbs实际测试与产物契约。
|
||||
- 最终全量 `pnpm exec vitest run`:**111文件 / 1641项通过**(新增7项:Link3、Breadcrumbs2、日期focus2);`pnpm typecheck`通过。旧Link“禁用仍保留href”的断言按本次修复契约改为无href,并补属性恢复/中键/子捕获/取消/ref断言,无删除或skip。
|
||||
- `pnpm build:docs`通过;最终捕获门禁补齐后用最新库dist再运行`pnpm --filter @heroui-vue/docs build`通过;`pnpm --filter @heroui-vue/playground build`通过。仅文档构建既有chunk大小警告。
|
||||
- 最终 `node scripts/check-package.mjs link-focus api-root-aliases date-picker date-range-picker` 通过;ESM/CSS、NodeNext/bundler类型正反例均通过。新action与id类型可解析,内部itemKey类型不公开。解包核实组件包包含LICENSE.react-aria。
|
||||
- 修改代码Prettier与`git diff --check`通过。
|
||||
|
||||
## 真实浏览器场景(5174/?link-focus)
|
||||
|
||||
可复用夹具 `tests/fixtures/link-focus.vue`,与文档相同的公开组件和基础演示,无浏览器事件补发或源码注入:
|
||||
|
||||
1. 初始勾选禁用:两根a的href/target/download均null、tabindex=-1;实际左键、中键后计数0/0、URL不变。点击“聚焦原生链接”调用公开focus,再发送真实Return,焦点仍native-link、计数0/0、URL不变。右键节点无链接URL,不提供该组件自身导航。
|
||||
2. 取消禁用:原生恢复#link-destination/_blank/example.txt;asChild恢复#child-destination/_blank/child.txt。Breadcrumbs点击“数字零”、Enter激活“空标识”后输出精确`[0,""]`。语言选择器zh-CN→en-US后默认列表名“导航栏”→“Breadcrumbs”。
|
||||
3. 单日期和范围日期触发器:鼠标点击均可打开可见日历,触发器matches=false且无data-focus-visible;Esc自然关闭、焦点回到触发器,与浏览器matches同步;分别从最后日期分段发送真实Tab,焦点落触发器且标记true。
|
||||
|
||||
## 边界与交接
|
||||
|
||||
- asChild遵循既有契约:一个元素/转发attrs的组件根;未知路由组件须透传合并后的导航属性,不能自行覆盖禁用态属性。组件自编的非DOM跳转逻辑不作为Link自身导航能力承诺;不新增整套路由依赖。
|
||||
- 明确区分实现与Vue方式:保留ol/span结构、Vue action与key/id模型;不引入React collection对象或React包装。
|
||||
- 无本卡未完成项。按用户授权 **accepted,合入main并push origin/main**。文档5173保留;5174启动前无监听,本轮重启并保留便于继续验证。
|
||||
- 下一任务HD-07-FIELD-OTP未自动实施。
|
||||
@@ -0,0 +1,48 @@
|
||||
# HD-07-FIELD-OTP 结果与验收
|
||||
|
||||
- 日期:2026-10-29;本会话亲自实施与验收,用户已授权完成后合并 push。
|
||||
- 分支 `task/hd-07-field-otp`,实际起点 `27cc62e36f16bc16843ccf25f202340eeac38871`;实现 **`2d7e3d4e1e12403bb90e92e393bc7fb798a5a2ba`**。
|
||||
- 固定 HeroUI `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`;依赖语义核对锁定的 input-otp **1.5.0** npm 源码映射中的原始 input.tsx,不使用滚动版本。不安装或运行 React,不新增依赖。
|
||||
|
||||
## 范围核销
|
||||
|
||||
| 项 | 处理与证据 |
|
||||
| --- | --- |
|
||||
| TextField 自动聚焦与焦点 | 共享 useTextField 挂载后聚焦真实 input/textarea,禁用不聚焦;根输出 data-focus-within/data-focus-visible,槽暴露同源状态。组内焦点移动保留 within,离开根清除;visible 使用实际 :focus-visible。SearchField 改用同一焦点状态,保留组/清空按钮协议。 |
|
||||
| 字段错误数组 | TextField/SearchField 支持 string 或 string[],本地错误在前、Form 同名服务端错误在后、重复消息去重;validate/原生消息沿用原有 touched/validationBehavior 规则。改变值的编辑提案或 reset 忽略当前字段/Form 响应,新的数组/对象重新显示;不原地修改调用方错误。 |
|
||||
| 字段校验详情 | FieldContext 增量可选 validationDetails,FieldError 槽读取同一协议。TextField/SearchField 快照真实控件的11个 ValidityState 标志;value 与动态 type/minLength/maxLength/pattern/required 改变后更新。默认槽新增公开 TextFieldRenderProps/SearchFieldRenderProps,SearchField value 来自同一字段值。 |
|
||||
| OTP 四项公共能力 | autoFocus 聚焦首个真实槽输入;pasteTransformer 先转换文本再限长、校验;textAlign 默认 left 并作用于实际透明 input;validationDetails 显式值优先,否则读取已有原生提交代理,通过共享 FieldError 槽暴露,不另建字段内核。 |
|
||||
| pattern | 固定1.5.0对整个候选字符串做 RegExp.test,空串可清空。原来逐字符筛选改为非法整次编辑拒绝;capture 边界在 PinInput 改值/前进焦点前恢复当前字符。保留现有全局/粘滞正则的无 lastIndex 副作用处理。带分隔符文本由显式 transformer 转换,不隐式挑出合法字符。 |
|
||||
| complete | 固定1.5.0仅在已接受值改变且旧长度不足、新长度等于 maxLength 时触发;不在初始满值挂载、满值替换、同值回写或受控拒绝提案时触发。删除/清空后重新填满再次通知,父级主动接受的新值遵循同一规则。 |
|
||||
| 底座与提交 | 保留 PinInput 多真实 input、索引空位、一次字符串 FormData、受控拒绝恢复/可重试、reset 与取消 reset;完整代码粘贴从首格替换,短粘贴从当前格替换,成功后聚焦末格或下一格并选择字符。禁用/只读不转换或修改,消费方 preventDefault 取消粘贴。 |
|
||||
| 无需增加 | containerClassName 在固定 HeroUI 公共类型中被 Omit 排除,不补;不换单 input 底座,不加入密码管理器策略。可感知边界见下节与组件文档。 |
|
||||
|
||||
同步更新 TextField、SearchField、InputOTP、FieldError 文档、compatibility 与移植来源。修复库自有 InputGroup/SearchFieldGroup 原始默认槽返回单 VNode 时 prepare 假定数组的既有缺陷;不执行未知组件 setup/render 探测。
|
||||
|
||||
## 验证
|
||||
|
||||
- `node scripts/task-check.mjs HD-07-FIELD-OTP` 通过;卡内补入最终 tarball 检查。
|
||||
- 最终全量 `pnpm exec vitest run`:**111文件 / 1654项通过**;`pnpm typecheck`通过。相对前置增加13项(字段4、SearchField1、OTP8)。保留原有索引删除、一次提交、表单重置、取消事件等断言,无删除/skip。
|
||||
- 新字段用例验证本地/Form顺序、编辑/reset/新响应、真实自动聚焦、组内焦点、原生 required 与动态 pattern 的 validity 快照。OTP 用例验证转换/整值拒绝/取消/只读禁用、textAlign、受控拒绝与接受、重复/已满替换/清空重填 complete、显式与原生 validity。
|
||||
- 最终 `node scripts/check-package.mjs field-otp m30-m32 shared-styles api-root-aliases` 通过:独立最终 tarball 的 ESM/CSS 与 bundler/NodeNext 类型正反例全部通过;新 props/具名槽类型可消费,错误对象、非法对齐、非字符串转换器、不完整 ValidityState 被拒绝。
|
||||
- `pnpm build:docs`、`pnpm --filter @heroui-vue/playground build`通过;动态约束补修后,使用最终产物再次构建 docs 与 playground通过。文档仅既有 chunk 大小提示。
|
||||
- 修改代码 Prettier 与 `git diff --check`通过。
|
||||
- 一次与库/文档构建并发运行的全量中 choice-demos 单例超过默认5秒;停止构建并串行重跑后全部通过。未放宽超时或更改该测试,将其记录为本次运行竞争现象,不据此宣布既有组件缺陷。
|
||||
|
||||
## 真实浏览器(5174/?field-otp)
|
||||
|
||||
复用夹具 `tests/fixtures/field-otp.vue`,实际原生键盘、剪贴板和控件操作;不通过脚本补发浏览器事件。
|
||||
|
||||
1. 挂载 TextField 后焦点在实际 input,槽内 within/visible 均 true;点击内部按钮 within 保持 true、鼠标 visible=false。输入 Alice 后本地/Form错误消失,新响应按“新字段错误|新Form错误”显示,reset 清值并清除当前响应;SearchField 输入 query 后槽 value 同步。
|
||||
2. 点击挂载 OTP 自动聚焦首格;空值提交显示原生“请填写此字段。”,FieldError valueMissing=true。真实粘贴 `12-34` 得到接受值1234、一次complete、焦点末格且选区[0,1],原生错误消除。设置right后4个真实输入的computed textAlign均right。
|
||||
3. 已满时粘贴 `56-78` 替换为5678,complete不增加。关闭父级接受后粘贴 `90-12` 记录提案9012,实际值恢复5678且不complete。只读时粘贴不生成提案;受控reset保留父值5678。
|
||||
4. 末格 BackSpace 得到567,按9填满5679再次complete;按非法a保持5679且焦点不前进。清空后粘贴 `12-34` 再次complete,结果顺序为1234、5679、1234。
|
||||
5. 5173的InputOTP正式文档确认新增4属性、整值pattern、accepted complete与差异说明实际渲染,原中文全部演示保留。
|
||||
|
||||
## 边界与交接
|
||||
|
||||
- 多 input 结构保留,不承诺单 input 的任意跨格选区或 pushPasswordManagerStrategy 徽标避让;视觉 slot 字符按移植CSS居中,textAlign用于真实透明输入。短信/密码管理器自动填充、真机IME/触屏、完整读屏未在本轮验收。
|
||||
- 原生代理 required 保持底座“非空”规则,不额外发明必须满长才满足 required;完整长度业务规则仍由应用校验。显式 validationDetails 不自动改变 isInvalid。
|
||||
- OTP显式 validationErrors 由调用方管理;Form 当前错误响应在有效编辑提案/reset时忽略。受控值的拒绝恢复与错误响应忽略是两个独立的既有协议,文档已说明。
|
||||
- 仅浏览器客户端,未执行SSR/水合/Nuxt服务端或逐像素专项。
|
||||
- 无本卡未完成项。按用户授权 accepted,合入main并push origin/main;保留5173/5174。下一项HD-08未自动启动。
|
||||
@@ -0,0 +1,104 @@
|
||||
# HD-08-TABLE 结果记录
|
||||
|
||||
- 任务卡:[HD-08-TABLE](../HD-08-TABLE.md);固定上游 `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`heroui/packages/react/src/components/table/table.tsx` 及其 react-aria/react-stately 依赖)。
|
||||
- 分支 task/hd-08-table;起点 aac93db65812a273c887709af4bf1a846439d8bb(main tip,含 HD-07 验收);实施 658dfbb7d920255e48e1b9cf99e15e34f11ec640(14 文件,table 组件/宽度模块/样式/契约、fixture、测试、文档与记录源);记录提交为本文件所在提交。主会话实施/自测,未合 main、未 push。
|
||||
- 本卡不实现 HD-09 的 Table/ListBox 虚拟化,未另建 Table 状态内核(宽度解析为独立纯函数模块,无新状态源)。
|
||||
|
||||
## 范围 1:空状态跨全部实际叶子列
|
||||
|
||||
**修改**。TableBody 空状态 `colspan` 默认由固定 `1` 改为**实际叶子列数**(`ctx.columns` 自注册计数,DOM 序无关),显式 `colspan` 仍优先。覆盖:
|
||||
|
||||
| 场景 | 证据 |
|
||||
| ------------------------------------------------- | ------------------------------------------------------------------------------------ |
|
||||
| 静态 3 列(含选择列、包装组件渲染的 TableColumn) | 单测:默认 colspan=3(自注册计数包含 TableColumnWrapper 子组件渲染的列与选择列) |
|
||||
| 列动态增减 | 单测:增 1 列→4,移除→3(columns map 为响应式注册表,重渲染同步) |
|
||||
| 显式 colspan 优先 | 单测:`:colspan="1"` → "1"(既有 visual-contracts 的显式 `colspan: 1` 钉点原样通过) |
|
||||
| 0→多行→0 | 既有 empty-state-and-labels 8 项(含包装集合回归/强制空态)全通过 |
|
||||
| 未知组件 | 保持 vnode 级 `slotLooksPopulated` 判定,**未**执行未知组件 setup/render 探测 |
|
||||
| 文档示例实测 | table-empty-state 演示空单元 colspan="4" = 表头 4 列(真实浏览器) |
|
||||
|
||||
未测量/无列环境回退 1,不写 `colspan="0"`。
|
||||
|
||||
## 范围 2:排序单次激活与基线焦点环
|
||||
|
||||
**现状核实**(真实浏览器实测先行):点击/Enter/Space 触发按钮的排序激活**本就各一次**(MutationObserver 计 aria-sort 变化:1/1/1);缺口是焦点环——焦点在内嵌 button(UA 默认环),`th` 的基线 inset 环规则(`.hv-table__column:focus-visible`)永不命中。
|
||||
|
||||
**修改**(非删 button、非补类名):保留触发按钮作为键盘/焦点适配层与既有 API(columnKey/isDisabled/合并 onClick),把**真实 `:focus-visible` 判定**(与 HD-06 相同的 `matches(':focus-visible')` 模式)转发到 `th` 的既有 `[data-focus-visible]` 钩子,基线 inset 环(`box-shadow: inset 0 0 0 2px var(--focus)`)随之生效;按钮的 UA 轮廓仅在列内抑制(`.hv-table__column .hv-table__sortable-column-trigger`),列外使用保留默认环。激活路径零改动:
|
||||
|
||||
- 单测:两次点击 = 两次 sortChange(button→冒泡→列单一排序路径);焦点转发 set/remove `[data-focus-visible]`。
|
||||
- 真实浏览器(tests/fixtures/table-layout):click/Enter/Space 各 1 次激活;真实 Tab 键聚焦触发按钮时 `th[data-focus-visible="true"]` + `oklch(0.6204 0.195 253.83) 0 0 0 2px inset` 环、按钮 outline none——**浅色与深色主题逐一实测**(`--focus` 为两主题共享 accent,值一致属预期)。
|
||||
|
||||
**无需修改(核实项)**:可排序未排序列输出 `aria-sort="none"`——基线 react-aria `useTableColumnHeader` 同样输出 `isSorted ? sortDirection : 'none'`(其源码实证;审计"上游只在排序时输出"有误),维持现状。
|
||||
|
||||
## 范围 3:defaultWidth="Nfr" 权重分配
|
||||
|
||||
**修改**。`packages/vue/src/components/table/widths.ts` 移植 react-stately `TableUtils.js` 的 `calculateColumnSizes`(flexbox §9.7 grow-only 解析 + min/max 违规冻结 + 级联取整,Apache-2.0 来源记录)并接线:
|
||||
|
||||
- px/`N%` 固定列先扣(百分比按表宽解析),`Nfr` 按权重分享剩余宽度;未设宽度的列**仅在存在 fr 列时**按 `1fr` 参与(基线 TableColumnLayout 默认语义),无 fr 的表布局零改动。
|
||||
- min/max 对份额生效:违规列冻结、余量再分配直至收敛;整数级联取整保持分配总和;可行约束且有可分配余量时列宽和=表宽,约束总和本身超出/不足表宽时不作无条件等宽承诺。
|
||||
- 存在 fr 列时表启用 `table-layout: fixed`(与基线 ResizableTableContainer 内的 `tableLayout: 'fixed'` 一致)实现精确几何。
|
||||
- 容器缩放(ResizeObserver)重分配;拖动列经既有 setWidth 冻结为像素宽度、fr 列重分享(对齐基线 changedColumns 冻结语义);RTL 几何一致、拖动方向反向(既有 resizer direction 逻辑)。
|
||||
- 未测量环境(jsdom/隐藏)不写宽度——既有 `defaultWidth 1fr does not write an invalid CSS width` 钉点(style.width="")原样通过。
|
||||
|
||||
**真实浏览器几何**(tests/fixtures/table-layout,容器 900/620/1400,Playwright 真实交互):
|
||||
|
||||
| 场景 | 实测 | 约束核对 |
|
||||
| -------------------- | --------------------- | ------------------------------------------------------------------------ |
|
||||
| 900 初始(表宽 892) | 178 / 356 / 180 / 178 | 1fr:2fr=178:356 恰 1:2 ✓;固定列 180 ✓;20% 列=178(892×20%)✓;和=892 ✓ |
|
||||
| 1400(表宽 1392) | 324 / 648 / 180 / 240 | 1:2 ✓;**max 钳制**:20%=278→240 ✓;和=1392 ✓ |
|
||||
| 620(表宽 612) | 120 / 190 / 180 / 122 | **min 钳制**:1fr 均分 103→120 冻结、余量归 2fr ✓;和=612 ✓ |
|
||||
| 拖动 +60px(LTR) | 238 / 296 / 180 / 178 | 拖动列=178+60=238 冻结 ✓;fr 重分享 296 ✓ |
|
||||
| 拖动后缩放至 1400 | 238 / 734 / 180 / 240 | 拖动列保持 238 ✓;fr 重分享 734 ✓ |
|
||||
| RTL | 238 / 734 / 180 / 240 | 几何不变 ✓ |
|
||||
| RTL 拖动 +40px 右 | 198 / 774 / 180 / 240 | 方向反转(238−40=198)✓ |
|
||||
|
||||
`table-layout: fixed` 各场景实测生效;无页面错误。
|
||||
|
||||
## 范围 4:保留项与 text-start/font-normal 核实
|
||||
|
||||
**保留(git diff 核对零改动)**:原生 `th scope="row"`(TableCell)、`:is(td, th.hv-table__cell)` 圆角选择器、`.table__column-resizer` 的 `z-index: 1` 命中区修复、HD-01~HD-07 成果。
|
||||
|
||||
**核实→缩小作用域**:`.table__cell` 的 `@apply text-start font-normal` 实测**确实阻断调用方继承**(祖先 `font-bold text-center` 下 td/th 行头仍 400/start,基线 td 行头应继承 600/center)。收窄为 `th.hv-table__cell { text-align: inherit; font-weight: inherit }`:
|
||||
|
||||
- 行头 th 中和 UA 加粗/居中(基线 td 排版)且完整跟随调用方级联;普通 td 恢复继承(实测 600/center 与基线语义一致)。
|
||||
- 默认无祖先样式时渲染(normal/start)与收窄前一致。
|
||||
|
||||
## 检查与验证
|
||||
|
||||
- `node scripts/task-check.mjs HD-08-TABLE`(head aac93db)✅
|
||||
- 卡内 checks:`vitest run tests/table.test.ts tests/regressions/toast-table/{sorting-and-actions,resize-selection,empty-state-and-labels}.test.ts`(24 项)✅、`pnpm typecheck` ✅
|
||||
- 全量 `pnpm exec vitest run`:**111 文件 / 1657 项**(新增 3:空态跨列、fr 分发与钳制、单次激活+焦点转发)✅;既有断言零修改零跳过
|
||||
- `pnpm build:docs` ✅;prettier ✅
|
||||
- 最终 tarball:`node scripts/check-package.mjs m35-m36 handbook-styles` ✅(m35-m36 契约增量补 `th.hv-table__cell`、`.hv-table__sortable-column-trigger` 两个 CSS 标记,锁定收窄后的规则进入最终产物)
|
||||
- 真实浏览器(playwright-core + 系统 Chrome):tests/fixtures/table-layout(playground 5174 注册)几何/钳制/拖动/RTL/主题表,文档站 5173 的 table-column-resizing(160/220/120/200=700 与基线算法逐毫一致)、table-empty-state(colspan=4)、table-sorting 焦点环;截图 hd08-table-layout-dark.png 存档
|
||||
|
||||
## 未完成与限制
|
||||
|
||||
1. 虚拟化(TableLayout/ListLayout 能力面)明确归 HD-09;本卡未触碰 table-virtualization 的固定行高窗口实现。
|
||||
2. 未测量环境(jsdom)下 fr 列不写宽度(保持原生),fr 分发语义由纯函数单测与真实浏览器几何覆盖;这是刻意设计(避免首帧 0 宽写入)。
|
||||
3. 混合 auto(未设宽度)+ fr 的表在 fr 模式下未设宽度列按 `1fr` 参与分配(基线 TableColumnLayout 语义);这是口径变化点,已在 table.md 注明。
|
||||
4. 拖动时仅拖动列冻结(基线另有"左侧列冻结为先前像素"的连续拖动细节),fr 列实时重分享;几何约束满足但拖动过程中的中间分布与基线可能不同,未见可见回归。
|
||||
5. 排序焦点环转发基于 `:focus-visible` 真实判定;Firefox 对 `:focus-visible` 的启发式与 Chromium 略有差异,本轮以系统 Chrome 验证,未做多引擎矩阵。
|
||||
|
||||
|
||||
## 集成人复核与补修(2026-10-29)
|
||||
|
||||
复核入口 `86d76a0675b2afc94284c4d6a1e0eea17bfd440f`。用户授权少量问题直接补修后合并push;补修 **`c019768e6ac45410cd0f403a325ee0de9727e4eb`**,原实施658dfbb保留。
|
||||
|
||||
| 问题 | 复现与处理 | 最终证据 |
|
||||
| --- | --- | --- |
|
||||
| 固定宽度与maxWidth冲突 | 原宽度解析扣除钳制后的100,但实际固定列仍写width/min-width180;900容器中列宽205/409/180/98,挤压了20%列。统一将全部列(含固定/百分比)解析结果写入DOM,受管布局不再把原始width作为额外min-width。 | 同场景修复后205/409/100/178,总892;测试增量覆盖固定列max钳制与实际style。 |
|
||||
| 无效fr不能收敛 | oopsfr/NaNfr/Infinityfr/1e999fr产生非有限因子,违规冻结循环无法收敛。仅有限数值因子进入算法,其他按1fr回退,沿用格式错误回退的已有方向。 | 新单测四种非法因子均返回有限份额300/600;浏览器切“无效fr回退”仍可操作,178/356/180/178。 |
|
||||
| 补修引出的缩小约束 | 全部列写像素后,已分配列宽可能撑住table,单看table矩形不能检测父容器缩小。增加父内容宽约束与ResizeObserver,保留显式table min-width的主动横向溢出。 | 浏览器1400→620后1392宽324/648/180/240回到612宽120/190/180/122;测试覆盖父容器小于旧table宽时的重新分配。 |
|
||||
| 测试和许可记录 | 修正focus测试在spy安装后才取originalMatches的递归风险;新用例卸载wrapper,保留全部原断言。补保留Adobe Copyright2022声明,组件包已有LICENSE.react-aria继续随产物发布;清除TableColumn过期“未实现fr”注释。 | Prettier、diff检查与全量回归通过。 |
|
||||
|
||||
### 独立复核验证
|
||||
|
||||
- 最终全量 **111文件 / 1658项通过**(原实施1657 + 新非法因子回归1;原宽度用例增量覆盖固定列/父容器边界);`pnpm typecheck`通过,扩展fixture后再次类型检查通过。
|
||||
- 最终 `node scripts/check-package.mjs m35-m36 handbook-styles`通过:tarball ESM/CSS、bundler/NodeNext类型正反例;随后最终dist的docs与playground生产构建通过,仅既有文档chunk提示。代码Prettier与git diff --check通过。
|
||||
- 真实浏览器使用5174 `?table-layout`公开夹具,无源码注入或合成事件。常规900/1400/620依次为178/356/180/178、324/648/180/240、120/190/180/122;固定列max100、无效fr场景见上表。
|
||||
- 620容器真实指针拖首手柄向右40:120/190→160/150;切RTL后向右20:160/150→140/170,后两列180/122保持。
|
||||
- 点击姓名后ascending,真实Tab/Shift+Tab后Enter变descending,Space再变ascending;浅/深均命中th[data-focus-visible=true],实际box-shadow为2px inset focus环。
|
||||
- 浏览器无数据时colspan4,增加列变5,显示3行时空态消失,再清空并移除列回colspan4;未知包装与选择列仍由原自注册单测覆盖。
|
||||
|
||||
原范围均已核销。状态 **accepted**,按用户授权合入main并push origin/main;保留5173/5174。虚拟化仍归HD-09,原记录的拖动时左侧列冻结分布差异保留为明确边界,不伪称完全复刻React布局状态。未开展SSR/水合/Nuxt服务端或逐像素专项;未自动开始下一张卡。
|
||||
@@ -0,0 +1,154 @@
|
||||
# HD-09-VIRTUALIZATION 结果:Table 与 ListBox 虚拟布局能力
|
||||
|
||||
- 起点:`dd4f04c20019315bc5a7208a229c81a108b1d4ed`(main,含 HD-08、HD-10、Header hover 修复)
|
||||
- 实现:`9e8d89e`(分支 `task/hd-09-virtualization`)
|
||||
- 固定源:`ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(只读对照 `/Users/maoyingjie/Documents/OpenSourceProjects/heroui/heroui`)
|
||||
- 范围:单目录串行;不含 SSR/水合/Nuxt、逐像素与完整读屏矩阵专项。
|
||||
|
||||
## 契约核对(补能力前)
|
||||
|
||||
固定源布局契约(table.mdx `TableLayout` 与 list-box.mdx `ListLayout` 参数表相同):`rowHeight` 48、`estimatedRowHeight` 无默认、`headingHeight` 48、`estimatedHeadingHeight` 无默认、`loaderHeight` 48、`dropIndicatorThickness` 2、`gap` 0、`padding` 0。显式传值仅出现在三个上游虚拟化示例:table/virtualization.tsx `rowHeight/headingHeight: 42`、list-box/virtualization.tsx 与 autocomplete/virtualization.tsx `rowHeight: 50`——均为示例值而非布局默认,本卡未机械统一(示例保持原值)。上游样式(autocomplete.styles.ts / popover.styles.ts)无 max-h/overflow 限制:弹层整体滚动 + sticky 搜索框是固定源模型(autocomplete-virtualization.tsx 的 `SearchField className="sticky top-0 z-10"`)。
|
||||
|
||||
## 执行范围逐项核销
|
||||
|
||||
### 1. 可变行高、估算高度、分组标题、加载行、gap/padding(已补)
|
||||
|
||||
- **ListBox**(`packages/vue/src/components/list-box/ListBox.vue`、`context.ts`):虚拟行序列扩展为 padding 占位行、数据驱动分组标题行(`ListBoxDataItem.heading`,按 `headingHeight` 计高,不参与选择与 `aria-posinset`)、条目行、`#loader` 插槽加载行。`rowHeight` 扩展为 `number | ((index) => number | undefined)`(函数返回 `undefined` 回退 `estimatedRowHeight`,最终回退 50);`gap` 仅在内容行(条目/标题/加载行)之间,计入较早一行的行占位;`padding` 为两端占位、不计 gap。每次布局重读全部高度输入(响应式更新无需重挂载)。行序列内核仍是 VueUse `useVirtualList`(函数式 itemHeight 原生支持可变行高),未新增同义状态内核。
|
||||
- **Table**(新增 `packages/vue/src/components/collection/virtual-rows.ts`):公共 `useVirtualRows` / `bindVirtualRows` 纯几何(前缀和 + 二分,无状态内核):可变行高、`estimatedRowHeight` 回退、`gap`(计入 `rowExtentOf`)、`padding`(计入 `padTop`/`padBottom`)、`loaderHeight` 行流末尾预留(在末行 gap 之后、尾 padding 之前,计入 `totalHeight` 与 `window.padBottom`,保证 padTop + 已渲染行 + padBottom ≡ totalHeight 无空洞);`scrollToIndex` 按行偏移滚动并夹在行流内;`bindVirtualRows` 绑定滚动与容器缩放。公共导出含类型(`UseVirtualRowsOptions`/`UseVirtualRows`/`VirtualRowHeight`/`VirtualRowWindow`)。
|
||||
- **Vue API 单位/默认/更新语义**:见 apps/docs/components/list-box.md「ListLayout 映射」表与 table.md「TableLayout 与 Vue 虚拟滚动」表(px 单位、默认值 rowHeight 50(数据模式)/headingHeight 48/loaderHeight 48/gap 0/padding 0、函数式行高语义、逐布局重读)。
|
||||
|
||||
### 2. 示例显式值、滚动容器、列布局、截断与 sticky(已恢复/保留)
|
||||
|
||||
- **table-virtualization**:保持 42px 显式行高(上游 layoutOptions 值)、`minWidth` 列布局(160/220/240)、单元格 `whitespace-nowrap overflow-hidden text-ellipsis` 截断、`h-[300px] min-w-[700px]` 表格与外层 `data-slot="table-virtual-viewport"` 滚动 div(`h-[300px] w-full overflow-auto`)。**裁决依据(浏览器实证)**:原生 `<table>` 不能当滚动容器——给 table 元素 `h-[300px]` 后 computed height 被内容撑到 45036px、`overflow-y: visible`(height 是最小高度且 overflow 需要确定高度);固定源滚动的是 `Table.Content` 虚拟网格(非 table 元素),结构差异决定外层滚动 div 是如实适配而非简化。表格行 inline 高 45 vs 42 为 border 排版(42 + 边框折叠),非布局偏差。
|
||||
- **list-box-virtualization**:核对后与上游一致(50px 双行、`h-[400px] w-[300px] overflow-y-auto`),**无需修改**(diff 空)。
|
||||
- **autocomplete-virtualization**:恢复弹层整体滚动 + sticky 搜索框。`autocomplete.css` 历史规则 `[data-slot="list-box"] { max-h-[320px] overflow-y-auto }`(列表自滚)限定 `:not([data-virtualized])` 保留(非虚拟化行为不变);虚拟化时 ListBox 输出 `data-virtualized` 钩子,filter 容器 `max-h-[min(400px,70vh)] overflow-y-auto` 承担弹层整体滚动,SearchField `sticky top-0 z-10` 钉在顶部。`max-h` 是上游可用空间钳制的近似替代(上游样式无 max-h 限制),差异如实记录。
|
||||
- 虚拟行高由组件布局参数承担,不照搬 RAC 类名;`[role="presentation"] > [data-slot="list-box-item"]` 宽度补偿 CSS(上游 react-aria 绝对定位行的移植遗留)对两滚模式仍成立,未改动。
|
||||
|
||||
### 3. 虚拟分组、动态过滤、异步追加的身份/选择/键盘/aria(已验证)
|
||||
|
||||
真实浏览器(playwright-core + 系统 Chrome,5173/5174)跨窗口键盘 ArrowDown×45 → 焦点条目「条目 46」`aria-posinset=46 / aria-setsize=900`(相对完整可见集合);Space 选择 `已选:46`,滚动离开再回(scrollTop 900→0)选择保持;过滤「条目 12」后渲染 7 项、选中 601 仍在;异步追加 100 项(61920→69672)后行流无空洞、选择保持。单测 `tests/virtual-rows.test.ts` 覆盖 heading 行不进 posinset 索引、loader 行独立计高、选择经逻辑 key emit 且受控回流标记、aria-setsize 恒为全集。
|
||||
|
||||
### 4. dropIndicatorThickness(记录,不补)
|
||||
|
||||
`grep` 确认 packages/vue 的 list-box/table 零拖放实现(无 drag/drop 代码):该参数度量放置指示线,无拖放则无对象,不补空参数冒充能力。已在 list-box.md / table.md 映射表记录为「不提供」。
|
||||
|
||||
## 用户可见通过条件(浏览器几何实测,对照固定源)
|
||||
|
||||
夹具 `tests/fixtures/virtual-rows.vue`(playground `?virtual-rows`)+ 三个文档示例(5173),记录于 scratchpad `verify-hd09.mjs` → `hd09.json`:
|
||||
|
||||
| 场景 | 实测 | 语义核对 |
|
||||
| --- | --- | --- |
|
||||
| 变高/分组/加载行/gap/padding(夹具) | pad 12(不计 gap)、heading wrapper 40=32+8、item 48/72/88=40/64/80+8、loader 40;几何衔接 top 4→16→56→104→176→264 无空洞 | gap 仅内容行之间、padding 两端;loaderHeight 独立 |
|
||||
| 滚动到底 | scrollTop 61600/61920、loader 行可见(40px) | 加载行可达 |
|
||||
| 异步追加 | 61920→69672、渲染 15 行、无跳位 | 行流连续 |
|
||||
| 跨窗口键盘 + 选择 | 条目 46、posinset 46/setsize 900、Space 选择保持 | 完整集合索引 |
|
||||
| 滚动定位(选中第 601 项) | scrollTop 46452、选中行可见 | revealRow 行偏移正确 |
|
||||
| 过滤 | 7 项、选中 601 保持 | 逻辑身份 |
|
||||
| 容器缩放 | 320→520 渲染 12→18 行 | bindVirtualRows/ResizeObserver |
|
||||
| 表格段变高(44/72+gap4、pad 12、loader 40) | 行 76/48 交替、padTop 12、scrollHeight 18700(含 loader 预留,DOM 自洽) | padTop+行+padBottom ≡ totalHeight |
|
||||
| 表格定位第 150 行 | scrollTop 9088、可见 行 141–157(含 overscan 6) | 前缀和偏移 |
|
||||
| 表格行数 300→600 | 37244→37300 对应、渲染 17 行 | count 响应式 |
|
||||
| 文档 list-box-virtualization | 50008/400 滚动、14 行、行高 50、到底 Benjamin Mar | 对照上游 50px/1000 项 |
|
||||
| 文档 table-virtualization | 外层 div 滚动 42084/300、16 行、行高 45(=42+border)、到底正常 | 对照上游 42px/1000 项 |
|
||||
| 文档 autocomplete-virtualization | filter 滚动 50056/400(overflow auto)、行高 50、14 行、到底 Benjamin Mar | 弹层整体滚动 |
|
||||
| autocomplete sticky | 滚 800px 后搜索框 top 相对 filter = 4(sticky top-0)、posinset 12 与滚动位一致、18 行 | sticky 搜索框恢复 |
|
||||
|
||||
“Benjamin Mar”=固定源生成数据末项 Benjamin Martinez,与上游一致。
|
||||
|
||||
## 启动与复现
|
||||
|
||||
```bash
|
||||
node scripts/task-check.mjs HD-09-VIRTUALIZATION # 前置通过
|
||||
pnpm exec vitest run tests/collection-filter-virtual.test.ts tests/table.test.ts \
|
||||
tests/collection-state.test.ts tests/virtual-rows.test.ts # 68 项
|
||||
pnpm test # 全量 112 文件 1683 项
|
||||
pnpm typecheck # vue-tsc 干净
|
||||
pnpm build:docs # 文档构建成功
|
||||
pnpm --filter playground build
|
||||
node scripts/check-package.mjs virtual-rows list-box b02-pickers api-root-aliases
|
||||
# 浏览器:5173/5174 在跑;scratchpad pw/verify-hd09.mjs、diag-auto-virt2.mjs、diag-auto-struct.mjs
|
||||
```
|
||||
|
||||
## 检查结果
|
||||
|
||||
- 卡内 checks:`tests/collection-filter-virtual.test.ts tests/table.test.ts tests/collection-state.test.ts`(57 项)+ 新增 `tests/virtual-rows.test.ts`(11 项)= 68 项全过。
|
||||
- 全量 vitest 112 文件 1683 项全过(HD-10 基线 1672 + 11)。typecheck 干净。build:docs 与 playground build 成功。
|
||||
- tarball 契约(最终打包产物、无源码 alias):新增 `tests/package/virtual-rows-contract.ts`(useVirtualRows/bindVirtualRows 选项与类型、ListBoxOptions 虚拟参数、`@ts-expect-error` 负例)+ `client-checks.json` 注册 `virtual-rows`(exports `useVirtualRows`/`bindVirtualRows`,CSS `data-virtualized` 钩子);`virtual-rows`/`list-box`/`b02-pickers`/`api-root-aliases` 四项通过(CSS token 按压缩产物实际形式匹配)。
|
||||
- 保留成果回归:HD-08(fr 列宽/上下限/容器缩放/排序焦点/自动空态跨列、th 行头/圆角/resizer)与 HD-10(共享 locale 过滤、异步防污染、插槽数据、子菜单 delay/RTL)对应套件全过;5173/5174 服务保留。
|
||||
- 文档/矩阵/来源同步:apps/docs/components/list-box.md(ListLayout 映射表)、table.md(TableLayout 映射表 + useVirtualRows 表)、docs/compatibility.md(HD-09 段与条目更新)、docs/upstream.md(HD-09 来源记录)。
|
||||
|
||||
## 限制与差异(如实记录)
|
||||
|
||||
- `estimatedHeadingHeight` / `headingHeight`(TableLayout):Vue 表格无分区表头模型,Table 侧不提供;ListBox 侧 `headingHeight` 固定(无可变标题测量)。
|
||||
- `dropIndicatorThickness`:拖放零实现,不提供(任务 4 按记录处理)。
|
||||
- autocomplete 弹层滚动高度 `max-h-[min(400px,70vh)]` 为近似可用空间钳制(上游无 max-h 限制、由 overlay 约束),属样式差异。
|
||||
- `overscan` 初始化时确定(VueUse 语义),动态调整未支持;虚拟模式要求 `items` + 竖向方向(违例抛错,语义不变)。
|
||||
- 表格示例行 inline 高 45px 为 42px + 边框排版差(border-collapse 排版),几何口径以布局参数为准。
|
||||
- 全量 vitest 偶发并发超时属环境性(隔离复跑全过,已有先例记录);本次全量一次通过。
|
||||
|
||||
|
||||
## 集成人复核:HD09-R1(2026-10-29,未验收)
|
||||
|
||||
复核入口 **ee37e66d37a128fb3cc28b6adb6af585675c0511**。原实施记录中的“逐项核销/无空洞/无跳位”不能作为最终验收结论;以下实际场景仍有阻断,暂不合main、不push。当前分支保留,用户无需重新提供旧聊天。
|
||||
|
||||
### 已直接补修
|
||||
|
||||
**ae27fb28d19f5611d23b5926a961e84e01be0002**:ListBox行wrapper由`item-${id}`改为`item-${encodeKey(id)}`,复用既有类型保真编码。新增测试让数字0与字符串0条目带组件局部状态后重排:修复前报`Duplicate collection key: 0`并出现卸载异常;修复后顺序正确且创建时身份与当前身份保持一致。浏览器夹具“反转零标识”实测为`当前 string:0 / 创建时 string:0`、`当前 number:0 / 创建时 number:0`。此项不再阻断,但返修须保留。
|
||||
|
||||
### 未关闭问题与准确复现
|
||||
|
||||
| ID | 严重度/位置 | 实测证据与影响 | 返修要求 |
|
||||
| --- | --- | --- | --- |
|
||||
| R1-01 | P1,ListBox虚拟行序列 / useVirtualRows geometry | `rowHeight`返回undefined只采用estimatedRowHeight,未观察行元素实际高度、未回写测量。5174 `?virtual-rows` 点击“切换未知行高”,原生换行内容高128,连续三行占位各56(48估算+8gap),top156/212/268,内容明显重叠。原夹具仅预先给出40/64/80,不足以证明未知内容的估算→实测闭环。标题估算亦明确未补,与任务范围不符。 | 在现有模型上补实际测量和修正,处理行/标题高度、宽度改变、过滤重排的类型保真缓存及锚定;不能只加一个永不校准的fallback或用差异文档把本卡能力移除。 |
|
||||
| R1-02 | P1,apps/docs/demos/table-virtualization.vue | 5173 `/components/table#虚拟滚动`,首屏16行均`style.height=42px`但实际45px,总scrollHeight42084;实际滚动后24行、aria-rowindex45–68、scrollTop2160,总scrollHeight42108。仅窗口项数变化就多出24px,模型与DOM不自洽。原报告“42+边框非布局偏差”结论不成立。table-fixed/额外ellipsis仍沿用,固定源对应示例没有这些类,尚未核销原恢复要求。 | 行布局/测量与spacer必须共享真实几何,保持固定集合总高度稳定并覆盖到底/反向滚动;对列布局和截断逐项恢复或提供确切适配证据,不用新增截断掩盖宽度问题。 |
|
||||
| R1-03 | P1,virtual-rows.ts scrollToIndex / bindVirtualRows | 原夹具点击“定位第150行”(调用索引150,实际第151行),scrollTop9088。视口top548/bottom848,目标top808/bottom884,高76的目标行仍有36px在视口外;表头恰为36px。算法只把正文offset当容器offset,缺行流原点/表头偏移。overscan使目标已挂载不能证明可见。 | 明确并处理行流起点与滚动坐标的关系,确保目标行实际可见;修正按钮0/1基口径,补真实矩形断言。 |
|
||||
| R1-04 | P1,ListBox.vue resolveScrollParent与watch(root) | 新夹具“加载父容器列表”:先挂载空集合,200px overflow父容器含48px固定搜索区;到达200项后root引用未变,旧绑定仍以列表自身为容器。浏览器实际listHeight10008、parentHeight200、scrollHeight10056、已挂载200项,未保持虚拟窗口。此场景等价异步初次响应/空过滤恢复,不是额外新功能。 | 不能以当前scrollHeight>clientHeight作为唯一祖先选择条件并只查一次;在数据/布局更新后正确绑定测量、scroll监听及清理,处理父级行流偏移和sticky区域。 |
|
||||
|
||||
复现已保存在 `tests/fixtures/virtual-rows.vue`(5174/?virtual-rows),仅公开组件组合、按钮和文本内容;未通过浏览器脚本修改状态或补发事件。Table正式示例没有做“修正截图”的补丁;保留原实现用于返修验证。上述父滚动容器、测量与坐标问题需要联动修改,超出少量边角修补,因此未强行集成。
|
||||
|
||||
### 本轮实际检查
|
||||
|
||||
- 原实现定向4文件/68项通过、typecheck通过,说明原用例未覆盖上述真实几何,并不免除返修。
|
||||
- typed key探针修复前失败,补修后定向4文件/**69项通过**;新复现夹具最终`pnpm typecheck`通过。修改代码Prettier、`git diff --check`通过。
|
||||
- 本轮未合并,所以未重复执行整库发布构建/最终tarball或把原1683项通过描述为补修后全量通过。返修完成后需针对最终代码重新做相关套件、构建、产物与浏览器验收。
|
||||
- 保留VueUse/Reka已有基础设施及HD-08/HD-10成果,未新增依赖;保留5173/5174。无SSR/水合/Nuxt服务端或逐像素专项。
|
||||
|
||||
继续任务:在当前`task/hd-09-virtualization`从本复核提交继续,按任务卡HD09-R1清单关闭四项,再更新本节问题状态与证据;不新建平行任务、不合main、不push。
|
||||
|
||||
## HD09-R1 最终修复与验收(2026-10-29)
|
||||
|
||||
用户随后明确要求本会话继续实施。本节覆盖前述未验收结论和原实施的限制说明;原证据保留,便于追溯,不代表问题仍未解决。
|
||||
|
||||
- 复核与typed key补修:ae27fb28d19f5611d23b5926a961e84e01be0002。
|
||||
- 测量、滚动与表格几何修复:**5a00e25a25bec484f3f0067545e992fa39ce53d3**。
|
||||
- 动态loader占位补修:**6d9e3f31cf0883cce416ce1056f675a65a536ec6**。
|
||||
- 沿用当前task/hd-09-virtualization,起点dd4f04c与原实施9e8d89e保留;未回退HD-08/HD-10或Header成果,无新增依赖。
|
||||
|
||||
### R1逐项关闭
|
||||
|
||||
| 项 | 最终处理 | 场景与证据 |
|
||||
| --- | --- | --- |
|
||||
| R1-01:估算→实测闭环 | useVirtualRows新增measureRow、稳定keys与resetMeasurements。函数行高返回undefined时先估算,挂载后ResizeObserver读取自然高度并更新前缀和。ListBox与Table复用同一几何;ListBox补函数式headingHeight与estimatedHeadingHeight。实测缓存保留key类型,宽度变化失效窗口外旧尺寸、重测可见内容;测量修正保留首个可见锚点。 | 未知ListBox内容128px/外层136px(含8px空白gap),无重叠;未知标题自然26px/外层34px。Table未知内容在800宽时205px,缩至520后重测305px,行间仍4px。新单测验证实测高度、typed cache与锚点(上方行增加50,scrollTop300→350且首可见逻辑行不变)。 |
|
||||
| R1-02:Table模型/DOM一致 | 新增TableRow.height作为精确几何的Vue适配。原生th/td保留,padding放入内部内容盒,避免原生单元格最小高度把42撑成45;省略height时保持自然DOM/排版供测量。内容盒保留普通流与继承对齐,不改非虚拟表格。正式示例移除额外table-fixed/ellipsis,保留700px最小宽与列minWidth。 | 正式示例表头42、数据行42,1000行滚动总高**42042**。首屏、滚动和Ctrl+End到末行、Ctrl+Home返回时总高一致;末行Benjamin Martinez完整可见,不再随窗口项数漂移。新单测确认fixed内容盒仅用于显式height行,原生行头scope=row保留。 |
|
||||
| R1-03:行流原点与定位 | bindVirtualRows新增content/scrollPaddingStart,Table默认识别真实tbody;观察表头与行流尺寸,定位计入实际起点和sticky遮挡。未知目标实测后再校准,用户滚动离开则取消待完成定位;修正第150行按钮为索引149。 | 已知第150行完整可见;未知表格第150行实测205px,目标top483/bottom688,视口392–692,包含全部内容。父容器Home后第1项相对视口top48,恰位于48px sticky区域下面;End到第200项完整可见。单测覆盖36px表头原点与40px sticky遮挡。 |
|
||||
| R1-04:父容器动态绑定 | 依据overflow策略选择容器,不依赖挂载时是否已溢出;root/content/virtualized变化与组件更新时检查绑定,scroll/resize监听按绑定清理。整体滚动时使用行流坐标;PageUp/Down按真实几何和可见视口定位。 | 200px父容器空→200项后仅挂载约9项,End/ Home跨窗口往返正确。未知主列表定位第601项后PageDown到第604项;位置与aria-posinset一致。过滤“条目 12”后aria-setsize11且仍选601;恢复并追加100项后setsize900,选择仍601。 |
|
||||
| 动态loader残留 | slots对象本身不提供依赖追踪:同步记录loader插槽是否存在,及时失效行流。保留loaderHeight与真实slot,避免关闭后空留48px。 | 新回归在items不变时移除条件loader:补修前仍2行、补修后仅1条数据行。表格末尾实际loader40px,滚到底时top640/bottom680、视口392–692,完整可达;总高仍18700。 |
|
||||
|
||||
### 最终验证
|
||||
|
||||
- `pnpm exec vitest run`:**112文件 / 1688项通过**(原1683 + typed key1 + 实测/原点/精确TableRow3 + 动态loader1)。原断言未删除/skip,不放宽超时。
|
||||
- `pnpm typecheck`通过。最终额外夹具的完整rowKeys/focusRow组合也通过类型与playground构建。
|
||||
- 最终 `node scripts/check-package.mjs virtual-rows list-box b02-pickers api-root-aliases m35-m36`通过:独立tarball ESM/CSS、bundler/NodeNext类型正反例;覆盖measureRow/bind配置、函数式标题估算、TableRow.height与原有选择器/Table契约,CSS精确行内容盒进入产物。
|
||||
- 最终库dist后的docs与playground生产构建通过。仅既有文档chunk大小提示;代码Prettier和git diff --check通过。
|
||||
- 真实浏览器使用5174 `?virtual-rows`与5173正式Table虚拟化示例;本节记录实际DOM矩形与真实点击/键盘/滚动,不以挂载、CSS token或代数恒等式替代可见性。
|
||||
- 源码/文档/兼容矩阵/来源同步。纠正旧报告中的“45px边框差异不影响布局”“Vue无表头模型”“仅回退值代表估算完成”“overscan仅初始化”口径;原实现的VueUse范围计算被共享行几何承接,集合身份/选择/焦点状态仍是同一份。
|
||||
|
||||
### 当前边界
|
||||
|
||||
- 显式数字行高由调用方保证容纳内容;未知内容不要强制固定CSS高度,应返回undefined并绑定measureRow。TableHeader常驻,因此按实际tbody原点处理表头,无需提供一个脱离DOM的表头估算参数。
|
||||
- 估算行在未访问前仍使用估算值,访问后校准,这是估算语义;批量替换窗口外内容的组合式消费者可调用resetMeasurements。组合式应在Vue setup/effectScope中使用,以随生命周期清理测量观察器。
|
||||
- ListBox沿用默认50px以兼容已有数据模式;公共Table几何的默认估算为48px。三个固定源示例仍分别显式42/50/50,不混淆默认与示例传值。
|
||||
- Table gap/loader由消费方在预留空间中渲染presentation行,避免双算高度;夹具提供实际示例。无拖放,不提供dropIndicatorThickness;Autocomplete的400px/70vh高度上限仍是已披露的可用空间近似。
|
||||
- 浏览器客户端范围;未执行SSR/水合/Nuxt服务端、逐像素或完整设备/读屏矩阵。
|
||||
|
||||
R1四项及typed key均已关闭。本会话完成最终验收,按用户授权合入main并push origin/main;保留5173/5174,未自动启动下一任务。
|
||||
@@ -0,0 +1,101 @@
|
||||
# HD-10-COLLECTIONS 结果记录
|
||||
|
||||
- 任务卡:[HD-10-COLLECTIONS](../HD-10-COLLECTIONS.md);固定上游 `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`apps/docs/src/demos/cn/combo-box/asynchronous-loading.tsx`、`dropdown.tsx` 及 react-aria/react-stately 依赖)。
|
||||
- 分支 task/hd-10-collections;起点 c34faccd7051a3c17bc510da05858ca29fdaf1cc(main tip,含 HD-08 验收与集成补修 c019768);实施 c8d54abefbf668fe10f2f7f6ab6ecca945a471e3(21 文件,picker/菜单组件、演示与夹具、契约与测试、文档与记录源);记录提交为本文件所在提交。主会话实施/自测,未合 main、未 push。
|
||||
- 本卡不扩展 HD-09 虚拟布局;未开展 SSR/水合/Nuxt 专项。
|
||||
|
||||
## 范围 1:ComboBox 异步例自动增量加载与请求防污染
|
||||
|
||||
**修改**(apps/docs/demos/combo-box-asynchronous-loading.vue 重写):
|
||||
|
||||
- **滚动到底自动增量加载**:IntersectionObserver 哨兵(隐藏 1px 元素)驱动 loadMore;加载中显示基线同款加载行(`flex items-center justify-center gap-2 py-2` + Spinner sm + 「加载更多…」,`text-sm text-muted` 保留已纠正的类写法);新页未把哨兵推出视口时续载链保持填充(等价固定源 ListBoxLoadMoreItem 每次集合变更重挂载观察器的语义)。
|
||||
- **防重复请求/旧请求/过期响应**:`loading || loadingMore || error || !hasMore` 守卫(单测双触发出一次请求);新请求 abort 旧请求(AbortController);单调序号令牌丢弃过期响应(查询切换中途不混入旧数据,单测 + 浏览器实证)。
|
||||
- **失败重试**:错误态显示「重试」按钮(异常态保留,不退化为纯手动加载);本地数据源以「模拟加载失败」开关注入失败。
|
||||
- **模拟数据与 SWAPI 的差异**:示例注释与 combo-box.md「异步加载」节明确记载——固定源请求 swapi.py4e.com(useAsyncList 游标分页、82 条远端人员),本例为 12 条本地角色、模拟 300ms 延迟、失败可注入;加载行位于 ListBox 之外(固定源为行内 ListBoxLoadMoreItem 哨兵),自动触发语义一致。
|
||||
|
||||
**Select 未重复实现(验证)**:select-asynchronous-loading 的 useIntersectionObserver 真实网络滚动触发经浏览器实测——初始 20 条、滚动自动追加至 180 条、无重复(180 unique),未改其实现。
|
||||
|
||||
**证据**:单测 3 项(combo-box-demos.test.ts:自动增量+防重复、过期丢弃、失败重试);真实浏览器(文档站):自动链加载 12/12 无重复、查询切换 vader→solo 仅剩 Han Solo、失败→重试→恢复 8 条。
|
||||
|
||||
## 范围 2:过滤逻辑共用与 locale 敏感折叠
|
||||
|
||||
**修改**:`createBaseContains`(Intl.Collator `sensitivity: "base"`,与 Autocomplete/ComboBox 默认谓词同一实现)从包根公开;autocomplete-virtualization 示例改用 `useLocale()` + `createBaseContains` 过滤(原 `toLocaleLowerCase().includes` 的大小写折叠但无变音折叠),与默认过滤共用一份逻辑。文档「过滤函数(useFilter 替代)」补公开导出说明。
|
||||
|
||||
**证据**:既有组件测试「Autocomplete default base-sensitivity filter matches accents」(`cafe` 命中 `Café`)不变并通过;b02-pickers 类型契约以 `sharedMatcher("Café", "cafe")` 钉签名;真实浏览器验证列表过滤(solo/vader 查询)行为正确。
|
||||
|
||||
## 范围 3:Autocomplete 触发器语义与插槽组合能力
|
||||
|
||||
**核实(真实浏览器,autocomplete-default / autocomplete-multiple-select)**:
|
||||
|
||||
| 项 | 实测 | 结论 |
|
||||
| ------------------ | ---------------------------------------------------------------------------------- | ------------------------------------- |
|
||||
| Tab 停靠 | 触发器 `role=button tabindex=0` 唯一停靠;clear button `tabindex=-1`;Tab 离开组合 | 与「单一 Tab 入口」声明一致,无需修改 |
|
||||
| Enter / Space | 各自打开列表 | ✓ |
|
||||
| Escape | 关闭并回焦触发器 | ✓ |
|
||||
| Delete / Backspace | 清除选中("Florida"→占位「选择州/省」;多选两项→占位) | ✓ |
|
||||
| IME | `isComposing` 的 Enter 不触发 | ✓ |
|
||||
| 单选 | 选择后触发器显示选中值 | ✓ |
|
||||
| 多选 | 两项组合显示("CaliforniaTexas")、Delete 整体清除 | ✓ |
|
||||
|
||||
role=button/tabindex 与固定源 RAC Group 的差异为既有文档化适配(「单一 Tab 入口」模型),实测无不符合等价公开组合的停靠点,**无需修改**。
|
||||
|
||||
**修改(插槽数据补齐组合能力)**:`AutocompleteValue` 作用域插槽补 `selectedItem`(首个/单选项)且 `selectedItems` 条目携带 `item`(根 `items` 中的源数据项);`ComboBox` 根插槽补 `selectedItem`。对齐上游 `selectedItem` 与 `(T | null)[] selectedItems` 的值语义,调用方无需按键反查自己的数据(原示例普遍 `users.find(...)`);不执行未知组件 setup/render、不复制子组件。集合自发现项(无 `items` prop)`item` 为 undefined。类型契约(b02-pickers-contract.ts)与单测(picker-public-contracts +2)钉住形状。
|
||||
|
||||
## 范围 4:Dropdown 子菜单 delay、配置契约与 RTL
|
||||
|
||||
**核实**:固定源 `useSubmenuTrigger` 的 `delay` 默认 200ms,经 RAC `SubmenuTrigger`/HeroUI `DropdownSubmenuTrigger` 逐层透传为公共 prop;我方此前为 Reka 固定 100ms 且无配置(审计属实)。
|
||||
|
||||
**修改**:`DropdownSubmenuTrigger` 新增 `delay` prop(默认 200ms)。实现为受控 open 门 + 悬停定时:hover 启动定时(仅鼠标指针,同 Reka 的 isMouseEvent 门),Reka 的 100ms 早期请求在门内被吞、由配置延迟接管;键盘展开立即生效并取消挂起定时(与基线 `onSubmenuOpen → cancelOpenTimeout` 一致);指针离开/关闭/卸载取消。顺带移除对子菜单面板 `side`/`align` 的无效透传(Reka MenuSubContent 的模板绑定固定 side 且实测透传 attrs 不生效;注释与文档均已声明「底层固定」)。
|
||||
|
||||
**真实浏览器证据**(tests/fixtures/collections-rtl.vue,playground 5174 注册;ConfigProvider dir + DropdownRoot dir 双路):
|
||||
|
||||
| 项 | RTL 实测 | LTR 实测 |
|
||||
| ------------------------- | ---------------------------------- | --------------------- |
|
||||
| 默认延迟(200ms) | 222ms 打开 | 216ms 打开 |
|
||||
| 自定义 `:delay="600"` | 618ms 打开 | — |
|
||||
| 键盘展开(ArrowLeft/RTL) | 32ms(立即) | — |
|
||||
| 定位 | subX 342 < triggerX 536 → **向左** | subX 740 > 536 → 向右 |
|
||||
|
||||
定位链路探针证实方向由 ConfigProvider→菜单根逐层解析(早前贴左缘时 side=left 碰壁翻转为 right 属碰撞翻转的正常行为)。文档站另有 hoverDefault 245ms / keyboard 46ms 对照。
|
||||
|
||||
**Button/Avatar 触发器布局补偿(保留)**:浏览器证据显示补偿规则 `.hv-dropdown__trigger.hv-button{display:inline-flex}` 实际胜出(inline-flex 作为 flex 子项被块化为 computed `flex`,禁用样式表后回落 `.hv-dropdown__trigger` 的 inline-block 证明补偿在起作用);未发现布局问题,**保留不改**。
|
||||
|
||||
## 检查与验证
|
||||
|
||||
- `node scripts/task-check.mjs HD-10-COLLECTIONS`(head c34facc)✅
|
||||
- 卡内 checks:`vitest run` 7 套件(autocomplete/combo-box/select/b01-menu-dropdown/picker-public-contracts 等,175 项,复核实测纠正原计数)✅、`pnpm typecheck` ✅
|
||||
- 全量 `pnpm exec vitest run`:**111 文件 / 1666 项**(新增 8:3 子菜单 delay 契约、3 异步加载行为、2 插槽数据)✅;既有断言零修改
|
||||
- `pnpm build:docs` ✅;prettier ✅
|
||||
- 最终 tarball:`node scripts/check-package.mjs b02-pickers api-root-aliases` ✅(`createBaseContains` 入契约导出;b02-pickers-contract.ts 增 selectedItem/item/匹配器类型正反例,nodenext/bundler 双解析 strict 通过)
|
||||
- 真实浏览器(playwright-core + 系统 Chrome):异步滚动/防重/过期/重试、触发器键盘/IME/单多选、子菜单延迟/RTL/键盘、触发器布局;截图 hd10-submenu-ltr.png 等存档
|
||||
- 文档同步:combo-box.md(异步差异说明、插槽表)、autocomplete.md(插槽表、过滤函数节)、dropdown.md(delay 行与差异注记)、兼容矩阵与来源记录
|
||||
|
||||
## 未完成与限制
|
||||
|
||||
1. RTL 夹具使用 ConfigProvider + DropdownRoot 双路传 dir(二者均实测生效);纯文档示例未包 ConfigProvider,站级 RTL 切换不在本卡范围。
|
||||
2. Reka MenuSubTrigger 的 100ms 固定计时无法配置,延迟门为受控 open 层重定(DropdownSubmenuTrigger.vue 注释记载机制与基线差异);拖动/触摸指针不启动悬停展开(与 Reka isMouseEvent 一致)。
|
||||
3. `ComboBoxValue`/`AutocompleteValue` 的 `item` 类型为 `ComboBoxItem`/`AutocompleteItem`(含额外字段的对象经结构性赋值传入,消费者按自身类型收窄);未引入泛型插槽类型。
|
||||
4. 测试环境偶发并发超时(与本卡改动无关,隔离复跑全过);button-toggle 间歇项已在 HD-08 记录中归档。
|
||||
|
||||
|
||||
## 集成人复核与补修(2026-10-29)
|
||||
|
||||
入口 `d1528569a8e7b2aeb589897c63279919d61bd554`,用户授权少量问题直接补修后合并push;补修 **`bf6cf0f8d12fe54a72e5ff524b1b05dbaadcfe86`**。
|
||||
|
||||
| 项 | 复现与修复 | 证据 |
|
||||
| --- | --- | --- |
|
||||
| 悬停等待期间点击被吞 | 原门禁仅区分全局keydown与hover,点击发生在600ms计时期间也被阻止。改为触发器本地capture记录实际激活事件,click/键盘可绕过hover等待,移除各实例window keydown监听。 | 修复前新增点击探针失败;修复后50ms时点击立即打开,不等待600ms。 |
|
||||
| 禁用项被hover计时器打开 | 自有定时器绕过底座disabled检查,isDisabled、Menu disabledKeys与等待期间变禁用三种均复现打开。改为读取实际触发器aria-disabled/data-disabled,在排程、到期与底座open请求三个边界校验。 | 三个探针修复前全部失败、修复后全部通过;浏览器禁用分享后菜单项真实aria-disabled=true且无法展开。 |
|
||||
| click取消与关闭清理 | asChild底座可先于消费方bubble处理器请求open。click的接受延至本次事件链完成后检查defaultPrevented,保持消费方取消与单次回调;键盘仍同步进入底座原焦点路径。父根关闭清除待执行hover并关闭本级。 | 新增消费方preventDefault与父关闭/重开两项回归;取消点击不会绕过延迟,父级关闭后不会残留打开。 |
|
||||
| 产物契约与变更范围 | 补b01-menu-dropdown最终包的delay number正反例;client-checks.json还原无关整文件格式变化,仅保留createBaseContains增量导出。夹具加入禁用开关,移除源码实验性注释。 | 三组最终tarball双解析/ESM/CSS通过;未更改已有断言或新增依赖。 |
|
||||
|
||||
### 最终复核结果
|
||||
|
||||
- 全量 `pnpm exec vitest run`:**111文件 / 1672项通过**(原实施1666+本轮6:点击1、两种禁用2、动态禁用1、父关闭1、消费方取消1);`pnpm typecheck`通过。
|
||||
- 最终 `node scripts/check-package.mjs b01-menu-dropdown b02-pickers api-root-aliases`通过:新增delay类型正反例、选项源数据槽、过滤器导出及原有契约。使用最终dist的docs/playground构建通过;Prettier与git diff --check通过。未因历史间歇项放宽超时或跳过断言。
|
||||
- 5173正式ComboBox异步示例:打开后4→12条且无重复;快速vader→solo后仅Han Solo。注入失败后空集合+重试按钮,关闭失败开关并重试后仅Darth Vader且重试消失。实际原生指针切换失败开关,未用脚本补发事件。
|
||||
- 5173正式Select异步例:初始20条,实际在弹层内滚动后40条、40个唯一名称;保留原IntersectionObserver实现。
|
||||
- 5174 `?collections-rtl`:禁用分享不可展开;启用后RTL真实Home/Down/Left立即展开,焦点到“邮件”,trigger x536/submenu x316且data-side=left。Escape逐级关闭,切LTR点击展开时submenu x约744、data-side=right。保留原实施的200/600ms真实hover测量;本轮对应延迟、离开取消、键盘立即的定时回归重新全量通过,不将单测时钟冒称新的浏览器耗时测量。
|
||||
- 源码确认虚拟化例与默认过滤共用createBaseContains,locale来自useLocale的响应式computed;既有Café/cafe与组合输入/键盘单多选回归全部保留通过。插槽数据源契约沿用原实施的两个新增运行时断言与最终包类型验证。
|
||||
|
||||
无本卡阻断项。状态 **accepted**,按用户授权合入main并push origin/main;保留5173/5174。未启动HD-09或其他任务,未执行SSR/水合/Nuxt服务端、逐像素或完整设备/读屏矩阵。
|
||||
+31
-1
@@ -169,7 +169,7 @@ M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生
|
||||
|
||||
## LISTBOX-01(2026-10-23)
|
||||
|
||||
固定 ce90ea3 的 list-box / list-box-item / list-box-section 源码、CSS/tv,以及中文正文和九个预览。CSS/tv 按 hv- 移植,源勾选图形遵循原 Apache-2.0;文档图标用现有 Tabler Vue。原 alert 演示曾改为内联状态反馈(2026-10-28 HD-02 已按固定基线恢复为 alert 反馈与原结构),React render 改 as/插槽,Virtualizer/ListLayout 改 VueUse 固定行高虚拟化。依据、差异与限制见 [LISTBOX-01](component-notes.md)。
|
||||
固定 ce90ea3 的 list-box / list-box-item / list-box-section 源码、CSS/tv,以及中文正文和九个预览。CSS/tv 按 hv- 移植,源勾选图形遵循原 Apache-2.0;文档图标用现有 Tabler Vue。原 alert 演示曾改为内联状态反馈(2026-10-28 HD-02 已按固定基线恢复为 alert 反馈与原结构),React render 改 as/插槽,Virtualizer/ListLayout 改 VueUse 虚拟行序列(固定/可变行高、heading/loader 行、gap/padding,语义映射见 list-box.md 的 ListLayout 映射表)。依据、差异与限制见 [LISTBOX-01](component-notes.md)。
|
||||
|
||||
## M33–M34(2026-10-23)
|
||||
|
||||
@@ -356,3 +356,33 @@ CSS/tv 仅加 `hv-` 前缀与 Apache-2.0 来源;`colorPickerVariants` 保持
|
||||
## HD-01 示例与 Dropdown 组合(2026-10-28)
|
||||
|
||||
Button/ButtonGroup/ToggleButton/ToggleButtonGroup与指定Accordion/Disclosure示例按ce90ea3的cn源码恢复,保留Tabler图标适配。Vue Dropdown根容器承载attrs/原生事件;ButtonGroup CSS增加仅作用于标记直接成员的位置规则,圆角/outline数值沿用基线,来源许可保留。行为和证据见HD-01任务结果。
|
||||
|
||||
## HD-05 来源(2026-10-28)
|
||||
|
||||
- packages/styles/src/index.ts 的 `labelVariants`/`descriptionVariants`/`fieldErrorVariants`/`textFieldVariants`/`switchGroupVariants`:移植 `heroui/packages/styles/src/components/{label/label,description/description,field-error/field-error,textfield/textfield,switch-group/switch-group}.styles.ts`,仅加 `hv-` 前缀;变体键、默认值与 slot 集合逐键保留(Apache-2.0,见 third-party/HEROUI-LICENSE)。
|
||||
- packages/styles/base/base.css:移植 `heroui/packages/styles/base/base.css` 的边框色继承规则(`*, ::after, ::before, ::backdrop, ::file-selector-button { border-color: var(--border, currentColor) }`),导入序保持 preflight 之后的 base 层。同文件的 `:root { view-transition-name: none }` 与 `::view-transition { pointer-events: none }` 未移植:库与文档站均无 View Transitions API 使用证据,按 HD-05 约定记录无需修改,不建立专项。
|
||||
|
||||
### HD-06(2026-10-29)
|
||||
|
||||
Link/Breadcrumbs 对照固定 ce90ea3;Breadcrumbs 的34种名称移植自该上游锁文件的 react-aria 3.52.1 `dist/private/intl/breadcrumbs`,仅数据,不引入 React 运行时。Adobe Apache-2.0声明保留于第三方许可及组件包 `LICENSE.react-aria`(随 tarball发布)。Vue identity采用 id/key/index,事件为 @action。日期焦点标记适配真实 DOM :focus-visible。
|
||||
|
||||
### HD-07(2026-10-29)
|
||||
|
||||
固定HeroUI ce90ea3的InputOTP公开类型及锁定input-otp1.5.0(npm tarball只读source map)核对:pattern.test整值、pasteTransformer先转换、complete effect只跟随accepted value跨阈值。仅在现有Vue/Reka字段/PinInput边界适配,不安装React或增加运行时依赖;底座多input、索引空位、单字段提交保留。全局/sticky RegExp去状态化延续既有Vue行为;字符选区限单槽,非单input任意跨槽选择。字段错误与focus采用现有共享上下文,新增原生ValidityState快照。
|
||||
|
||||
## HD-08 来源(2026-10-29)
|
||||
|
||||
- packages/vue/src/components/table/widths.ts:移植 react-stately `TableUtils.js`(`calculateColumnSizes` flex-grow 列宽解析、min/max 违规冻结、级联取整)与 `TableColumnLayout.js` 的默认宽度语义(未设宽度按 `1fr`),Apache-2.0;仅函数级移植,无新状态内核。
|
||||
- 排序焦点环转发与空状态跨列自适应为 Vue 适配(基线由 RAC useTableColumnHeader 的 press/focus 与 TableBody colSpan 承担);`aria-sort` 的 `"none"` 输出与基线 useTableColumnHeader 一致,不作改动。
|
||||
|
||||
## HD-10 来源(2026-10-29)
|
||||
|
||||
- 子菜单 hover 延迟契约对齐 react-aria `useSubmenuTrigger`(`delay` 默认 200ms、任何 open 请求先取消挂起定时、指针离开取消),Apache-2.0;实现为受控 open 门 + 定时器(Reka 2.11 的固定 100ms 悬停计时不可配置,见 DropdownSubmenuTrigger.vue 注释)。
|
||||
- Autocomplete/ComboBox 的 `selectedItem`/`selectedItems.item` 插槽数据对应上游 `selectedItem`/`(T | null)[] selectedItems` 的值语义;以 Vue 插槽数据补齐,不复制 item 子树(固定源 Callout 的 children 复制行为不移植)。
|
||||
- `createBaseContains` 与 `useFilter({sensitivity:"base"}).contains` 语义一致(locale 敏感折叠),作为公开过滤器与默认谓词共用。
|
||||
|
||||
## HD-09 虚拟布局(2026-10-29)
|
||||
|
||||
固定 ce90ea3 的 `TableLayout`/`ListLayout` 布局契约(table.mdx / list-box.mdx 参数表)与三个虚拟化示例(table 42px、list-box/autocomplete 50px 显式行高;autocomplete 弹层整体滚动 + sticky 搜索框)。`packages/vue/src/components/collection/virtual-rows.ts` 为自研纯测量实现(前缀和+二分),仅语义对齐契约(gap 在内容行之间、padding 为两端占位、loader 预留在行流末尾),非上游代码移植;ListBox 行序列走 VueUse `useVirtualList`(函数式 itemHeight)。autocomplete.css 的虚拟化弹层滚动规则为本仓新增(历史 320px 列表自滚规则限定 `:not([data-virtualized])` 保留);上游样式无 max-h 限制,`max-h-[min(400px,70vh)]` 是近似可用空间钳制的替代,差异如实记录。dropIndicatorThickness 对应拖放布局,Vue 侧 ListBox/Table 零拖放实现,不提供。
|
||||
|
||||
HD09-R1:自然行/标题测量、类型保真尺寸缓存和滚动绑定为本库Vue适配;ListBox复用同一useVirtualRows几何,保留既有集合选择/焦点模型,不引入React状态或第二套全局协议。Table原生th/td的padding最小高度与42px虚拟行冲突已证实,新增TableRow.height内容盒适配,不改变非虚拟表格默认DOM。TableLayout headingHeight对应常驻表头,按真实tbody原点处理,纠正原“无分区表头模型所以不提供”的解释。
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/* Adapted from HeroUI ce90ea3, packages/styles/base/base.css.
|
||||
* Copyright 2025 NextUI Inc. Apache-2.0; see third-party/HEROUI-LICENSE. */
|
||||
|
||||
/* Border color inheritance
|
||||
*
|
||||
* Every border without an explicit color resolves to the theme border token
|
||||
* instead of `currentColor`. This lives in the base layer right after
|
||||
* Tailwind preflight, so component rules (components layer), utilities and
|
||||
* consumer CSS all override it normally — no !important required. When
|
||||
* `--border` is undefined the declaration falls back to `currentColor`. */
|
||||
*,
|
||||
::after,
|
||||
::before,
|
||||
::backdrop,
|
||||
::file-selector-button {
|
||||
border-color: var(--border, currentColor);
|
||||
}
|
||||
@@ -200,10 +200,24 @@
|
||||
* popover itself is constrained (e.g. inside a Modal, or a short viewport). Without
|
||||
* it the list keeps its full 320px and its overflow is clipped by the popover, making
|
||||
* the last options unreachable. */
|
||||
[data-slot="list-box"] {
|
||||
[data-slot="list-box"]:not([data-virtualized]) {
|
||||
@apply max-h-[320px] min-h-0 scrollbar overflow-y-auto p-1.5 outline-none;
|
||||
}
|
||||
|
||||
/* Virtualized lists scroll the popover content as a whole (the pinned
|
||||
* upstream layout): the row window binds to this scrolling ancestor and the
|
||||
* search field can stay sticky at its top. The height cap stands in for the
|
||||
* upstream overlay's available-space clamp. */
|
||||
&:has([data-slot="list-box"][data-virtualized]) [data-slot="autocomplete-filter"] {
|
||||
@apply max-h-[min(400px,70vh)] overflow-y-auto;
|
||||
}
|
||||
|
||||
[data-slot="list-box"][data-virtualized] {
|
||||
@apply min-h-0 p-1.5 outline-none;
|
||||
max-height: none;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
[data-slot="list-box-item"] {
|
||||
@apply px-2.5;
|
||||
}
|
||||
|
||||
@@ -170,6 +170,15 @@
|
||||
@apply flex items-center justify-between;
|
||||
}
|
||||
|
||||
/* The trigger button owns keyboard focus (click/Enter/Space activate the
|
||||
column's sort once), but the visible ring stays on the column header like
|
||||
the pinned baseline: the trigger forwards its real `:focus-visible` state to
|
||||
the th's `data-focus-visible` hook, so its own UA outline is suppressed here
|
||||
(scoped: a trigger outside a column keeps the default ring). */
|
||||
.hv-table__column .hv-table__sortable-column-trigger {
|
||||
@apply outline-none;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
Sortable Column Indicator — chevron that flips based on `data-direction`.
|
||||
Defaults to pointing up (ascending) and rotates 180° for descending.
|
||||
@@ -261,12 +270,31 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* Native row headers (<th scope="row">) render with the baseline cell
|
||||
* typography: `inherit` replicates the pinned source's td-based row headers
|
||||
* (UA bold/center neutralised) while caller text-align/font-weight keep
|
||||
* cascading into every cell — scoping the reset to `th` preserves ancestor
|
||||
* inheritance for the regular td cells. */
|
||||
/* Explicit virtual row heights must not be enlarged by native cell padding.
|
||||
Keep the original padding on an inset content box, with native th/td intact. */
|
||||
.hv-table__cell[data-fixed-height] {
|
||||
position: relative;
|
||||
padding: 0;
|
||||
overflow: clip;
|
||||
}
|
||||
.hv-table__fixed-cell-content {
|
||||
@apply absolute inset-x-0 top-1/2 -translate-y-1/2 px-4 py-3;
|
||||
}
|
||||
|
||||
th.hv-table__cell {
|
||||
text-align: inherit;
|
||||
font-weight: inherit;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
Table Cell (<td>)
|
||||
-------------------------------------------------------------------------- */
|
||||
.hv-table__cell {
|
||||
/* Native row headers must preserve the baseline cell typography/alignment. */
|
||||
@apply text-start font-normal;
|
||||
@apply h-full bg-surface px-4 py-3 align-middle text-sm text-foreground;
|
||||
|
||||
@apply border-b border-separator-tertiary/50;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
@layer theme, base, components, utilities;
|
||||
@import "tailwindcss/theme.css" layer(theme);
|
||||
@import "tailwindcss/preflight.css" layer(base);
|
||||
/* Base defaults follow preflight so they win same-layer ties (border color
|
||||
* fallback); upstream keeps them in base/base.css in the same order. */
|
||||
@import "./base/base.css" layer(base);
|
||||
@import "./themes/shared/theme.css";
|
||||
@import "./themes/default/variables.css";
|
||||
/* Mode overrides must follow theme defaults so an explicit mode on a theme root wins. */
|
||||
|
||||
@@ -119,6 +119,28 @@ export const switchVariants = tv({
|
||||
|
||||
export type SwitchVariants = VariantProps<typeof switchVariants>;
|
||||
|
||||
export const switchGroupVariants = tv({
|
||||
defaultVariants: {
|
||||
orientation: "vertical",
|
||||
},
|
||||
slots: {
|
||||
base: "hv-switch-group",
|
||||
items: "hv-switch-group__items",
|
||||
},
|
||||
variants: {
|
||||
orientation: {
|
||||
horizontal: {
|
||||
base: "hv-switch-group--horizontal",
|
||||
},
|
||||
vertical: {
|
||||
base: "hv-switch-group--vertical",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type SwitchGroupVariants = VariantProps<typeof switchGroupVariants>;
|
||||
|
||||
export { tv, cn, type VariantProps } from "tailwind-variants";
|
||||
|
||||
export const closeButtonVariants = tv({
|
||||
@@ -199,6 +221,21 @@ export const textAreaVariants = tv({
|
||||
|
||||
export type TextAreaVariants = VariantProps<typeof textAreaVariants>;
|
||||
|
||||
export const textFieldVariants = tv({
|
||||
base: "hv-textfield",
|
||||
defaultVariants: {
|
||||
fullWidth: false,
|
||||
},
|
||||
variants: {
|
||||
fullWidth: {
|
||||
false: "",
|
||||
true: "hv-textfield--full-width",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type TextFieldVariants = VariantProps<typeof textFieldVariants>;
|
||||
|
||||
export const avatarVariants = tv({
|
||||
defaultVariants: {
|
||||
color: "default",
|
||||
@@ -1746,6 +1783,40 @@ export const errorMessageVariants = tv({
|
||||
|
||||
export type ErrorMessageVariants = VariantProps<typeof errorMessageVariants>;
|
||||
|
||||
export const labelVariants = tv({
|
||||
base: "hv-label",
|
||||
defaultVariants: {
|
||||
isDisabled: false,
|
||||
isInvalid: false,
|
||||
isRequired: false,
|
||||
},
|
||||
variants: {
|
||||
isDisabled: {
|
||||
true: "hv-label--disabled",
|
||||
},
|
||||
isInvalid: {
|
||||
true: "hv-label--invalid",
|
||||
},
|
||||
isRequired: {
|
||||
true: "hv-label--required",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type LabelVariants = VariantProps<typeof labelVariants>;
|
||||
|
||||
export const descriptionVariants = tv({
|
||||
base: "hv-description",
|
||||
});
|
||||
|
||||
export type DescriptionVariants = VariantProps<typeof descriptionVariants>;
|
||||
|
||||
export const fieldErrorVariants = tv({
|
||||
base: "hv-field-error",
|
||||
});
|
||||
|
||||
export type FieldErrorVariants = VariantProps<typeof fieldErrorVariants>;
|
||||
|
||||
export const comboBoxVariants = tv({
|
||||
defaultVariants: {
|
||||
fullWidth: false,
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2019 Adobe
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -4,7 +4,8 @@
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist"
|
||||
"dist",
|
||||
"LICENSE.react-aria"
|
||||
],
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@@ -453,6 +453,7 @@ export default defineComponent({
|
||||
textValue:
|
||||
records.value.find((record) => record.key === key)?.text ??
|
||||
String(key),
|
||||
item: props.items?.find((entry) => entry.id === key),
|
||||
})),
|
||||
),
|
||||
selectionMode: computed(() => props.selectionMode),
|
||||
|
||||
@@ -20,6 +20,7 @@ export default defineComponent({
|
||||
defaultChildren,
|
||||
selectedText,
|
||||
selectedItems,
|
||||
selectedItem: selectedItems[0] ?? null,
|
||||
}) ?? defaultChildren;
|
||||
return h(
|
||||
"span",
|
||||
|
||||
@@ -5,9 +5,11 @@ import type { CollectionRecord, OwnedCollection } from "../collection/owner";
|
||||
import type { useChoiceField } from "../choice/shared";
|
||||
|
||||
export type AutocompleteValue = CollectionKey | CollectionKey[] | null;
|
||||
export interface AutocompleteSelectedItem {
|
||||
export interface AutocompleteSelectedItem<T = AutocompleteItem> {
|
||||
key: CollectionKey;
|
||||
textValue: string;
|
||||
/** Source entry from the root `items` (absent for collection-discovered items). */
|
||||
item?: T;
|
||||
}
|
||||
export interface AutocompleteOptions {
|
||||
modelValue?: AutocompleteValue;
|
||||
@@ -42,6 +44,12 @@ export interface AutocompleteValueState {
|
||||
/** Accepted `textValue`s joined by ", ". */
|
||||
selectedText: string;
|
||||
selectedItems: AutocompleteSelectedItem[];
|
||||
/**
|
||||
* First accepted entry (the single-select selection), or null. Entries carry
|
||||
* the source `items` data in `item` so callers can compose rich trigger
|
||||
* content from their own records without re-mapping keys.
|
||||
*/
|
||||
selectedItem: AutocompleteSelectedItem | null;
|
||||
}
|
||||
/** Scoped-slot state of the `Autocomplete` root. */
|
||||
export interface AutocompleteState {
|
||||
|
||||
@@ -13,6 +13,9 @@ import {
|
||||
import { breadcrumbsVariants } from "@heroui-vue/styles";
|
||||
import { disabledContextKey, useInheritedDisabled } from "../field/disabled";
|
||||
import BreadcrumbsItem from "./BreadcrumbsItem.vue";
|
||||
import { useLocale } from "../../providers/context";
|
||||
import { breadcrumbsLabel } from "./locale";
|
||||
import { breadcrumbsActionKey } from "./context";
|
||||
|
||||
function flattenChildren(
|
||||
nodes: VNodeChild[],
|
||||
@@ -46,7 +49,7 @@ export default defineComponent({
|
||||
props: {
|
||||
ariaLabel: {
|
||||
type: String,
|
||||
default: "Breadcrumbs",
|
||||
default: undefined,
|
||||
},
|
||||
isDisabled: {
|
||||
type: Boolean,
|
||||
@@ -58,7 +61,10 @@ export default defineComponent({
|
||||
default: "ol",
|
||||
},
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
emits: { action: (_key: string | number) => true },
|
||||
setup(props, { attrs, slots, emit }) {
|
||||
const { locale } = useLocale();
|
||||
provide(breadcrumbsActionKey, (key) => emit("action", key));
|
||||
const variants = breadcrumbsVariants();
|
||||
// Merge with ancestor Fieldset/disabled scopes; never shadow parent true.
|
||||
const disabled = useInheritedDisabled(() => props.isDisabled);
|
||||
@@ -73,6 +79,7 @@ export default defineComponent({
|
||||
const isLast = ++index === total;
|
||||
return cloneVNode(node, {
|
||||
isLast,
|
||||
itemKey: node.props?.id ?? node.key ?? index - 1,
|
||||
separatorSlot: slots.separator,
|
||||
});
|
||||
});
|
||||
@@ -82,7 +89,7 @@ export default defineComponent({
|
||||
{
|
||||
...attrs,
|
||||
class: [variants.base(), attrs.class],
|
||||
"aria-label": props.ariaLabel || "Breadcrumbs",
|
||||
"aria-label": props.ariaLabel || breadcrumbsLabel(locale.value),
|
||||
"data-slot": "breadcrumbs",
|
||||
},
|
||||
children,
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
cloneVNode,
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
isVNode,
|
||||
useAttrs,
|
||||
type PropType,
|
||||
@@ -14,6 +15,7 @@ import {
|
||||
import { breadcrumbsVariants } from "@heroui-vue/styles";
|
||||
import { useInheritedDisabled } from "../field/disabled";
|
||||
import Link from "../link/Link.vue";
|
||||
import { breadcrumbsActionKey } from "./context";
|
||||
import BreadcrumbsSeparatorIcon from "./BreadcrumbsSeparatorIcon.vue";
|
||||
|
||||
function flattenChildren(
|
||||
@@ -57,6 +59,10 @@ export default defineComponent({
|
||||
name: "BreadcrumbsItem",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
id: {
|
||||
type: [String, Number] as PropType<string | number>,
|
||||
default: undefined,
|
||||
},
|
||||
href: {
|
||||
type: String,
|
||||
default: undefined,
|
||||
@@ -77,6 +83,11 @@ export default defineComponent({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
/** Identity supplied by the parent from id/key/index. */
|
||||
itemKey: {
|
||||
type: [String, Number] as PropType<string | number>,
|
||||
default: undefined,
|
||||
},
|
||||
/** Set by Breadcrumbs for the final item. */
|
||||
isLast: {
|
||||
type: Boolean,
|
||||
@@ -94,6 +105,7 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
setup(props, { attrs, slots }) {
|
||||
const action = inject(breadcrumbsActionKey, undefined);
|
||||
const variants = breadcrumbsVariants();
|
||||
const disabled = useInheritedDisabled(
|
||||
() => props.isDisabled || props.isLast,
|
||||
@@ -136,6 +148,19 @@ export default defineComponent({
|
||||
else rootAttrs[key] = value;
|
||||
}
|
||||
|
||||
const onClick = linkAttrs.onClick;
|
||||
linkAttrs.onClick = [
|
||||
...(Array.isArray(onClick) ? onClick : onClick ? [onClick] : []),
|
||||
(event: MouseEvent) => {
|
||||
if (
|
||||
!event.defaultPrevented &&
|
||||
!disabled.value &&
|
||||
props.itemKey !== undefined
|
||||
)
|
||||
action?.(props.itemKey);
|
||||
},
|
||||
];
|
||||
|
||||
const content =
|
||||
slots.default?.({
|
||||
isCurrent: current,
|
||||
@@ -172,6 +197,7 @@ export default defineComponent({
|
||||
props.as,
|
||||
{
|
||||
...rootAttrs,
|
||||
id: props.id == null ? undefined : String(props.id),
|
||||
class: [variants.item(), callerClass],
|
||||
"data-slot": "breadcrumbs-item",
|
||||
"data-current": current ? "true" : undefined,
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { InjectionKey } from "vue";
|
||||
export const breadcrumbsActionKey: InjectionKey<
|
||||
(key: string | number) => void
|
||||
> = Symbol("breadcrumbs-action");
|
||||
@@ -0,0 +1,55 @@
|
||||
// Breadcrumb labels from react-aria 3.52.1 (fixed upstream lockfile).
|
||||
// Copyright Adobe. Apache-2.0; see third-party/REACT-ARIA-LICENSE.
|
||||
const labels: Record<string, string> = {
|
||||
"ar-AE": "عناصر الواجهة",
|
||||
"bg-BG": "Трохи хляб",
|
||||
"cs-CZ": "Popis cesty",
|
||||
"da-DK": "Brødkrummer",
|
||||
"de-DE": "Breadcrumbs",
|
||||
"el-GR": "Πλοηγήσεις breadcrumb",
|
||||
"en-US": "Breadcrumbs",
|
||||
"es-ES": "Migas de pan",
|
||||
"et-EE": "Lingiread",
|
||||
"fi-FI": "Navigointilinkit",
|
||||
"fr-FR": "Chemin de navigation",
|
||||
"he-IL": "שבילי ניווט",
|
||||
"hr-HR": "Navigacijski putovi",
|
||||
"hu-HU": "Morzsamenü",
|
||||
"it-IT": "Breadcrumb",
|
||||
"ja-JP": "パンくずリスト",
|
||||
"ko-KR": "탐색 표시",
|
||||
"lt-LT": "Naršymo kelias",
|
||||
"lv-LV": "Atpakaļceļi",
|
||||
"nb-NO": "Navigasjonsstier",
|
||||
"nl-NL": "Broodkruimels",
|
||||
"pl-PL": "Struktura nawigacyjna",
|
||||
"pt-BR": "Caminho detalhado",
|
||||
"pt-PT": "Categorias",
|
||||
"ro-RO": "Miez de pâine",
|
||||
"ru-RU": "Навигация",
|
||||
"sk-SK": "Navigačné prvky Breadcrumbs",
|
||||
"sl-SI": "Drobtine",
|
||||
"sr-SP": "Putanje navigacije",
|
||||
"sv-SE": "Sökvägar",
|
||||
"tr-TR": "İçerik haritaları",
|
||||
"uk-UA": "Навігаційна стежка",
|
||||
"zh-CN": "导航栏",
|
||||
"zh-TW": "導覽列",
|
||||
};
|
||||
export function breadcrumbsLabel(locale: string): string {
|
||||
try {
|
||||
const requested = new Intl.Locale(locale);
|
||||
if (labels[requested.baseName]) return labels[requested.baseName]!;
|
||||
const expanded = requested.maximize();
|
||||
const candidates = Object.keys(labels).filter(
|
||||
(key) => new Intl.Locale(key).language === requested.language,
|
||||
);
|
||||
const key =
|
||||
candidates.find(
|
||||
(key) => new Intl.Locale(key).maximize().script === expanded.script,
|
||||
) ?? candidates[0];
|
||||
return labels[key ?? "en-US"]!;
|
||||
} catch {
|
||||
return labels["en-US"]!;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,397 @@
|
||||
/** Shared virtual geometry; collection selection and logical identity stay with their owners. */
|
||||
import {
|
||||
computed,
|
||||
shallowRef,
|
||||
toValue,
|
||||
nextTick,
|
||||
getCurrentScope,
|
||||
onScopeDispose,
|
||||
type ComputedRef,
|
||||
type MaybeRefOrGetter,
|
||||
} from "vue";
|
||||
import type { CollectionKey } from "./keys";
|
||||
|
||||
export type VirtualRowHeight = number | ((index: number) => number | undefined);
|
||||
export interface UseVirtualRowsOptions {
|
||||
count: MaybeRefOrGetter<number>;
|
||||
/** Stable typed identities for measured rows. Defaults to the row index. */
|
||||
keys?: MaybeRefOrGetter<readonly CollectionKey[]>;
|
||||
/** Undefined heights are estimated until measureRow observes the real row. */
|
||||
rowHeight: VirtualRowHeight;
|
||||
estimatedRowHeight?: number | ((index: number) => number);
|
||||
loaderHeight?: number;
|
||||
gap?: number;
|
||||
padding?: number;
|
||||
overscan?: number;
|
||||
}
|
||||
export interface VirtualRowWindow {
|
||||
start: number;
|
||||
end: number;
|
||||
padTop: number;
|
||||
padBottom: number;
|
||||
}
|
||||
export interface VirtualRowsBindingOptions {
|
||||
/** Element at the row stream origin (e.g. tbody below the table header). */
|
||||
content?: HTMLElement;
|
||||
/** Visible sticky chrome occluding the start of the viewport, in px. */
|
||||
scrollPaddingStart?: number | (() => number);
|
||||
}
|
||||
export interface UseVirtualRows {
|
||||
window: ComputedRef<VirtualRowWindow>;
|
||||
rowOffsetOf: (index: number) => number;
|
||||
rowExtentOf: (index: number) => number;
|
||||
totalHeight: ComputedRef<number>;
|
||||
update: (scrollTop: number, viewportHeight: number) => void;
|
||||
scrollToIndex: (element: HTMLElement, index: number) => void;
|
||||
/** Ref callback for naturally sized rows (accepts a DOM node or Vue component ref). */
|
||||
measureRow: (index: number, element: unknown) => void;
|
||||
/** Invalidate offscreen cached content sizes after caller-owned data changes. */
|
||||
resetMeasurements: () => void;
|
||||
}
|
||||
const positive = (value: number | undefined, fallback: number) =>
|
||||
value != null && Number.isFinite(value) && value > 0 ? value : fallback;
|
||||
const nonnegative = (value: number | undefined) =>
|
||||
value != null && Number.isFinite(value) ? Math.max(0, value) : 0;
|
||||
const binders = new WeakMap<
|
||||
UseVirtualRows,
|
||||
(element: HTMLElement, options: VirtualRowsBindingOptions) => () => void
|
||||
>();
|
||||
|
||||
export function useVirtualRows(options: UseVirtualRowsOptions): UseVirtualRows {
|
||||
const state = shallowRef({ scrollTop: 0, viewport: 0 });
|
||||
const sizes = shallowRef(new Map<CollectionKey, number>());
|
||||
const nodes = new Map<HTMLElement, CollectionKey>();
|
||||
const rowKeys = computed(() =>
|
||||
options.keys ? toValue(options.keys) : undefined,
|
||||
);
|
||||
const keyAt = (index: number) => rowKeys.value?.[index] ?? index;
|
||||
const rawHeight = (index: number) =>
|
||||
typeof options.rowHeight === "function"
|
||||
? options.rowHeight(index)
|
||||
: options.rowHeight;
|
||||
const estimate = (index: number) =>
|
||||
positive(
|
||||
typeof options.estimatedRowHeight === "function"
|
||||
? options.estimatedRowHeight(index)
|
||||
: options.estimatedRowHeight,
|
||||
48,
|
||||
);
|
||||
const geometry = computed(() => {
|
||||
const rawCount = toValue(options.count);
|
||||
const count = Number.isFinite(rawCount)
|
||||
? Math.max(0, Math.floor(rawCount))
|
||||
: 0;
|
||||
const gap = nonnegative(options.gap),
|
||||
pad = nonnegative(options.padding),
|
||||
loader = nonnegative(options.loaderHeight);
|
||||
const offsets = new Float64Array(count + 1);
|
||||
let top = pad;
|
||||
for (let i = 0; i < count; i++) {
|
||||
offsets[i] = top;
|
||||
const raw = rawHeight(i);
|
||||
top += positive(raw ?? sizes.value.get(keyAt(i)), estimate(i));
|
||||
if (i < count - 1) top += gap;
|
||||
}
|
||||
offsets[count] = top;
|
||||
return {
|
||||
count,
|
||||
offsets,
|
||||
pad,
|
||||
loaderSpan: loader > 0 ? loader + (count ? gap : 0) : 0,
|
||||
};
|
||||
});
|
||||
const rowOffsetOf = (index: number) =>
|
||||
geometry.value.offsets[
|
||||
Math.min(geometry.value.count, Math.max(0, Math.floor(index) || 0))
|
||||
]!;
|
||||
const rowExtentOf = (index: number) =>
|
||||
rowOffsetOf(index + 1) - rowOffsetOf(index);
|
||||
const totalHeight = computed(
|
||||
() =>
|
||||
rowOffsetOf(geometry.value.count) +
|
||||
geometry.value.loaderSpan +
|
||||
geometry.value.pad,
|
||||
);
|
||||
function firstAt(top: number) {
|
||||
const { count, offsets } = geometry.value;
|
||||
let lo = 0,
|
||||
hi = count;
|
||||
while (lo < hi) {
|
||||
const mid = (lo + hi) >> 1;
|
||||
if (offsets[mid + 1]! <= top) lo = mid + 1;
|
||||
else hi = mid;
|
||||
}
|
||||
return lo;
|
||||
}
|
||||
const window = computed(() => {
|
||||
const { count, offsets } = geometry.value;
|
||||
const overscan = Math.floor(nonnegative(options.overscan ?? 8));
|
||||
const start = Math.max(0, firstAt(state.value.scrollTop) - overscan);
|
||||
let lo = start,
|
||||
hi = count;
|
||||
const limit = state.value.scrollTop + state.value.viewport;
|
||||
while (lo < hi) {
|
||||
const mid = (lo + hi) >> 1;
|
||||
if (offsets[mid]! < limit) lo = mid + 1;
|
||||
else hi = mid;
|
||||
}
|
||||
// Keep an initial window while a hidden/unmeasured container mounts.
|
||||
const end = Math.min(
|
||||
count,
|
||||
Math.max(lo + overscan, start + (count ? 1 : 0)),
|
||||
);
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
padTop: rowOffsetOf(start),
|
||||
padBottom: Math.max(0, totalHeight.value - rowOffsetOf(end)),
|
||||
};
|
||||
});
|
||||
function update(scrollTop: number, viewportHeight: number) {
|
||||
const top = nonnegative(scrollTop),
|
||||
viewport = nonnegative(viewportHeight);
|
||||
if (state.value.scrollTop !== top || state.value.viewport !== viewport)
|
||||
state.value = { scrollTop: top, viewport };
|
||||
}
|
||||
let binding:
|
||||
| {
|
||||
element: HTMLElement;
|
||||
options: VirtualRowsBindingOptions;
|
||||
origin: () => number;
|
||||
inset: () => number;
|
||||
measure: () => void;
|
||||
}
|
||||
| undefined;
|
||||
let pendingTarget:
|
||||
| { element: HTMLElement; key: CollectionKey; scrollTop?: number }
|
||||
| undefined;
|
||||
function withAnchor(change: () => void) {
|
||||
const index = firstAt(state.value.scrollTop);
|
||||
const anchorKey = keyAt(index),
|
||||
before = rowOffsetOf(index);
|
||||
change();
|
||||
if (binding && index < geometry.value.count) {
|
||||
const keys = rowKeys.value;
|
||||
const nextIndex = keys ? keys.indexOf(anchorKey) : index;
|
||||
if (nextIndex >= 0) {
|
||||
const delta = rowOffsetOf(nextIndex) - before;
|
||||
if (delta) {
|
||||
binding.element.scrollTop += delta;
|
||||
if (pendingTarget?.element === binding.element)
|
||||
pendingTarget.scrollTop = binding.element.scrollTop;
|
||||
}
|
||||
}
|
||||
binding.measure();
|
||||
}
|
||||
}
|
||||
function resetMeasurements() {
|
||||
if (sizes.value.size)
|
||||
withAnchor(() => {
|
||||
sizes.value = new Map();
|
||||
});
|
||||
}
|
||||
function measureNodes() {
|
||||
const next = new Map(sizes.value);
|
||||
let changed = false;
|
||||
for (const [node, key] of nodes) {
|
||||
if (!node.isConnected) {
|
||||
observer?.unobserve(node);
|
||||
nodes.delete(node);
|
||||
continue;
|
||||
}
|
||||
const h = node.getBoundingClientRect().height;
|
||||
if (
|
||||
Number.isFinite(h) &&
|
||||
h > 0 &&
|
||||
Math.abs((next.get(key) ?? 0) - h) > 0.25
|
||||
) {
|
||||
next.set(key, h);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed)
|
||||
withAnchor(() => {
|
||||
sizes.value = next;
|
||||
});
|
||||
if (pendingTarget && next.has(pendingTarget.key)) {
|
||||
const target = pendingTarget;
|
||||
pendingTarget = undefined;
|
||||
const keys = rowKeys.value;
|
||||
const index = keys ? keys.indexOf(target.key) : Number(target.key);
|
||||
if (index >= 0) scrollToIndex(target.element, index);
|
||||
}
|
||||
}
|
||||
const observer =
|
||||
typeof ResizeObserver === "undefined"
|
||||
? undefined
|
||||
: new ResizeObserver(measureNodes);
|
||||
let queued = false;
|
||||
function queueMeasurement() {
|
||||
if (queued) return;
|
||||
queued = true;
|
||||
void nextTick(() => {
|
||||
queued = false;
|
||||
measureNodes();
|
||||
});
|
||||
}
|
||||
function measureRow(index: number, value: unknown) {
|
||||
const element =
|
||||
value instanceof HTMLElement
|
||||
? value
|
||||
: (value as { $el?: unknown } | null)?.$el;
|
||||
if (!(element instanceof HTMLElement) || rawHeight(index) !== undefined) {
|
||||
queueMeasurement();
|
||||
return;
|
||||
}
|
||||
const key = keyAt(index);
|
||||
if (nodes.get(element) !== key) {
|
||||
nodes.set(element, key);
|
||||
observer?.observe(element);
|
||||
}
|
||||
queueMeasurement();
|
||||
}
|
||||
function scrollToIndex(element: HTMLElement, requested: number) {
|
||||
if (!geometry.value.count) return;
|
||||
const index = Math.max(
|
||||
0,
|
||||
Math.min(geometry.value.count - 1, Math.floor(requested) || 0),
|
||||
);
|
||||
const b = binding?.element === element ? binding : undefined;
|
||||
if (rawHeight(index) === undefined && !sizes.value.has(keyAt(index)))
|
||||
pendingTarget = { element, key: keyAt(index) };
|
||||
const origin = b?.origin() ?? 0,
|
||||
inset = b?.inset() ?? 0;
|
||||
const top = origin + rowOffsetOf(index),
|
||||
extent = rowExtentOf(index);
|
||||
if (
|
||||
top < element.scrollTop + inset ||
|
||||
extent > element.clientHeight - inset
|
||||
)
|
||||
element.scrollTop = Math.max(0, top - inset);
|
||||
else if (top + extent > element.scrollTop + element.clientHeight)
|
||||
element.scrollTop = top + extent - element.clientHeight;
|
||||
if (pendingTarget?.element === element)
|
||||
pendingTarget.scrollTop = element.scrollTop;
|
||||
if (b) b.measure();
|
||||
else update(element.scrollTop, element.clientHeight);
|
||||
}
|
||||
const rows: UseVirtualRows = {
|
||||
window,
|
||||
rowOffsetOf,
|
||||
rowExtentOf,
|
||||
totalHeight,
|
||||
update,
|
||||
scrollToIndex,
|
||||
measureRow,
|
||||
resetMeasurements,
|
||||
};
|
||||
let disposeBinding: (() => void) | undefined;
|
||||
binders.set(rows, (element, config) => {
|
||||
disposeBinding?.();
|
||||
config = {
|
||||
...config,
|
||||
content:
|
||||
config.content ??
|
||||
element.querySelector<HTMLElement>(
|
||||
'[data-slot="table-content"] > tbody',
|
||||
) ??
|
||||
undefined,
|
||||
};
|
||||
const origin = () =>
|
||||
config.content
|
||||
? config.content.getBoundingClientRect().top -
|
||||
element.getBoundingClientRect().top -
|
||||
element.clientTop +
|
||||
element.scrollTop
|
||||
: 0;
|
||||
const inset = () =>
|
||||
nonnegative(
|
||||
typeof config.scrollPaddingStart === "function"
|
||||
? config.scrollPaddingStart()
|
||||
: config.scrollPaddingStart,
|
||||
);
|
||||
let width = element.clientWidth;
|
||||
const measure = () => {
|
||||
if (element.clientWidth !== width) {
|
||||
width = element.clientWidth;
|
||||
// Retain connected rows until their own ResizeObserver reports the
|
||||
// new natural size. Resetting them to estimates can toggle scrollbars
|
||||
// repeatedly when the whole collection is near the viewport height.
|
||||
const visible = new Set(
|
||||
[...nodes].filter(([node]) => node.isConnected).map(([, key]) => key),
|
||||
);
|
||||
withAnchor(() => {
|
||||
sizes.value = new Map(
|
||||
[...sizes.value].filter(([key]) => visible.has(key)),
|
||||
);
|
||||
});
|
||||
}
|
||||
update(
|
||||
Math.max(0, element.scrollTop + inset() - origin()),
|
||||
Math.max(0, element.clientHeight - inset()),
|
||||
);
|
||||
};
|
||||
binding = { element, options: config, origin, inset, measure };
|
||||
const previousAnchor = element.style.overflowAnchor;
|
||||
element.style.overflowAnchor = "none";
|
||||
const resize =
|
||||
typeof ResizeObserver === "undefined"
|
||||
? undefined
|
||||
: new ResizeObserver(measure);
|
||||
resize?.observe(element);
|
||||
if (config.content) {
|
||||
for (
|
||||
let node: HTMLElement | null = config.content;
|
||||
node && node !== element;
|
||||
node = node.parentElement
|
||||
) {
|
||||
resize?.observe(node);
|
||||
// Header/sticky chrome may move the stream without resizing it.
|
||||
for (
|
||||
let previous = node.previousElementSibling;
|
||||
previous;
|
||||
previous = previous.previousElementSibling
|
||||
)
|
||||
resize?.observe(previous);
|
||||
}
|
||||
}
|
||||
const onScroll = () => {
|
||||
if (
|
||||
pendingTarget?.element === element &&
|
||||
pendingTarget.scrollTop != null &&
|
||||
Math.abs(pendingTarget.scrollTop - element.scrollTop) > 1
|
||||
)
|
||||
pendingTarget = undefined;
|
||||
measure();
|
||||
};
|
||||
element.addEventListener("scroll", onScroll, { passive: true });
|
||||
let live = true;
|
||||
const dispose = () => {
|
||||
if (!live) return;
|
||||
live = false;
|
||||
resize?.disconnect();
|
||||
element.removeEventListener("scroll", onScroll);
|
||||
element.style.overflowAnchor = previousAnchor;
|
||||
if (binding?.element === element) binding = undefined;
|
||||
};
|
||||
disposeBinding = dispose;
|
||||
measure();
|
||||
return dispose;
|
||||
});
|
||||
if (getCurrentScope())
|
||||
onScopeDispose(() => {
|
||||
observer?.disconnect();
|
||||
nodes.clear();
|
||||
disposeBinding?.();
|
||||
});
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** Bind a real scroll viewport and the row stream's actual origin. */
|
||||
export function bindVirtualRows(
|
||||
rows: UseVirtualRows,
|
||||
element: HTMLElement,
|
||||
options: VirtualRowsBindingOptions = {},
|
||||
): () => void {
|
||||
return binders.get(rows)!(element, options);
|
||||
}
|
||||
@@ -58,6 +58,7 @@ export default defineComponent({
|
||||
inputValue: string;
|
||||
selectedKey: CollectionKey | null;
|
||||
selectedKeys: CollectionKey[];
|
||||
selectedItem: ComboBoxItem | null;
|
||||
}) => VNodeChild;
|
||||
}>,
|
||||
props: {
|
||||
@@ -653,6 +654,7 @@ export default defineComponent({
|
||||
textValue:
|
||||
records.value.find((record) => record.key === key)?.text ??
|
||||
String(key),
|
||||
item: props.items?.find((entry) => entry.id === key),
|
||||
})),
|
||||
),
|
||||
selectionMode: computed(() => props.selectionMode),
|
||||
@@ -792,6 +794,10 @@ export default defineComponent({
|
||||
? null
|
||||
: (value.value as CollectionKey | null),
|
||||
selectedKeys: [...keys.value],
|
||||
selectedItem:
|
||||
(!Array.isArray(value.value) && value.value != null
|
||||
? (props.items?.find((entry) => entry.id === value.value) ?? null)
|
||||
: null) ?? null,
|
||||
});
|
||||
const children = Array.isArray(rendered)
|
||||
? rendered
|
||||
|
||||
@@ -17,6 +17,12 @@ export interface ComboBoxState {
|
||||
inputValue: string;
|
||||
selectedKey: CollectionKey | null;
|
||||
selectedKeys: CollectionKey[];
|
||||
/**
|
||||
* Source entry from the root `items` matching the single selected key
|
||||
* (null in multiple mode or for custom/discovered values). Lets callers
|
||||
* compose rich value displays from their own data without re-mapping keys.
|
||||
*/
|
||||
selectedItem: ComboBoxItem | null;
|
||||
}
|
||||
/** Scoped-slot state of `ComboBoxValue`. */
|
||||
export interface ComboBoxValueState {
|
||||
@@ -26,6 +32,8 @@ export interface ComboBoxValueState {
|
||||
export interface ComboBoxSelectedItem {
|
||||
key: CollectionKey;
|
||||
textValue: string;
|
||||
/** Source entry from the root `items` (absent for collection-discovered items). */
|
||||
item?: ComboBoxItem;
|
||||
}
|
||||
/** Props shared by the SFC and the context; keep one schema. */
|
||||
export interface ComboBoxOptions {
|
||||
|
||||
@@ -77,7 +77,11 @@ watch(
|
||||
:data-open="popover.state.isOpen.value || undefined"
|
||||
:data-disabled="disabled || undefined"
|
||||
:data-focus-visible="focusVisible || undefined"
|
||||
@focus="focusVisible = true"
|
||||
@focus="
|
||||
focusVisible = ($event.currentTarget as HTMLElement).matches(
|
||||
':focus-visible',
|
||||
)
|
||||
"
|
||||
@blur="focusVisible = false"
|
||||
>
|
||||
<slot />
|
||||
|
||||
@@ -77,7 +77,11 @@ watch(
|
||||
:data-open="popover.state.isOpen.value || undefined"
|
||||
:data-disabled="disabled || undefined"
|
||||
:data-focus-visible="focusVisible || undefined"
|
||||
@focus="focusVisible = true"
|
||||
@focus="
|
||||
focusVisible = ($event.currentTarget as HTMLElement).matches(
|
||||
':focus-visible',
|
||||
)
|
||||
"
|
||||
@blur="focusVisible = false"
|
||||
>
|
||||
<slot />
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
<script setup lang="ts">
|
||||
import { useAttrs } from "vue";
|
||||
import { descriptionVariants } from "@heroui-vue/styles";
|
||||
import { useFieldPart } from "../field/useFieldPart";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const attrs = useAttrs();
|
||||
const { id } = useFieldPart("description", attrs);
|
||||
</script>
|
||||
<template>
|
||||
<p v-bind="attrs" :id="id" class="hv-description" data-slot="description">
|
||||
<p
|
||||
v-bind="attrs"
|
||||
:id="id"
|
||||
:class="descriptionVariants()"
|
||||
data-slot="description"
|
||||
>
|
||||
<slot />
|
||||
</p>
|
||||
</template>
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
inject,
|
||||
isVNode,
|
||||
nextTick,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
provide,
|
||||
ref,
|
||||
@@ -31,8 +32,6 @@ import {
|
||||
submenuOpenKey,
|
||||
} from "../menu/context";
|
||||
import { useOverlayAnimation } from "../overlay/animation";
|
||||
import { resolvePlacement, type OverlayPlacement } from "../overlay/placement";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import { elementFromValue, menuSurfaceFromVNode } from "./dom";
|
||||
import DropdownPopover from "./DropdownPopover.vue";
|
||||
|
||||
@@ -104,16 +103,83 @@ function inheritedProps(props: Record<string, unknown> | null) {
|
||||
export default defineComponent({
|
||||
name: "DropdownSubmenuTrigger",
|
||||
inheritAttrs: false,
|
||||
setup(_, { slots }) {
|
||||
props: {
|
||||
/**
|
||||
* Hover-to-open delay in ms (the pinned useSubmenuTrigger contract).
|
||||
* Keyboard and programmatic opens stay immediate and cancel the pending
|
||||
* hover open, matching the baseline.
|
||||
*/
|
||||
delay: { type: Number, default: 200 },
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const dropdownCtx = inject(dropdownContextKey, null);
|
||||
const config = useConfig();
|
||||
provide(submenuContentKey, true);
|
||||
|
||||
const subOpen = ref(false);
|
||||
const triggerRef = ref<unknown>(null);
|
||||
const contentElement = ref<HTMLElement | null>(null);
|
||||
const fallbackId = useId();
|
||||
/**
|
||||
* Reka's MenuSubTrigger opens submenus after a fixed 100ms hover, while the
|
||||
* pinned source waits `delay` (200ms by default). The controlled open gate
|
||||
* below defers hover-driven opens to the configured delay: our own timer
|
||||
* owns the hover open, early hover requests are swallowed, and keyboard
|
||||
* opens (which arrive during a keydown) cancel the pending timer and open
|
||||
* at once like the baseline.
|
||||
*/
|
||||
const hoverOpenTimer = ref<ReturnType<typeof setTimeout> | null>(null);
|
||||
let activationEvent: Event | undefined;
|
||||
function triggerDisabled() {
|
||||
const element = elementFromValue(triggerRef.value);
|
||||
return (
|
||||
element?.getAttribute("aria-disabled") === "true" ||
|
||||
element?.hasAttribute("data-disabled") === true
|
||||
);
|
||||
}
|
||||
function clearHoverOpen() {
|
||||
if (hoverOpenTimer.value) {
|
||||
clearTimeout(hoverOpenTimer.value);
|
||||
hoverOpenTimer.value = null;
|
||||
}
|
||||
}
|
||||
function scheduleHoverOpen() {
|
||||
if (hoverOpenTimer.value || subOpen.value || triggerDisabled()) return;
|
||||
if (!(props.delay > 0)) {
|
||||
subOpen.value = true;
|
||||
return;
|
||||
}
|
||||
hoverOpenTimer.value = setTimeout(() => {
|
||||
hoverOpenTimer.value = null;
|
||||
if (!triggerDisabled() && dropdownCtx?.open.value !== false)
|
||||
subOpen.value = true;
|
||||
}, props.delay);
|
||||
}
|
||||
function itemPointerMove(event: Event) {
|
||||
if ((event as MouseEvent).defaultPrevented) return;
|
||||
// Same gate as Reka's SubTrigger: only mouse hover starts the open.
|
||||
if ((event as PointerEvent).pointerType !== "mouse") return;
|
||||
scheduleHoverOpen();
|
||||
}
|
||||
function itemPointerLeave() {
|
||||
clearHoverOpen();
|
||||
}
|
||||
function activationCapture(event: Event) {
|
||||
activationEvent = event;
|
||||
queueMicrotask(() => {
|
||||
if (activationEvent === event) activationEvent = undefined;
|
||||
});
|
||||
}
|
||||
onBeforeUnmount(clearHoverOpen);
|
||||
watch(
|
||||
() => dropdownCtx?.open.value,
|
||||
(open) => {
|
||||
if (open === false) {
|
||||
clearHoverOpen();
|
||||
subOpen.value = false;
|
||||
}
|
||||
},
|
||||
);
|
||||
const contentAttrs = {
|
||||
label: ref<string | undefined>(),
|
||||
labelledBy: ref<string | undefined>(),
|
||||
@@ -224,9 +290,6 @@ export default defineComponent({
|
||||
if (!CONTROL_PROPS.has(key)) domProps[key] = value;
|
||||
}
|
||||
|
||||
const placement = (popoverProps.placement as OverlayPlacement) ?? "end";
|
||||
const position = resolvePlacement(placement, config?.dir.value ?? "ltr");
|
||||
|
||||
panelConfig.dismissDisabled =
|
||||
(popoverProps.isKeyboardDismissDisabled as boolean | undefined) ??
|
||||
false;
|
||||
@@ -234,8 +297,10 @@ export default defineComponent({
|
||||
popoverProps.shouldCloseOnInteractOutside as
|
||||
((event: Event) => boolean) | undefined;
|
||||
|
||||
// Reka fixes the submenu side/align to the parent convention, so only
|
||||
// the offsets/collision props can be forwarded.
|
||||
// Reka's MenuSubContent fixes the submenu side/align to the parent
|
||||
// convention (right in LTR, left in RTL) and only accepts the offsets /
|
||||
// collision props here: forwarded side/align attrs never reach the
|
||||
// popper placement (the template binding wins), so they are not passed.
|
||||
const panelProps: Record<string, unknown> = {
|
||||
sideOffset:
|
||||
(popoverProps.sideOffset as number | undefined) ??
|
||||
@@ -256,9 +321,6 @@ export default defineComponent({
|
||||
contentAttrs.loop.value ??
|
||||
false,
|
||||
};
|
||||
const side = (popoverProps.side as string | undefined) ?? position.side;
|
||||
const align =
|
||||
(popoverProps.align as string | undefined) ?? position.align;
|
||||
|
||||
const keydownChain = [
|
||||
...asArray(popoverProps.onKeydown as Handler),
|
||||
@@ -309,6 +371,34 @@ export default defineComponent({
|
||||
{
|
||||
open: subOpen.value,
|
||||
"onUpdate:open": (value: boolean) => {
|
||||
if (value) {
|
||||
if (triggerDisabled()) {
|
||||
clearHoverOpen();
|
||||
return;
|
||||
}
|
||||
const click = activationEvent;
|
||||
if (click?.type === "click") {
|
||||
// asChild's primitive can request open before the item's
|
||||
// bubble handlers. Let the complete click chain cancel it.
|
||||
queueMicrotask(() => {
|
||||
if (
|
||||
click.defaultPrevented ||
|
||||
triggerDisabled() ||
|
||||
dropdownCtx?.open.value === false
|
||||
)
|
||||
return;
|
||||
clearHoverOpen();
|
||||
subOpen.value = true;
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Reka's fixed 100ms hover timer requests the open before the
|
||||
// configured delay; the delay owns that open instead. Keyboard
|
||||
// opens arrive during a keydown and pass through at once,
|
||||
// cancelling the pending hover open like the baseline.
|
||||
if (hoverOpenTimer.value && !activationEvent) return;
|
||||
clearHoverOpen();
|
||||
} else clearHoverOpen();
|
||||
subOpen.value = value;
|
||||
},
|
||||
},
|
||||
@@ -333,6 +423,17 @@ export default defineComponent({
|
||||
// Escape with focus on the trigger (pointer-opened
|
||||
// submenu) must also close only this level.
|
||||
onKeydown: handleEscape,
|
||||
onKeydownCapture: [
|
||||
...asArray(attrs.onKeydownCapture as Handler),
|
||||
activationCapture,
|
||||
],
|
||||
onClickCapture: [
|
||||
...asArray(attrs.onClickCapture as Handler),
|
||||
activationCapture,
|
||||
],
|
||||
// Hover intent drives the configured open delay.
|
||||
onPointermove: itemPointerMove,
|
||||
onPointerleave: itemPointerLeave,
|
||||
})
|
||||
: null,
|
||||
},
|
||||
@@ -347,8 +448,6 @@ export default defineComponent({
|
||||
{
|
||||
...domProps,
|
||||
...panelProps,
|
||||
side,
|
||||
align,
|
||||
...ariaProps,
|
||||
class: [
|
||||
dropdownCtx?.slots.value.popover(),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { useAttrs } from "vue";
|
||||
import { fieldErrorVariants } from "@heroui-vue/styles";
|
||||
import { useFieldPart } from "./useFieldPart";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const attrs = useAttrs();
|
||||
@@ -12,12 +13,13 @@ const { field, id } = useFieldPart("error", attrs);
|
||||
:id="id"
|
||||
data-slot="field-error"
|
||||
data-visible
|
||||
class="hv-field-error"
|
||||
:class="fieldErrorVariants()"
|
||||
role="alert"
|
||||
>
|
||||
<slot
|
||||
:validation-errors="field?.errors.value ?? []"
|
||||
:is-invalid="field?.invalid.value ?? false"
|
||||
:validation-details="field?.validationDetails?.value"
|
||||
>
|
||||
{{ field?.errors.value.join(" ") }}
|
||||
</slot>
|
||||
|
||||
@@ -12,6 +12,7 @@ export interface FieldContext {
|
||||
required: ComputedRef<boolean>;
|
||||
invalid: ComputedRef<boolean>;
|
||||
errors: ComputedRef<string[]>;
|
||||
validationDetails?: ComputedRef<ValidityState | undefined>;
|
||||
labelIds?: Ref<string[]>;
|
||||
descriptionIds: Ref<string[]>;
|
||||
errorIds: Ref<string[]>;
|
||||
|
||||
@@ -12,12 +12,16 @@ import {
|
||||
shallowRef,
|
||||
useId,
|
||||
watchEffect,
|
||||
onMounted,
|
||||
nextTick,
|
||||
type PropType,
|
||||
type ExtractPropTypes,
|
||||
type Slots,
|
||||
type VNode,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { validitySnapshot } from "./validation";
|
||||
import { textFieldVariants } from "@heroui-vue/styles";
|
||||
import {
|
||||
fieldContextKey,
|
||||
formContextKey,
|
||||
@@ -33,6 +37,18 @@ import {
|
||||
|
||||
import { useInheritedDisabled } from "./disabled";
|
||||
|
||||
export interface TextFieldRenderProps {
|
||||
value: string;
|
||||
isDisabled: boolean;
|
||||
isReadOnly: boolean;
|
||||
isRequired: boolean;
|
||||
isInvalid: boolean;
|
||||
isFocusWithin: boolean;
|
||||
isFocusVisible: boolean;
|
||||
validationErrors: string[];
|
||||
validationDetails: ValidityState;
|
||||
}
|
||||
|
||||
export const textFieldProps = {
|
||||
modelValue: String,
|
||||
defaultValue: String,
|
||||
@@ -49,6 +65,8 @@ export const textFieldProps = {
|
||||
isReadOnly: Boolean,
|
||||
isRequired: Boolean,
|
||||
isInvalid: Boolean,
|
||||
autoFocus: Boolean,
|
||||
validationErrors: [String, Array] as PropType<string | string[]>,
|
||||
fullWidth: Boolean,
|
||||
variant: String as PropType<"primary" | "secondary">,
|
||||
validationBehavior: String as PropType<ValidationBehavior>,
|
||||
@@ -88,6 +106,10 @@ export function useTextField(
|
||||
const touched = ref(false),
|
||||
nativeError = ref("");
|
||||
const dismissed = shallowRef<object>();
|
||||
const dismissedLocal = shallowRef<string | string[]>();
|
||||
const focused = ref(false),
|
||||
focusVisible = ref(false);
|
||||
const details = shallowRef<ValidityState>(validitySnapshot());
|
||||
const descriptionIds = ref<string[]>([]),
|
||||
errorIds = ref<string[]>([]);
|
||||
// Pre-plan direct/native-wrapped parts before rendering controls, so SSR has
|
||||
@@ -108,11 +130,19 @@ export function useTextField(
|
||||
? errorMessages(source[props.name])
|
||||
: [];
|
||||
});
|
||||
const localErrors = computed(() =>
|
||||
props.validationErrors !== dismissedLocal.value
|
||||
? errorMessages(props.validationErrors)
|
||||
: [],
|
||||
);
|
||||
const externalErrors = computed(() => [
|
||||
...new Set([...localErrors.value, ...serverErrors.value]),
|
||||
]);
|
||||
const customErrors = computed(() =>
|
||||
errorMessages(props.validate?.(value.value)),
|
||||
);
|
||||
const errors = computed(() => [
|
||||
...serverErrors.value,
|
||||
...externalErrors.value,
|
||||
...(touched.value || behavior.value === "aria" ? customErrors.value : []),
|
||||
...((touched.value || behavior.value === "aria") && nativeError.value
|
||||
? [nativeError.value]
|
||||
@@ -127,8 +157,11 @@ export function useTextField(
|
||||
);
|
||||
function setValue(next: string) {
|
||||
if (disabled.value || readOnly.value) return;
|
||||
if (next !== value.value) {
|
||||
dismissed.value = form?.validationErrors.value;
|
||||
dismissedLocal.value = props.validationErrors;
|
||||
}
|
||||
internal.value = next;
|
||||
dismissed.value = form?.validationErrors.value;
|
||||
nativeError.value = "";
|
||||
emit("update:modelValue", next);
|
||||
}
|
||||
@@ -147,6 +180,7 @@ export function useTextField(
|
||||
required,
|
||||
invalid,
|
||||
errors,
|
||||
validationDetails: computed(() => details.value),
|
||||
descriptionIds,
|
||||
errorIds,
|
||||
value,
|
||||
@@ -188,7 +222,7 @@ export function useTextField(
|
||||
touched.value = true;
|
||||
const element = event.target as HTMLInputElement | HTMLTextAreaElement;
|
||||
nativeError.value =
|
||||
customErrors.value.length || serverErrors.value.length
|
||||
customErrors.value.length || externalErrors.value.length
|
||||
? ""
|
||||
: element.validationMessage;
|
||||
},
|
||||
@@ -197,6 +231,7 @@ export function useTextField(
|
||||
touched.value = false;
|
||||
nativeError.value = "";
|
||||
dismissed.value = form?.validationErrors.value;
|
||||
dismissedLocal.value = props.validationErrors;
|
||||
},
|
||||
};
|
||||
provide(fieldContextKey, field);
|
||||
@@ -204,16 +239,28 @@ export function useTextField(
|
||||
watchEffect(
|
||||
() => {
|
||||
const currentValue = value.value;
|
||||
// Native constraints are patched by the leaf before this post effect.
|
||||
// Track root props even when the value itself has not changed.
|
||||
void [
|
||||
props.type,
|
||||
props.minLength,
|
||||
props.maxLength,
|
||||
props.pattern,
|
||||
required.value,
|
||||
];
|
||||
control.value?.setCustomValidity(
|
||||
behavior.value === "native" && !disabled.value && !readOnly.value
|
||||
? [...serverErrors.value, ...customErrors.value].join(" ")
|
||||
? [...externalErrors.value, ...customErrors.value].join(" ")
|
||||
: "",
|
||||
);
|
||||
if (behavior.value === "native" && touched.value)
|
||||
nativeError.value =
|
||||
customErrors.value.length || serverErrors.value.length
|
||||
customErrors.value.length || externalErrors.value.length
|
||||
? ""
|
||||
: (control.value?.validationMessage ?? "");
|
||||
const snapshot = validitySnapshot(control.value?.validity);
|
||||
if (JSON.stringify(snapshot) !== JSON.stringify(details.value))
|
||||
details.value = snapshot;
|
||||
if (behavior.value === "aria")
|
||||
nativeError.value =
|
||||
disabled.value || readOnly.value
|
||||
@@ -224,9 +271,30 @@ export function useTextField(
|
||||
},
|
||||
{ flush: "post" },
|
||||
);
|
||||
onMounted(() => {
|
||||
void nextTick(() => {
|
||||
if (props.autoFocus && !disabled.value) control.value?.focus();
|
||||
});
|
||||
});
|
||||
function focusIn(event: FocusEvent) {
|
||||
focused.value = true;
|
||||
focusVisible.value = (event.target as HTMLElement).matches(
|
||||
":focus-visible",
|
||||
);
|
||||
}
|
||||
function focusOut(event: FocusEvent) {
|
||||
if (
|
||||
!(event.currentTarget as HTMLElement).contains(
|
||||
event.relatedTarget as Node | null,
|
||||
)
|
||||
) {
|
||||
focused.value = false;
|
||||
focusVisible.value = false;
|
||||
}
|
||||
}
|
||||
expose({ focus: () => control.value?.focus(), element: control });
|
||||
function prepare(
|
||||
nodes: VNodeChild[],
|
||||
nodes: VNodeChild,
|
||||
found: {
|
||||
description: string[];
|
||||
error: string[];
|
||||
@@ -236,7 +304,7 @@ export function useTextField(
|
||||
},
|
||||
path = "",
|
||||
): VNodeChild[] {
|
||||
return nodes.map((node, index) => {
|
||||
return (Array.isArray(nodes) ? nodes : [nodes]).map((node, index) => {
|
||||
if (!isVNode(node) || node.type === Comment) return node;
|
||||
const position = `${path}-${index}`;
|
||||
const type = node.type as { name?: string; __name?: string };
|
||||
@@ -266,7 +334,7 @@ export function useTextField(
|
||||
node.children &&
|
||||
typeof node.children === "object"
|
||||
) {
|
||||
const groupSlots = node.children as { default?: () => VNodeChild[] };
|
||||
const groupSlots = node.children as { default?: () => VNodeChild };
|
||||
if (typeof groupSlots.default === "function") {
|
||||
const prepared = prepare(groupSlots.default(), found, position);
|
||||
const clone = cloneVNode(node);
|
||||
@@ -304,6 +372,10 @@ export function useTextField(
|
||||
isRequired: required.value,
|
||||
isInvalid: invalid.value,
|
||||
validationErrors: errors.value,
|
||||
validationDetails: details.value,
|
||||
value: value.value,
|
||||
isFocusWithin: focused.value,
|
||||
isFocusVisible: focusVisible.value,
|
||||
...options.slotState?.(),
|
||||
}) ?? [],
|
||||
found,
|
||||
@@ -325,12 +397,14 @@ export function useTextField(
|
||||
Object.entries(attrs).filter(([key]) => !key.startsWith("aria-")),
|
||||
),
|
||||
class: [
|
||||
options.rootClass?.() ?? [
|
||||
"hv-textfield",
|
||||
props.fullWidth && "hv-textfield--full-width",
|
||||
],
|
||||
options.rootClass?.() ??
|
||||
textFieldVariants({ fullWidth: props.fullWidth }),
|
||||
attrs.class,
|
||||
],
|
||||
onFocusin: focusIn,
|
||||
onFocusout: focusOut,
|
||||
"data-focus-within": focused.value || undefined,
|
||||
"data-focus-visible": focusVisible.value || undefined,
|
||||
"data-slot": options.rootSlot ?? "textfield",
|
||||
"data-invalid": invalid.value || undefined,
|
||||
"data-disabled": disabled.value || undefined,
|
||||
@@ -342,5 +416,5 @@ export function useTextField(
|
||||
children,
|
||||
);
|
||||
};
|
||||
return { field, element: control, render };
|
||||
return { field, element: control, render, focused, focusVisible };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/** Snapshot native readonly validity flags without retaining a live DOM object. */
|
||||
export function validitySnapshot(value?: ValidityState): ValidityState {
|
||||
return {
|
||||
badInput: value?.badInput ?? false,
|
||||
customError: value?.customError ?? false,
|
||||
patternMismatch: value?.patternMismatch ?? false,
|
||||
rangeOverflow: value?.rangeOverflow ?? false,
|
||||
rangeUnderflow: value?.rangeUnderflow ?? false,
|
||||
stepMismatch: value?.stepMismatch ?? false,
|
||||
tooLong: value?.tooLong ?? false,
|
||||
tooShort: value?.tooShort ?? false,
|
||||
typeMismatch: value?.typeMismatch ?? false,
|
||||
valid: value?.valid ?? true,
|
||||
valueMissing: value?.valueMissing ?? false,
|
||||
};
|
||||
}
|
||||
@@ -17,10 +17,12 @@ import {
|
||||
useAttrs,
|
||||
useId,
|
||||
watch,
|
||||
watchEffect,
|
||||
type PropType,
|
||||
type VNode,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { validitySnapshot } from "../field/validation";
|
||||
import { PinInputRoot } from "reka-ui";
|
||||
import { inputOTPVariants, type InputOTPVariants } from "@heroui-vue/styles";
|
||||
import { useInheritedDisabled } from "../field/disabled";
|
||||
@@ -43,11 +45,11 @@ function attrBoolean(value: unknown): boolean {
|
||||
return value != null && value !== false;
|
||||
}
|
||||
|
||||
/** Match one character without leaking lastIndex on global/sticky regexes. */
|
||||
function charAllowed(re: RegExp, char: string): boolean {
|
||||
if (!char) return true;
|
||||
/** Test the whole candidate without leaking lastIndex on global/sticky regexes. */
|
||||
function valueAllowed(re: RegExp, value: string): boolean {
|
||||
if (!value) return true;
|
||||
const flags = re.flags.replace(/[gy]/g, "");
|
||||
return new RegExp(re.source, flags).test(char);
|
||||
return new RegExp(re.source, flags).test(value);
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
@@ -83,6 +85,13 @@ export default defineComponent({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
autoFocus: Boolean,
|
||||
pasteTransformer: Function as PropType<(pastedText: string) => string>,
|
||||
textAlign: {
|
||||
type: String as PropType<"left" | "center" | "right">,
|
||||
default: "left",
|
||||
},
|
||||
validationDetails: Object as PropType<ValidityState>,
|
||||
validationErrors: {
|
||||
type: Array as PropType<string[]>,
|
||||
default: undefined,
|
||||
@@ -113,7 +122,7 @@ export default defineComponent({
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
/** Character filter, e.g. REGEXP_ONLY_DIGITS. */
|
||||
/** Whole-value predicate, e.g. REGEXP_ONLY_DIGITS. */
|
||||
pattern: {
|
||||
type: [String, RegExp] as PropType<string | RegExp>,
|
||||
default: undefined,
|
||||
@@ -179,19 +188,23 @@ export default defineComponent({
|
||||
: EMPTY_ERRORS;
|
||||
});
|
||||
|
||||
const nativeError = ref("");
|
||||
const invalid = computed(
|
||||
() =>
|
||||
props.isInvalid ||
|
||||
(props.validationErrors?.length ?? 0) > 0 ||
|
||||
serverErrors.value.length > 0 ||
|
||||
Boolean(nativeError.value) ||
|
||||
attrs["aria-invalid"] === true ||
|
||||
attrs["aria-invalid"] === "true",
|
||||
);
|
||||
const errors = computed(() => [
|
||||
...(props.validationErrors ?? EMPTY_ERRORS),
|
||||
...serverErrors.value,
|
||||
...(nativeError.value ? [nativeError.value] : []),
|
||||
]);
|
||||
|
||||
const nativeDetails = shallowRef<ValidityState>(validitySnapshot());
|
||||
const resolvedId = computed(() => props.id ?? autoId);
|
||||
/** Stable id per real focusable input; Label `for` uses index 0. */
|
||||
function inputId(index: number): string {
|
||||
@@ -206,6 +219,9 @@ export default defineComponent({
|
||||
required: computed(() => props.required),
|
||||
invalid,
|
||||
errors,
|
||||
validationDetails: computed(
|
||||
() => props.validationDetails ?? nativeDetails.value,
|
||||
),
|
||||
labelIds,
|
||||
descriptionIds,
|
||||
errorIds,
|
||||
@@ -261,18 +277,25 @@ export default defineComponent({
|
||||
const raw = next[i];
|
||||
return raw == null ? "" : String(raw);
|
||||
});
|
||||
const proposed = stringFromChars(clamped);
|
||||
const re = pattern.value;
|
||||
if (re) {
|
||||
for (let i = 0; i < clamped.length; i++) {
|
||||
const char = clamped[i];
|
||||
if (char && !charAllowed(re, char)) clamped[i] = "";
|
||||
}
|
||||
if (re && !valueAllowed(re, proposed)) {
|
||||
// Force the primitive and native inputs back to the accepted slots.
|
||||
const accepted = [...slotChars.value];
|
||||
void nextTick(() => {
|
||||
slotChars.value = accepted;
|
||||
rootEl.value
|
||||
?.querySelectorAll<HTMLInputElement>(
|
||||
'input[data-slot="input-otp-input"]',
|
||||
)
|
||||
.forEach((input, index) => {
|
||||
input.value = accepted[index] ?? "";
|
||||
});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
const previous = stringFromChars(slotChars.value);
|
||||
const prevFilled = slotChars.value.filter(Boolean).length;
|
||||
const nextFilled = clamped.filter(Boolean).length;
|
||||
slotChars.value = clamped;
|
||||
const proposed = stringFromChars(clamped);
|
||||
const currentPublic = isControlled.value
|
||||
? (props.modelValue ?? "")
|
||||
: previous;
|
||||
@@ -282,6 +305,7 @@ export default defineComponent({
|
||||
lastEmitted = proposed;
|
||||
// Effective edit dismisses the current server-error response.
|
||||
dismissed.value = form?.validationErrors.value;
|
||||
nativeError.value = "";
|
||||
emit("update:modelValue", proposed);
|
||||
emit("change", proposed);
|
||||
void nextTick(() => {
|
||||
@@ -294,15 +318,27 @@ export default defineComponent({
|
||||
}
|
||||
});
|
||||
}
|
||||
if (
|
||||
prevFilled < length.value &&
|
||||
nextFilled === length.value &&
|
||||
length.value > 0
|
||||
) {
|
||||
emit("complete", proposed);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Completion follows the accepted public value, never a rejected proposal.
|
||||
watch(
|
||||
() =>
|
||||
isControlled.value
|
||||
? (props.modelValue ?? "")
|
||||
: stringFromChars(slotChars.value),
|
||||
(next, previous) => {
|
||||
if (
|
||||
next !== previous &&
|
||||
previous.length < length.value &&
|
||||
next.length === length.value &&
|
||||
length.value > 0
|
||||
)
|
||||
emit("complete", next);
|
||||
},
|
||||
{ flush: "post" },
|
||||
);
|
||||
|
||||
function handlePinUpdate(value: unknown) {
|
||||
applyChars(Array.isArray(value) ? value : []);
|
||||
}
|
||||
@@ -327,6 +363,7 @@ export default defineComponent({
|
||||
slotChars.value = charsFromString(incoming, length.value);
|
||||
}
|
||||
dismissed.value = form?.validationErrors.value;
|
||||
nativeError.value = "";
|
||||
});
|
||||
}
|
||||
|
||||
@@ -349,7 +386,46 @@ export default defineComponent({
|
||||
formEl = next;
|
||||
formEl?.addEventListener("reset", reset);
|
||||
}
|
||||
onMounted(bindForm);
|
||||
onMounted(() => {
|
||||
bindForm();
|
||||
void nextTick(() => {
|
||||
if (props.autoFocus && !disabled.value)
|
||||
rootEl.value
|
||||
?.querySelector<HTMLInputElement>(
|
||||
'input[data-slot="input-otp-input"]:not(:disabled)',
|
||||
)
|
||||
?.focus();
|
||||
});
|
||||
});
|
||||
watchEffect(
|
||||
() => {
|
||||
// Shared FieldContext exposes the real validation proxy, with optional
|
||||
// caller-supplied ValidityState taking precedence for FieldError slots.
|
||||
const proxy = rootEl.value?.querySelector<HTMLInputElement>(
|
||||
'input[aria-hidden="true"]',
|
||||
);
|
||||
if (!proxy) return;
|
||||
const source = pattern.value?.source;
|
||||
if (source) proxy.setAttribute("pattern", source);
|
||||
else proxy.removeAttribute("pattern");
|
||||
proxy.readOnly = readOnly.value;
|
||||
if (disabled.value || readOnly.value) nativeError.value = "";
|
||||
proxy.setCustomValidity(
|
||||
disabled.value || readOnly.value
|
||||
? ""
|
||||
: [...(props.validationErrors ?? []), ...serverErrors.value].join(
|
||||
" ",
|
||||
),
|
||||
);
|
||||
// Track primitive value updates so native validity is read after DOM patch.
|
||||
chars.value;
|
||||
props.required;
|
||||
const snapshot = validitySnapshot(proxy.validity);
|
||||
if (JSON.stringify(snapshot) !== JSON.stringify(nativeDetails.value))
|
||||
nativeDetails.value = snapshot;
|
||||
},
|
||||
{ flush: "post" },
|
||||
);
|
||||
onUpdated(bindForm);
|
||||
onBeforeUnmount(() => {
|
||||
formEl?.removeEventListener("reset", reset);
|
||||
@@ -369,12 +445,78 @@ export default defineComponent({
|
||||
chars,
|
||||
mask: computed(() => props.mask),
|
||||
inputClassName: computed(() => props.inputClassName),
|
||||
textAlign: computed(() => props.textAlign),
|
||||
handlePaste,
|
||||
guardInput,
|
||||
describedBy,
|
||||
inputId,
|
||||
labelledBy,
|
||||
accessibleLabel,
|
||||
});
|
||||
|
||||
function guardInput(event: InputEvent, index: number) {
|
||||
if (event.isComposing) return;
|
||||
if (!(event.target instanceof HTMLInputElement)) return;
|
||||
const target = event.target;
|
||||
const next = [...slotChars.value];
|
||||
const multi = (event.data?.length ?? 0) > 1;
|
||||
if (multi) {
|
||||
const text = target.value;
|
||||
const start = text.length >= length.value ? 0 : index;
|
||||
for (
|
||||
let i = start;
|
||||
i < Math.min(start + text.length, length.value);
|
||||
i++
|
||||
)
|
||||
next[i] = text[i - start]!;
|
||||
} else next[index] = event.data || target.value.slice(-1);
|
||||
if (
|
||||
disabled.value ||
|
||||
readOnly.value ||
|
||||
event.defaultPrevented ||
|
||||
(pattern.value && !valueAllowed(pattern.value, stringFromChars(next)))
|
||||
) {
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
target.value = slotChars.value[index] ?? "";
|
||||
target.select();
|
||||
}
|
||||
}
|
||||
|
||||
function handlePaste(event: ClipboardEvent, index: number) {
|
||||
if (
|
||||
event.defaultPrevented ||
|
||||
disabled.value ||
|
||||
readOnly.value ||
|
||||
!event.clipboardData
|
||||
)
|
||||
return;
|
||||
const raw =
|
||||
event.clipboardData.getData("text/plain") ||
|
||||
event.clipboardData.getData("text");
|
||||
const text = props.pasteTransformer ? props.pasteTransformer(raw) : raw;
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
if (!text) return;
|
||||
// Preserve PinInput's slot editing convention: a full code replaces
|
||||
// all slots; a shorter paste starts at the focused slot.
|
||||
const start = text.length >= length.value ? 0 : index;
|
||||
const next = [...slotChars.value];
|
||||
for (let i = start; i < Math.min(start + text.length, length.value); i++)
|
||||
next[i] = text[i - start]!;
|
||||
if (!applyChars(next)) return;
|
||||
void nextTick(() => {
|
||||
if (isControlled.value && props.modelValue !== stringFromChars(next))
|
||||
return;
|
||||
const inputs = rootEl.value?.querySelectorAll<HTMLInputElement>(
|
||||
'input[data-slot="input-otp-input"]',
|
||||
);
|
||||
const input = inputs?.[Math.min(start + text.length, length.value - 1)];
|
||||
input?.focus();
|
||||
input?.select();
|
||||
});
|
||||
}
|
||||
|
||||
function prepareLabels(
|
||||
nodes: VNodeChild[],
|
||||
ids: string[],
|
||||
@@ -405,6 +547,19 @@ export default defineComponent({
|
||||
return node;
|
||||
});
|
||||
}
|
||||
function invalidCapture(event: Event) {
|
||||
const target = event.target;
|
||||
if (
|
||||
target instanceof HTMLInputElement &&
|
||||
target.getAttribute("aria-hidden") === "true"
|
||||
) {
|
||||
nativeDetails.value = validitySnapshot(target.validity);
|
||||
nativeError.value =
|
||||
props.validationErrors?.length || serverErrors.value.length
|
||||
? ""
|
||||
: target.validationMessage;
|
||||
}
|
||||
}
|
||||
function render() {
|
||||
const labels: string[] = [];
|
||||
const children = prepareLabels(slots.default?.() ?? [], labels);
|
||||
@@ -413,6 +568,7 @@ export default defineComponent({
|
||||
return h(
|
||||
PinInputRoot,
|
||||
{
|
||||
...attrs,
|
||||
ref: setRoot,
|
||||
modelValue: chars.value,
|
||||
disabled: disabled.value,
|
||||
@@ -423,7 +579,14 @@ export default defineComponent({
|
||||
required: props.required,
|
||||
id: resolvedId.value,
|
||||
"onUpdate:modelValue": handlePinUpdate,
|
||||
...attrs,
|
||||
onInvalidCapture: [
|
||||
...(Array.isArray(attrs.onInvalidCapture)
|
||||
? attrs.onInvalidCapture
|
||||
: attrs.onInvalidCapture
|
||||
? [attrs.onInvalidCapture]
|
||||
: []),
|
||||
invalidCapture,
|
||||
],
|
||||
class: [variantSlots.value.base(), attrs.class],
|
||||
"data-disabled": disabled.value || undefined,
|
||||
"data-invalid": invalid.value ? "true" : undefined,
|
||||
|
||||
@@ -93,6 +93,7 @@ export default defineComponent({
|
||||
onKeydownCapture: userKeydownCapture,
|
||||
onPaste: userPaste,
|
||||
onPasteCapture: userPasteCapture,
|
||||
onInputCapture: userInputCapture,
|
||||
...rest
|
||||
} = attrs as Record<string, unknown>;
|
||||
|
||||
@@ -110,6 +111,7 @@ export default defineComponent({
|
||||
...toHandlerArray(userPasteCapture),
|
||||
...toHandlerArray(userPaste),
|
||||
stopIfPrevented,
|
||||
(event) => context?.handlePaste(event as ClipboardEvent, props.index),
|
||||
];
|
||||
|
||||
return h(
|
||||
@@ -117,6 +119,10 @@ export default defineComponent({
|
||||
{
|
||||
...rest,
|
||||
class: [slotClass, cls],
|
||||
onInputCapture: [
|
||||
...toHandlerArray(userInputCapture),
|
||||
(event: InputEvent) => context?.guardInput(event, props.index),
|
||||
],
|
||||
onKeydownCapture: keydownCapture,
|
||||
onPasteCapture: pasteCapture,
|
||||
"data-active": isActive.value || undefined,
|
||||
@@ -151,6 +157,7 @@ export default defineComponent({
|
||||
disabled: isDisabled.value,
|
||||
readonly: isReadOnly.value || undefined,
|
||||
class: inputClass,
|
||||
style: { textAlign: context?.textAlign.value },
|
||||
id: context?.inputId(props.index),
|
||||
"data-slot": "input-otp-input",
|
||||
autocomplete: "one-time-code",
|
||||
|
||||
@@ -14,6 +14,9 @@ export interface InputOTPContextValue {
|
||||
chars: ComputedRef<string[]>;
|
||||
mask: ComputedRef<boolean>;
|
||||
inputClassName: ComputedRef<string | undefined>;
|
||||
textAlign: ComputedRef<"left" | "center" | "right">;
|
||||
guardInput: (event: InputEvent, index: number) => void;
|
||||
handlePaste: (event: ClipboardEvent, index: number) => void;
|
||||
describedBy: ComputedRef<string | undefined>;
|
||||
labelledBy: ComputedRef<string | undefined>;
|
||||
accessibleLabel: ComputedRef<string | undefined>;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, onUnmounted, useAttrs, useId, watch } from "vue";
|
||||
import { labelVariants } from "@heroui-vue/styles";
|
||||
import { useFieldPart } from "../field/useFieldPart";
|
||||
import { useInheritedDisabled } from "../field/disabled";
|
||||
import { fieldContextKey } from "../field/context";
|
||||
@@ -68,12 +69,13 @@ onUnmounted(() => {
|
||||
:for="
|
||||
attrs.for ?? (field?.kind === 'text' ? field.controlId.value : undefined)
|
||||
"
|
||||
class="hv-label"
|
||||
:class="{
|
||||
'hv-label--required': props.isRequired || field?.required.value,
|
||||
'hv-label--disabled': disabled,
|
||||
'hv-label--invalid': props.isInvalid || field?.invalid.value,
|
||||
}"
|
||||
:class="
|
||||
labelVariants({
|
||||
isRequired: Boolean(props.isRequired || field?.required.value),
|
||||
isDisabled: Boolean(disabled),
|
||||
isInvalid: Boolean(props.isInvalid || field?.invalid.value),
|
||||
})
|
||||
"
|
||||
data-slot="label"
|
||||
>
|
||||
<slot />
|
||||
|
||||
@@ -8,8 +8,9 @@ import {
|
||||
onMounted,
|
||||
watch,
|
||||
onBeforeUnmount,
|
||||
onUpdated,
|
||||
} from "vue";
|
||||
import { Primitive } from "reka-ui";
|
||||
import LinkPrimitive from "./LinkPrimitive";
|
||||
import { linkVariants } from "@heroui-vue/styles";
|
||||
import { linkContextKey } from "./context";
|
||||
|
||||
@@ -187,6 +188,7 @@ const passthroughAttrs = computed(() => {
|
||||
return rest;
|
||||
});
|
||||
|
||||
const onRootAuxClickCapture = (e: Event) => guardClick(e, undefined);
|
||||
const onRootClickCapture = (e: Event) =>
|
||||
guardClick(e, liveAttr("onClickCapture"));
|
||||
const onRootClickBubble = (e: Event) => guardClick(e, liveAttr("onClick"));
|
||||
@@ -200,6 +202,7 @@ let bound: HTMLElement | null = null;
|
||||
|
||||
function unbindRoot() {
|
||||
if (!bound) return;
|
||||
bound.removeEventListener("auxclick", onRootAuxClickCapture, true);
|
||||
bound.removeEventListener("click", onRootClickCapture, true);
|
||||
bound.removeEventListener("click", onRootClickBubble, false);
|
||||
bound.removeEventListener("keydown", onRootKeydownCapture, true);
|
||||
@@ -212,6 +215,7 @@ function bindRoot(el: HTMLElement) {
|
||||
if (bound === el) return;
|
||||
unbindRoot();
|
||||
bound = el;
|
||||
el.addEventListener("auxclick", onRootAuxClickCapture, true);
|
||||
el.addEventListener("click", onRootClickCapture, true);
|
||||
el.addEventListener("click", onRootClickBubble, false);
|
||||
el.addEventListener("keydown", onRootKeydownCapture, true);
|
||||
@@ -219,13 +223,20 @@ function bindRoot(el: HTMLElement) {
|
||||
el.addEventListener("keyup", onRootKeyup, false);
|
||||
}
|
||||
|
||||
let rootInstance: unknown;
|
||||
function setRoot(raw: unknown) {
|
||||
rootInstance = raw;
|
||||
const el = resolveElement(raw);
|
||||
element.value = el;
|
||||
if (el) bindRoot(el);
|
||||
else unbindRoot();
|
||||
}
|
||||
|
||||
onUpdated(() => {
|
||||
const el = resolveElement(rootInstance);
|
||||
if (el !== element.value) setRoot(rootInstance);
|
||||
});
|
||||
|
||||
function focus(e: FocusEvent) {
|
||||
focused.value = true;
|
||||
focusVisible.value = (e.target as HTMLElement).matches(":focus-visible");
|
||||
@@ -253,17 +264,20 @@ defineExpose({
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Primitive
|
||||
<LinkPrimitive
|
||||
:ref="setRoot"
|
||||
as="a"
|
||||
:is-disabled="disabled"
|
||||
:as-child="asChild"
|
||||
v-bind="passthroughAttrs"
|
||||
:href="href"
|
||||
:target="href ? target : undefined"
|
||||
:href="disabled ? undefined : href"
|
||||
:target="!disabled && href ? target : undefined"
|
||||
:rel="rel"
|
||||
:download="downloadAttr"
|
||||
:download="disabled ? undefined : downloadAttr"
|
||||
:class="slots.base()"
|
||||
:role="(attrs.role as string | undefined) ?? (asChild ? 'link' : undefined)"
|
||||
:role="
|
||||
(attrs.role as string | undefined) ??
|
||||
(asChild || disabled ? 'link' : undefined)
|
||||
"
|
||||
:tabindex="
|
||||
disabled
|
||||
? -1
|
||||
@@ -296,5 +310,5 @@ defineExpose({
|
||||
:is-focused="focused"
|
||||
:is-focus-visible="focusVisible"
|
||||
/>
|
||||
</Primitive>
|
||||
</LinkPrimitive>
|
||||
</template>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { cloneVNode, defineComponent, h, mergeProps } from "vue";
|
||||
import { overlayNodes } from "../overlay/OverlayAction";
|
||||
|
||||
/** Slot composition with disabled navigation attributes taking precedence.
|
||||
* Preserve the child's ref rather than letting a slot implementation delete it. */
|
||||
export default defineComponent({
|
||||
name: "LinkPrimitive",
|
||||
inheritAttrs: false,
|
||||
props: { asChild: Boolean, isDisabled: Boolean },
|
||||
setup(props, { attrs, slots }) {
|
||||
return () => {
|
||||
const children = slots.default?.();
|
||||
if (!props.asChild) return h("a", attrs, children);
|
||||
const nodes = overlayNodes(children);
|
||||
if (nodes.length !== 1 || typeof nodes[0]?.type === "symbol")
|
||||
throw new Error("Link asChild requires one element or component root.");
|
||||
const child = nodes[0]!;
|
||||
const { ref: _ref, ...childProps } = child.props ?? {};
|
||||
const merged = mergeProps(attrs, childProps);
|
||||
if (props.isDisabled) {
|
||||
const block = (event: Event) => {
|
||||
if (
|
||||
event instanceof KeyboardEvent &&
|
||||
!["Enter", " ", "Spacebar"].includes(event.key)
|
||||
)
|
||||
return;
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
};
|
||||
// The child's native capture listener is installed before Link's root
|
||||
// listeners. Gate it here so disabled activation cannot run child code.
|
||||
merged.onClickCapture = block;
|
||||
merged.onAuxclickCapture = block;
|
||||
for (const key of ["onKeydownCapture", "onKeyupCapture"]) {
|
||||
const handler = merged[key];
|
||||
merged[key] = [
|
||||
block,
|
||||
...(Array.isArray(handler) ? handler : handler ? [handler] : []),
|
||||
];
|
||||
}
|
||||
|
||||
Object.assign(merged, {
|
||||
href: null,
|
||||
target: null,
|
||||
download: null,
|
||||
ping: null,
|
||||
tabindex: -1,
|
||||
tabIndex: -1,
|
||||
"aria-disabled": "true",
|
||||
});
|
||||
}
|
||||
return cloneVNode({ ...child, props: {} }, merged, true);
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -8,19 +8,24 @@ import {
|
||||
onBeforeUpdate,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
onUpdated,
|
||||
provide,
|
||||
ref,
|
||||
shallowRef,
|
||||
useAttrs,
|
||||
useSlots,
|
||||
watch,
|
||||
watchEffect,
|
||||
} from "vue";
|
||||
import { useVirtualList } from "@vueuse/core";
|
||||
import { bindVirtualRows, useVirtualRows } from "../collection/virtual-rows";
|
||||
import { listboxVariants } from "@heroui-vue/styles";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import Header from "../header/HeaderRoot.vue";
|
||||
import { useInheritedDisabled, disabledContextKey } from "../field/disabled";
|
||||
import { useCollectionSelection } from "../collection/selection";
|
||||
import { useCollectionRegistry } from "../collection/registry";
|
||||
import { collectionOwnerKey } from "../collection/owner";
|
||||
import { assertKey } from "../collection/keys";
|
||||
import { assertKey, encodeKey } from "../collection/keys";
|
||||
import {
|
||||
listBoxKey,
|
||||
type ListBoxDataItem,
|
||||
@@ -37,6 +42,10 @@ const props = withDefaults(defineProps<ListBoxOptions<T>>(), {
|
||||
variant: "default",
|
||||
as: "div",
|
||||
rowHeight: 50,
|
||||
headingHeight: 48,
|
||||
loaderHeight: 48,
|
||||
gap: 0,
|
||||
padding: 0,
|
||||
overscan: 5,
|
||||
});
|
||||
const owner = inject(collectionOwnerKey, undefined);
|
||||
@@ -62,7 +71,10 @@ const emit = defineEmits<{
|
||||
defineSlots<{
|
||||
default?: (props: { item: T; index: number }) => unknown;
|
||||
empty?: () => unknown;
|
||||
loader?: () => unknown;
|
||||
}>();
|
||||
const slots = useSlots();
|
||||
const hasLoader = ref(Boolean(slots.loader));
|
||||
const attrs = useAttrs();
|
||||
const instance = getCurrentInstance()!;
|
||||
const modelPresence = () =>
|
||||
@@ -76,6 +88,7 @@ const selectedPresence = () =>
|
||||
const controlled = ref(modelPresence() || selectedPresence());
|
||||
const hasModel = ref(modelPresence());
|
||||
onBeforeUpdate(() => {
|
||||
hasLoader.value = Boolean(slots.loader);
|
||||
hasModel.value = modelPresence();
|
||||
controlled.value = hasModel.value || selectedPresence();
|
||||
});
|
||||
@@ -231,18 +244,178 @@ const visibleItems = computed(() => {
|
||||
return items.filter((item) => visible.has(item.id));
|
||||
});
|
||||
const source = computed(() => visibleItems.value);
|
||||
// VueUse owns measurement, scroll range and cleanup; one logical collection
|
||||
// remains available for select-all/typeahead even while most rows are unmounted.
|
||||
const {
|
||||
list: windowItems,
|
||||
containerProps,
|
||||
wrapperProps,
|
||||
scrollTo,
|
||||
} = useVirtualList(source, {
|
||||
itemHeight: () => props.rowHeight,
|
||||
overscan: props.overscan,
|
||||
/**
|
||||
* Virtualized row stream: padding spacers, optional heading rows (from the
|
||||
* item `heading` field), the item rows themselves and an optional loader row.
|
||||
* Row heights are px and re-read on every layout pass, so reactive heights or
|
||||
* props update the window without a remount. `gap` is the spacing between
|
||||
* content rows (item/heading/loader), counted into the earlier row's wrapper
|
||||
* height to keep one geometry source; padding spacers carry no gap.
|
||||
* `padding` renders as spacer rows at both ends.
|
||||
*/
|
||||
type VirtualRow =
|
||||
| { key: string; kind: "pad"; height: number; gap: number }
|
||||
| {
|
||||
key: string;
|
||||
kind: "heading";
|
||||
height: number | undefined;
|
||||
gap: number;
|
||||
text: string;
|
||||
estimate: number;
|
||||
}
|
||||
| {
|
||||
key: string;
|
||||
kind: "item";
|
||||
height: number | undefined;
|
||||
gap: number;
|
||||
item: T;
|
||||
index: number;
|
||||
estimate: number;
|
||||
}
|
||||
| { key: string; kind: "loader"; height: number; gap: number };
|
||||
const fallbackRowHeight = computed(
|
||||
() =>
|
||||
props.estimatedRowHeight ??
|
||||
(typeof props.rowHeight === "number" ? props.rowHeight : 50),
|
||||
);
|
||||
const virtualRows = computed<VirtualRow[]>(() => {
|
||||
const rows: VirtualRow[] = [];
|
||||
const push = (row: VirtualRow) => {
|
||||
const prev = rows.at(-1);
|
||||
if (row.kind !== "pad" && prev && prev.kind !== "pad")
|
||||
prev.gap = Math.max(0, props.gap);
|
||||
rows.push(row);
|
||||
};
|
||||
if (props.padding > 0)
|
||||
push({ key: "pad-top", kind: "pad", height: props.padding, gap: 0 });
|
||||
source.value.forEach((item, index) => {
|
||||
if (item.heading)
|
||||
push({
|
||||
key: `heading-${encodeKey(item.id)}`,
|
||||
kind: "heading",
|
||||
height:
|
||||
typeof props.headingHeight === "function"
|
||||
? props.headingHeight(index)
|
||||
: props.headingHeight,
|
||||
estimate: props.estimatedHeadingHeight ?? 48,
|
||||
text: item.heading,
|
||||
gap: 0,
|
||||
});
|
||||
push({
|
||||
key: `item-${encodeKey(item.id)}`,
|
||||
kind: "item",
|
||||
height:
|
||||
typeof props.rowHeight === "function"
|
||||
? props.rowHeight(index)
|
||||
: props.rowHeight,
|
||||
estimate: fallbackRowHeight.value,
|
||||
item,
|
||||
index,
|
||||
gap: 0,
|
||||
});
|
||||
});
|
||||
if (hasLoader.value && props.loaderHeight > 0)
|
||||
push({ key: "loader", kind: "loader", height: props.loaderHeight, gap: 0 });
|
||||
if (props.padding > 0)
|
||||
push({ key: "pad-bottom", kind: "pad", height: props.padding, gap: 0 });
|
||||
return rows;
|
||||
});
|
||||
const virtualLayout = useVirtualRows({
|
||||
count: () => virtualRows.value.length,
|
||||
keys: () => virtualRows.value.map((row) => row.key),
|
||||
rowHeight: (index) => {
|
||||
const row = virtualRows.value[index];
|
||||
return row?.height === undefined ? undefined : row.height + row.gap;
|
||||
},
|
||||
estimatedRowHeight: (index) => {
|
||||
const row = virtualRows.value[index];
|
||||
return (
|
||||
(row && "estimate" in row ? row.estimate : fallbackRowHeight.value) +
|
||||
(row?.gap ?? 0)
|
||||
);
|
||||
},
|
||||
get overscan() {
|
||||
return props.overscan;
|
||||
},
|
||||
});
|
||||
const windowItems = computed(() => {
|
||||
const { start, end } = virtualLayout.window.value;
|
||||
return virtualRows.value
|
||||
.slice(start, end)
|
||||
.map((data, index) => ({ data, index: start + index }));
|
||||
});
|
||||
const wrapperProps = computed(() => ({
|
||||
style: {
|
||||
height: `${virtualLayout.totalHeight.value}px`,
|
||||
paddingTop: `${virtualLayout.window.value.padTop}px`,
|
||||
boxSizing: "border-box" as const,
|
||||
overflowAnchor: "none" as const,
|
||||
},
|
||||
}));
|
||||
function rowIndexOfItem(index: number): number {
|
||||
return virtualRows.value.findIndex(
|
||||
(row) => row.kind === "item" && row.index === index,
|
||||
);
|
||||
}
|
||||
const root = shallowRef<HTMLElement | null>(null);
|
||||
const virtualContent = shallowRef<HTMLElement | null>(null);
|
||||
function resolveScrollParent() {
|
||||
const el = root.value;
|
||||
if (!el) return null;
|
||||
// Overflow policy matters even before an asynchronous collection overflows.
|
||||
for (let node: HTMLElement | null = el; node; node = node.parentElement)
|
||||
if (/^(auto|scroll)$/.test(getComputedStyle(node).overflowY)) return node;
|
||||
return el;
|
||||
}
|
||||
let scrollParent: HTMLElement | null = null;
|
||||
let boundContent: HTMLElement | null = null;
|
||||
let detachVirtual: (() => void) | undefined;
|
||||
function stickyInset() {
|
||||
if (!scrollParent || scrollParent === root.value) return 0;
|
||||
let inset = 0;
|
||||
// Measure preceding sticky chrome, including caller-owned search wrappers.
|
||||
for (
|
||||
let node = root.value;
|
||||
node && node !== scrollParent;
|
||||
node = node.parentElement
|
||||
) {
|
||||
for (
|
||||
let previous = node.previousElementSibling;
|
||||
previous;
|
||||
previous = previous.previousElementSibling
|
||||
) {
|
||||
const style = getComputedStyle(previous);
|
||||
if (style.position === "sticky" && style.top !== "auto")
|
||||
inset = Math.max(
|
||||
inset,
|
||||
(parseFloat(style.top) || 0) +
|
||||
previous.getBoundingClientRect().height,
|
||||
);
|
||||
}
|
||||
}
|
||||
return inset;
|
||||
}
|
||||
function refreshVirtualBinding() {
|
||||
const parent = props.virtualized ? resolveScrollParent() : null;
|
||||
if (parent === scrollParent && virtualContent.value === boundContent) return;
|
||||
detachVirtual?.();
|
||||
detachVirtual = undefined;
|
||||
scrollParent = parent;
|
||||
boundContent = virtualContent.value;
|
||||
if (parent && boundContent)
|
||||
detachVirtual = bindVirtualRows(virtualLayout, parent, {
|
||||
content: boundContent,
|
||||
scrollPaddingStart: stickyInset,
|
||||
});
|
||||
}
|
||||
watch([root, virtualContent, () => props.virtualized], refreshVirtualBinding, {
|
||||
flush: "post",
|
||||
});
|
||||
onUpdated(refreshVirtualBinding);
|
||||
onBeforeUnmount(() => {
|
||||
detachVirtual?.();
|
||||
scrollParent = null;
|
||||
});
|
||||
const root = containerProps.ref;
|
||||
let restoringFocus = false;
|
||||
function restoreFocus() {
|
||||
restoringFocus = true;
|
||||
@@ -282,8 +455,10 @@ async function waitForMountedRow(key: ListBoxKey, valid: () => boolean) {
|
||||
}
|
||||
/**
|
||||
* Bring a row into view without taking DOM focus. Virtualized lists move the
|
||||
* window by index; ordinary lists scroll the mounted row (the row itself may
|
||||
* sit inside any scroll container supplied by the caller).
|
||||
* window by row offset (item rows may sit behind heading/padding rows); the
|
||||
* scroll container may be any scrolling ancestor; ordinary lists scroll the
|
||||
* mounted row (the row itself may sit inside any scroll container supplied by
|
||||
* the caller).
|
||||
*/
|
||||
async function revealRow(key: ListBoxKey, valid: () => boolean) {
|
||||
// Every side effect is guarded: filtering, closing, unmounting or a newer
|
||||
@@ -292,16 +467,10 @@ async function revealRow(key: ListBoxKey, valid: () => boolean) {
|
||||
if (props.virtualized) {
|
||||
const index = source.value.findIndex((item) => item.id === key);
|
||||
if (index < 0 || !valid()) return;
|
||||
const rowTop = index * props.rowHeight;
|
||||
const element = root.value;
|
||||
if (
|
||||
element &&
|
||||
(rowTop < element.scrollTop ||
|
||||
rowTop + props.rowHeight > element.scrollTop + element.clientHeight)
|
||||
) {
|
||||
if (!valid()) return;
|
||||
scrollTo(index);
|
||||
}
|
||||
const rowIndex = rowIndexOfItem(index);
|
||||
if (rowIndex < 0) return;
|
||||
const element = scrollParent ?? root.value;
|
||||
if (element && valid()) virtualLayout.scrollToIndex(element, rowIndex);
|
||||
await waitForMountedRow(key, valid);
|
||||
return;
|
||||
}
|
||||
@@ -455,14 +624,36 @@ function keydown(event: KeyboardEvent) {
|
||||
.ordered()
|
||||
.find((member) => member.key() === active.value)
|
||||
?.element();
|
||||
const activeHeight =
|
||||
(typeof props.rowHeight === "function"
|
||||
? props.rowHeight(index)
|
||||
: props.rowHeight) ?? fallbackRowHeight.value;
|
||||
const height = props.virtualized
|
||||
? props.rowHeight
|
||||
: current?.getBoundingClientRect().height || props.rowHeight;
|
||||
const page = Math.max(
|
||||
? activeHeight
|
||||
: current?.getBoundingClientRect().height || activeHeight;
|
||||
const viewport = Math.max(
|
||||
1,
|
||||
Math.floor((root.value?.clientHeight ?? 0) / height),
|
||||
((scrollParent ?? root.value)?.clientHeight ?? 0) - stickyInset(),
|
||||
);
|
||||
target = index + (event.key === "PageDown" ? page : -page);
|
||||
if (props.virtualized && index >= 0) {
|
||||
const direction = event.key === "PageDown" ? 1 : -1;
|
||||
const offsetOf = (itemIndex: number) => {
|
||||
const logical = source.value.findIndex(
|
||||
(item) => item.id === items[itemIndex].key,
|
||||
);
|
||||
return virtualLayout.rowOffsetOf(rowIndexOfItem(logical));
|
||||
};
|
||||
const goal = offsetOf(index) + viewport * direction;
|
||||
target = index;
|
||||
while (target + direction >= 0 && target + direction < items.length) {
|
||||
target += direction;
|
||||
if (direction > 0 ? offsetOf(target) >= goal : offsetOf(target) <= goal)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
const page = Math.max(1, Math.floor(viewport / height));
|
||||
target = index + (event.key === "PageDown" ? page : -page);
|
||||
}
|
||||
} else if (event.key === backward) target = index - 1;
|
||||
else if (event.key === forward) target = index + 1;
|
||||
if (target !== undefined) {
|
||||
@@ -590,7 +781,9 @@ function rootAttrs() {
|
||||
throw new TypeError("Single ListBox accepts at most one selected key.");
|
||||
if (
|
||||
props.virtualized &&
|
||||
(!props.items || props.orientation !== "vertical" || props.rowHeight <= 0)
|
||||
(!props.items ||
|
||||
props.orientation !== "vertical" ||
|
||||
(typeof props.rowHeight === "number" && props.rowHeight <= 0))
|
||||
)
|
||||
throw new Error(
|
||||
"Virtualized ListBox requires items, vertical orientation and a positive rowHeight.",
|
||||
@@ -610,6 +803,9 @@ function rootAttrs() {
|
||||
dir: dir.value,
|
||||
"data-slot": "list-box",
|
||||
"data-hv-listbox": "",
|
||||
// Styling hook: virtualized lists bind their row window to a scrolling
|
||||
// ancestor and must not be forced into a self-scrolling box.
|
||||
"data-virtualized": props.virtualized ? "" : undefined,
|
||||
"data-disabled": disabled.value || undefined,
|
||||
"aria-disabled": disabled.value || undefined,
|
||||
"aria-readonly": readOnly.value || undefined,
|
||||
@@ -645,7 +841,8 @@ function rootAttrs() {
|
||||
)
|
||||
void focus(active.value);
|
||||
},
|
||||
onScroll: props.virtualized ? containerProps.onScroll : undefined,
|
||||
// Virtualized scrolling is owned by the resolved scroll parent (native
|
||||
// listener); the root itself needs no scroll handler.
|
||||
});
|
||||
}
|
||||
defineExpose({
|
||||
@@ -668,17 +865,35 @@ defineExpose({
|
||||
<slot v-if="!visibleItems.length" name="empty" />
|
||||
<div
|
||||
v-if="virtualized"
|
||||
ref="virtualContent"
|
||||
v-bind="wrapperProps"
|
||||
role="presentation"
|
||||
data-slot="list-box-virtual-content"
|
||||
>
|
||||
<div
|
||||
v-for="entry in windowItems"
|
||||
:key="entry.data.id"
|
||||
:key="entry.data.key"
|
||||
role="presentation"
|
||||
:style="{ height: `${rowHeight}px` }"
|
||||
:ref="(element) => virtualLayout.measureRow(entry.index, element)"
|
||||
:style="{
|
||||
height:
|
||||
entry.data.height === undefined
|
||||
? undefined
|
||||
: `${entry.data.height + entry.data.gap}px`,
|
||||
paddingBottom: `${entry.data.gap}px`,
|
||||
boxSizing: 'border-box',
|
||||
}"
|
||||
>
|
||||
<slot :item="entry.data" :index="entry.index" />
|
||||
<div v-if="entry.data.kind === 'pad'" aria-hidden="true" />
|
||||
<Header v-else-if="entry.data.kind === 'heading'">
|
||||
{{ entry.data.text }}
|
||||
</Header>
|
||||
<slot
|
||||
v-else-if="entry.data.kind === 'item'"
|
||||
:item="entry.data.item"
|
||||
:index="entry.data.index"
|
||||
/>
|
||||
<slot v-else name="loader" />
|
||||
</div>
|
||||
</div>
|
||||
<template v-else v-for="(item, index) in items" :key="item.id">
|
||||
|
||||
@@ -8,6 +8,12 @@ export interface ListBoxDataItem {
|
||||
id: ListBoxKey;
|
||||
textValue?: string;
|
||||
isDisabled?: boolean;
|
||||
/**
|
||||
* Virtualized grouping: a heading row is rendered before this item. The
|
||||
* heading is a display row (like the non-virtual ListBoxSection header) and
|
||||
* never participates in selection or the `aria-posinset` item indexing.
|
||||
*/
|
||||
heading?: string;
|
||||
}
|
||||
/** Shared schema: generic SFC parameter extraction can erase its prop types. */
|
||||
export interface ListBoxOptions<T extends ListBoxDataItem = ListBoxDataItem> {
|
||||
@@ -28,7 +34,25 @@ export interface ListBoxOptions<T extends ListBoxDataItem = ListBoxDataItem> {
|
||||
as?: string;
|
||||
items?: readonly T[];
|
||||
virtualized?: boolean;
|
||||
rowHeight?: number;
|
||||
/**
|
||||
* Row height in px. A number is the fixed row height; a function maps the
|
||||
* item index to its height (variable rows), returning `undefined` to fall
|
||||
* back to `estimatedRowHeight`. Re-read on every layout pass, so reactive
|
||||
* heights update the window without a remount.
|
||||
*/
|
||||
rowHeight?: number | ((index: number) => number | undefined);
|
||||
/** Fallback height in px for variable rows whose function returns undefined. */
|
||||
estimatedRowHeight?: number;
|
||||
/** Heading row height in px for virtualized `heading` rows. */
|
||||
headingHeight?: number | ((index: number) => number | undefined);
|
||||
/** Estimate used until an unknown heading is measured. */
|
||||
estimatedHeadingHeight?: number;
|
||||
/** Loader row height in px for the virtualized `#loader` row. */
|
||||
loaderHeight?: number;
|
||||
/** Gap in px between rows (counted after every row but the last). */
|
||||
gap?: number;
|
||||
/** List padding in px rendered as spacer rows at both ends. */
|
||||
padding?: number;
|
||||
overscan?: number;
|
||||
}
|
||||
export interface ListBoxItemState {
|
||||
|
||||
@@ -4,21 +4,24 @@ import {
|
||||
defineComponent,
|
||||
getCurrentInstance,
|
||||
nextTick,
|
||||
onMounted,
|
||||
provide,
|
||||
ref,
|
||||
type SlotsType,
|
||||
type VNode,
|
||||
} from "vue";
|
||||
import { searchFieldVariants } from "@heroui-vue/styles";
|
||||
import { textFieldProps, useTextField } from "../field/useTextField";
|
||||
import { searchFieldContextKey } from "./context";
|
||||
import { searchFieldContextKey, type SearchFieldRenderProps } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "SearchField",
|
||||
inheritAttrs: false,
|
||||
slots: Object as SlotsType<{
|
||||
default: (state: SearchFieldRenderProps) => VNode[];
|
||||
}>,
|
||||
props: {
|
||||
...textFieldProps,
|
||||
type: { type: String, default: "search" },
|
||||
autoFocus: Boolean,
|
||||
},
|
||||
emits: {
|
||||
"update:modelValue": (_value: string) => true,
|
||||
@@ -27,32 +30,34 @@ export default defineComponent({
|
||||
},
|
||||
setup(props, context) {
|
||||
const instance = getCurrentInstance();
|
||||
const hovered = ref(false),
|
||||
focused = ref(false),
|
||||
focusVisible = ref(false);
|
||||
const hovered = ref(false);
|
||||
const slots = computed(() =>
|
||||
searchFieldVariants({
|
||||
variant: props.variant,
|
||||
fullWidth: props.fullWidth,
|
||||
}),
|
||||
);
|
||||
const { field, element, render } = useTextField(props, context, {
|
||||
rootSlot: "search-field",
|
||||
rootClass: () => slots.value.base(),
|
||||
rootAttrs: () => ({
|
||||
onKeydown: keydown,
|
||||
"data-empty": !field.value.value || undefined,
|
||||
"data-focus-within": focused.value || undefined,
|
||||
"data-focus-visible": focusVisible.value || undefined,
|
||||
"data-hovered": (!field.disabled.value && hovered.value) || undefined,
|
||||
}),
|
||||
slotState: () => ({
|
||||
isEmpty: !field.value.value,
|
||||
isHovered: !field.disabled.value && hovered.value,
|
||||
isFocusWithin: focused.value,
|
||||
isFocusVisible: focusVisible.value,
|
||||
}),
|
||||
});
|
||||
const { field, element, render, focused, focusVisible } = useTextField(
|
||||
props,
|
||||
context,
|
||||
{
|
||||
rootSlot: "search-field",
|
||||
rootClass: () => slots.value.base(),
|
||||
rootAttrs: () => ({
|
||||
onKeydown: keydown,
|
||||
"data-empty": !field.value.value || undefined,
|
||||
"data-focus-within": focused.value || undefined,
|
||||
"data-focus-visible": focusVisible.value || undefined,
|
||||
"data-hovered": (!field.disabled.value && hovered.value) || undefined,
|
||||
}),
|
||||
slotState: () => ({
|
||||
isEmpty: !field.value.value,
|
||||
isHovered: !field.disabled.value && hovered.value,
|
||||
isFocusWithin: focused.value,
|
||||
isFocusVisible: focusVisible.value,
|
||||
}),
|
||||
},
|
||||
);
|
||||
function clear(event?: Event) {
|
||||
const input = element.value;
|
||||
if (
|
||||
@@ -112,9 +117,7 @@ export default defineComponent({
|
||||
clear,
|
||||
keydown,
|
||||
});
|
||||
onMounted(() => {
|
||||
if (props.autoFocus && !field.disabled.value) element.value?.focus();
|
||||
});
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import type { ComputedRef, InjectionKey, Ref } from "vue";
|
||||
import type { searchFieldVariants } from "@heroui-vue/styles";
|
||||
import type { TextFieldContext } from "../textfield/context";
|
||||
import type { TextFieldRenderProps } from "../field/useTextField";
|
||||
export interface SearchFieldRenderProps extends TextFieldRenderProps {
|
||||
isEmpty: boolean;
|
||||
isHovered: boolean;
|
||||
}
|
||||
export interface SearchFieldContext {
|
||||
field: TextFieldContext;
|
||||
slots: ComputedRef<ReturnType<typeof searchFieldVariants>>;
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
withDefaults(defineProps<{ orientation?: "horizontal" | "vertical" }>(), {
|
||||
orientation: "vertical",
|
||||
});
|
||||
import { computed } from "vue";
|
||||
import { switchGroupVariants } from "@heroui-vue/styles";
|
||||
const props = withDefaults(
|
||||
defineProps<{ orientation?: "horizontal" | "vertical" }>(),
|
||||
{
|
||||
orientation: "vertical",
|
||||
},
|
||||
);
|
||||
const styles = computed(() =>
|
||||
switchGroupVariants({ orientation: props.orientation }),
|
||||
);
|
||||
</script>
|
||||
<template>
|
||||
<div
|
||||
role="group"
|
||||
class="hv-switch-group"
|
||||
:class="`hv-switch-group--${orientation}`"
|
||||
data-slot="switch-group"
|
||||
>
|
||||
<div class="hv-switch-group__items" data-slot="switch-group-items">
|
||||
<div role="group" :class="styles.base()" data-slot="switch-group">
|
||||
<div :class="styles.items()" data-slot="switch-group-items">
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -90,10 +90,10 @@ export default defineComponent({
|
||||
* (TableRow/native tr, TableCollection.items) and no rows registered.
|
||||
*/
|
||||
empty: { type: Boolean, default: undefined },
|
||||
/** Colspan of the empty-state cell. */
|
||||
/** Colspan of the empty-state cell. Defaults to the real leaf column count. */
|
||||
colspan: {
|
||||
type: [Number, String] as PropType<number | string>,
|
||||
default: 1,
|
||||
default: undefined,
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
@@ -134,6 +134,11 @@ export default defineComponent({
|
||||
function renderEmptyRow() {
|
||||
const content = slots.empty?.();
|
||||
if (!content) return null;
|
||||
// Explicit colspan wins; otherwise span every real leaf column
|
||||
// (selection and wrapper-rendered TableColumns self-register), falling
|
||||
// back to a single cell before any column is known.
|
||||
const columns = ctx?.columns?.value.size ?? 0;
|
||||
const colspan = props.colspan ?? (columns > 0 ? columns : 1);
|
||||
return h(
|
||||
"tr",
|
||||
{
|
||||
@@ -147,7 +152,7 @@ export default defineComponent({
|
||||
{
|
||||
class: "hv-table__empty-cell",
|
||||
"data-slot": "table-empty-cell",
|
||||
colspan: props.colspan,
|
||||
colspan,
|
||||
role: "presentation",
|
||||
},
|
||||
content,
|
||||
|
||||
@@ -51,17 +51,23 @@ export default defineComponent({
|
||||
tabindex: attrs.tabindex ?? -1,
|
||||
class: [ctx?.slots.value.cell(), attrs.class],
|
||||
"data-slot": "table-cell",
|
||||
"data-fixed-height": row?.height?.value != null || undefined,
|
||||
"data-tree-column": isTreeColumn.value || undefined,
|
||||
"data-level": row?.level,
|
||||
colspan: props.colspan,
|
||||
},
|
||||
slots.default?.({
|
||||
isExpanded: row?.isExpanded.value ?? false,
|
||||
hasChildItems: row?.hasChildItems ?? false,
|
||||
isDisabled: row?.isDisabled.value ?? false,
|
||||
isTreeColumn: isTreeColumn.value,
|
||||
isSelected: row?.isSelected.value ?? false,
|
||||
}),
|
||||
(() => {
|
||||
const content = slots.default?.({
|
||||
isExpanded: row?.isExpanded.value ?? false,
|
||||
hasChildItems: row?.hasChildItems ?? false,
|
||||
isDisabled: row?.isDisabled.value ?? false,
|
||||
isTreeColumn: isTreeColumn.value,
|
||||
isSelected: row?.isSelected.value ?? false,
|
||||
});
|
||||
return row?.height?.value != null
|
||||
? [h("div", { class: "hv-table__fixed-cell-content" }, content)]
|
||||
: content;
|
||||
})(),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -42,7 +42,16 @@ export default defineComponent({
|
||||
([node, id, isRowHeader]) => {
|
||||
if (!ctx?.columns) return;
|
||||
const next = new Map(ctx.columns.value);
|
||||
if (node) next.set(token, { node, id, isRowHeader });
|
||||
if (node)
|
||||
next.set(token, {
|
||||
node,
|
||||
id,
|
||||
isRowHeader,
|
||||
widthSpec,
|
||||
applyWidth: (px: number | undefined) => {
|
||||
resolvedWidth.value = px;
|
||||
},
|
||||
});
|
||||
else next.delete(token);
|
||||
ctx.columns.value = next;
|
||||
},
|
||||
@@ -59,6 +68,8 @@ export default defineComponent({
|
||||
const width = computed(() =>
|
||||
props.width !== undefined ? props.width : internalWidth.value,
|
||||
);
|
||||
/** Pixel width resolved by the managed (fr) layout; unset stays native. */
|
||||
const resolvedWidth = ref<number | undefined>(undefined);
|
||||
const setWidth = (next: number) => {
|
||||
if (props.width === undefined) internalWidth.value = next;
|
||||
emit("update:width", next);
|
||||
@@ -69,12 +80,16 @@ export default defineComponent({
|
||||
width,
|
||||
setWidth,
|
||||
});
|
||||
const widthSpec = () => ({
|
||||
width: width.value,
|
||||
minWidth: props.minWidth,
|
||||
maxWidth: props.maxWidth,
|
||||
});
|
||||
const cssWidth = (value: string | number | undefined) => {
|
||||
if (value === undefined) return undefined;
|
||||
if (typeof value === "number") return `${value}px`;
|
||||
// CSS Grid fr units are not valid table widths. Treat Nfr as a flexible
|
||||
// column (native width:auto sharing remaining space). This does not
|
||||
// implement RAC fr weight proportions across columns.
|
||||
// fr is resolved by TableContent after measurement. Leave native layout
|
||||
// untouched until a managed pixel width is available.
|
||||
if (/^\d+(\.\d+)?fr$/.test(value)) return undefined;
|
||||
return value;
|
||||
};
|
||||
@@ -97,9 +112,13 @@ export default defineComponent({
|
||||
ref: element,
|
||||
class: [ctx?.slots.value.column(), attrs.class],
|
||||
style: {
|
||||
width: cssWidth(width.value),
|
||||
width:
|
||||
resolvedWidth.value !== undefined
|
||||
? `${resolvedWidth.value}px`
|
||||
: cssWidth(width.value),
|
||||
minWidth: cssWidth(
|
||||
typeof width.value === "number"
|
||||
resolvedWidth.value === undefined &&
|
||||
typeof width.value === "number"
|
||||
? Math.max(props.minWidth ?? 0, width.value)
|
||||
: props.minWidth,
|
||||
),
|
||||
|
||||
@@ -8,13 +8,17 @@ import {
|
||||
ref,
|
||||
shallowRef,
|
||||
mergeProps,
|
||||
nextTick,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
watch,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import { useTableNavigation } from "./navigation";
|
||||
import { useCollectionSelection } from "../collection/selection";
|
||||
import { calculateColumnSizes } from "./widths";
|
||||
|
||||
import type { TableKey } from "./context";
|
||||
import type { TableKey, TableColumnRegistration } from "./context";
|
||||
import { tableContextKey, type TableSortDirection } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
@@ -175,13 +179,14 @@ export default defineComponent({
|
||||
emit("expandedChange", next);
|
||||
}
|
||||
|
||||
const columns = shallowRef(new Map<symbol, TableColumnRegistration>());
|
||||
provide(tableContextKey, {
|
||||
...(parentCtx ?? {
|
||||
slots: computed(() => ({}) as never),
|
||||
variant: computed(() => "primary"),
|
||||
}),
|
||||
navigation,
|
||||
columns: shallowRef(new Map()),
|
||||
columns,
|
||||
columnDefinitions: shallowRef([]),
|
||||
selectionMode: computed(() => props.selectionMode),
|
||||
selectedKeys,
|
||||
@@ -198,12 +203,87 @@ export default defineComponent({
|
||||
sort,
|
||||
});
|
||||
|
||||
/**
|
||||
* Managed column widths: when any column declares an `fr` width the pinned
|
||||
* baseline weight semantics apply (react-stately TableColumnLayout): static
|
||||
* widths (px / %) are taken first, fr columns share the remaining width by
|
||||
* weight with min/max clamping, and unset columns count as 1fr. Unmeasured
|
||||
* environments (jsdom, display:none) keep native widths untouched.
|
||||
*/
|
||||
const managedLayout = ref(false);
|
||||
function orderedColumns() {
|
||||
return [...columns.value.values()].sort((a, b) =>
|
||||
a.node.compareDocumentPosition(b.node) & 2 ? 1 : -1,
|
||||
);
|
||||
}
|
||||
function recomputeLayout() {
|
||||
const entries = orderedColumns();
|
||||
const specs = entries.map((entry) => entry.widthSpec?.() ?? {});
|
||||
const managed = specs.some(
|
||||
(spec) => typeof spec.width === "string" && spec.width.endsWith("fr"),
|
||||
);
|
||||
if (!managed) {
|
||||
managedLayout.value = false;
|
||||
for (const entry of entries) entry.applyWidth?.(undefined);
|
||||
return;
|
||||
}
|
||||
const table = element.value;
|
||||
let availableWidth = table?.getBoundingClientRect().width ?? 0;
|
||||
const parent = table?.parentElement;
|
||||
if (table && parent) {
|
||||
const parentStyle = getComputedStyle(parent);
|
||||
const parentWidth =
|
||||
parent.clientWidth -
|
||||
(parseFloat(parentStyle.paddingLeft) || 0) -
|
||||
(parseFloat(parentStyle.paddingRight) || 0);
|
||||
// Assigned column pixels can keep a table wider than its shrinking
|
||||
// viewport. Observe that constraint too, retaining an explicit table
|
||||
// min-width for deliberate horizontal overflow.
|
||||
if (parentWidth > 0)
|
||||
availableWidth = Math.max(
|
||||
parseFloat(getComputedStyle(table).minWidth) || 0,
|
||||
Math.min(availableWidth, parentWidth),
|
||||
);
|
||||
}
|
||||
if (!(availableWidth > 0)) return;
|
||||
managedLayout.value = true;
|
||||
const sizes = calculateColumnSizes(availableWidth, specs);
|
||||
entries.forEach((entry, index) => {
|
||||
// Static columns must use the same clamped sizes deducted from the
|
||||
// remaining space, rather than their original width/percentage.
|
||||
entry.applyWidth?.(sizes[index]);
|
||||
});
|
||||
}
|
||||
const layoutSignature = computed(() =>
|
||||
[...columns.value.values()]
|
||||
.map((entry) => {
|
||||
const spec = entry.widthSpec?.();
|
||||
return `${String(spec?.width)}|${spec?.minWidth}|${spec?.maxWidth}`;
|
||||
})
|
||||
.join(";"),
|
||||
);
|
||||
watch([layoutSignature, columns], () => void nextTick(recomputeLayout), {
|
||||
flush: "post",
|
||||
});
|
||||
let layoutObserver: ResizeObserver | undefined;
|
||||
onMounted(() => {
|
||||
recomputeLayout();
|
||||
if (typeof ResizeObserver !== "undefined" && element.value) {
|
||||
layoutObserver = new ResizeObserver(() => recomputeLayout());
|
||||
layoutObserver.observe(element.value);
|
||||
if (element.value.parentElement)
|
||||
layoutObserver.observe(element.value.parentElement);
|
||||
}
|
||||
});
|
||||
onBeforeUnmount(() => layoutObserver?.disconnect());
|
||||
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
mergeProps(attrs, {
|
||||
ref: element,
|
||||
class: parentCtx?.slots.value.content(),
|
||||
style: managedLayout.value ? { tableLayout: "fixed" } : undefined,
|
||||
"data-slot": "table-content",
|
||||
role:
|
||||
attrs.role ??
|
||||
|
||||
@@ -31,6 +31,8 @@ export default defineComponent({
|
||||
level: { type: Number, default: undefined },
|
||||
rowKey: { type: [String, Number] as PropType<TableKey>, required: true },
|
||||
isDisabled: { type: Boolean, default: false },
|
||||
/** Exact virtual-row extent; omitted rows retain natural table sizing. */
|
||||
height: { type: Number, default: undefined },
|
||||
hasChildItems: { type: Boolean, default: false },
|
||||
as: { type: String, default: "tr" },
|
||||
},
|
||||
@@ -76,6 +78,7 @@ export default defineComponent({
|
||||
isSelected,
|
||||
isDisabled,
|
||||
isExpanded,
|
||||
height: computed(() => props.height),
|
||||
get hasChildItems() {
|
||||
return props.hasChildItems;
|
||||
},
|
||||
@@ -100,13 +103,11 @@ export default defineComponent({
|
||||
"aria-expanded": props.hasChildItems ? isExpanded.value : undefined,
|
||||
"aria-level": props.level,
|
||||
// 1-based level for CSS indent (matches upstream --table-row-level).
|
||||
style:
|
||||
props.level != null
|
||||
? ({ "--table-row-level": String(props.level) } as Record<
|
||||
string,
|
||||
string
|
||||
>)
|
||||
: undefined,
|
||||
style: {
|
||||
height: props.height != null ? `${props.height}px` : undefined,
|
||||
"--table-row-level":
|
||||
props.level != null ? String(props.level) : undefined,
|
||||
},
|
||||
"aria-selected":
|
||||
ctx && ctx.selectionMode.value !== "none"
|
||||
? isSelected.value
|
||||
|
||||
@@ -95,6 +95,21 @@ export default defineComponent({
|
||||
string,
|
||||
unknown
|
||||
>;
|
||||
/**
|
||||
* The trigger button owns keyboard focus (click/Enter/Space each activate
|
||||
* once through the column's single sort path). The visible focus ring
|
||||
* stays on the column header like the pinned baseline, by forwarding the
|
||||
* real `:focus-visible` state onto the th's existing `data-focus-visible`
|
||||
* hook — the trigger's own native outline is suppressed inside a column.
|
||||
*/
|
||||
const forwardFocusVisible = (event: FocusEvent, active: boolean) => {
|
||||
const trigger = event.currentTarget as HTMLElement | null;
|
||||
const th = trigger?.closest("th");
|
||||
if (!th) return;
|
||||
if (active && trigger?.matches(":focus-visible"))
|
||||
th.setAttribute("data-focus-visible", "true");
|
||||
else th.removeAttribute("data-focus-visible");
|
||||
};
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
@@ -121,6 +136,10 @@ export default defineComponent({
|
||||
if (!column?.allowsSorting.value && props.columnKey && ctx)
|
||||
ctx.sort(props.columnKey);
|
||||
},
|
||||
onFocus: (event: FocusEvent) =>
|
||||
forwardFocusVisible(event, true),
|
||||
onBlur: (event: FocusEvent) =>
|
||||
forwardFocusVisible(event, false),
|
||||
},
|
||||
),
|
||||
[slots.default?.(), renderIndicator()],
|
||||
|
||||
@@ -7,11 +7,23 @@ import type { tableVariants } from "@heroui-vue/styles";
|
||||
export type TableSlots = ReturnType<typeof tableVariants>;
|
||||
export type TableSortDirection = "ascending" | "descending" | "none";
|
||||
|
||||
export interface TableColumnRegistration {
|
||||
node: HTMLElement;
|
||||
id?: string;
|
||||
isRowHeader: boolean;
|
||||
/** Reactive width spec for managed (fr) layout: controlled or default width. */
|
||||
widthSpec?: () => {
|
||||
width?: string | number;
|
||||
minWidth?: number;
|
||||
maxWidth?: number;
|
||||
};
|
||||
/** Apply (or clear, with undefined) a computed pixel width on a flexible column. */
|
||||
applyWidth?: (px: number | undefined) => void;
|
||||
}
|
||||
|
||||
export interface TableContextValue {
|
||||
columnDefinitions?: Ref<{ id?: string; isRowHeader: boolean }[]>;
|
||||
columns?: Ref<
|
||||
Map<symbol, { node: HTMLElement; id?: string; isRowHeader: boolean }>
|
||||
>;
|
||||
columns?: Ref<Map<symbol, TableColumnRegistration>>;
|
||||
navigation?: ReturnType<typeof useTableNavigation>;
|
||||
slots: ComputedRef<TableSlots>;
|
||||
variant: ComputedRef<string>;
|
||||
@@ -36,6 +48,7 @@ export const tableContextKey: InjectionKey<TableContextValue> =
|
||||
Symbol("hv-table");
|
||||
|
||||
export interface TableRowContextValue {
|
||||
height?: ComputedRef<number | undefined>;
|
||||
nextCellIndex: () => number;
|
||||
key: TableKey;
|
||||
isSelected: ComputedRef<boolean>;
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* Column width resolution for managed tables (explicit `fr` widths).
|
||||
*
|
||||
* Ported from react-stately `TableUtils.js` / `TableColumnLayout.js`
|
||||
* Copyright 2022 Adobe. All rights reserved.
|
||||
* Licensed under Apache-2.0 (LICENSE.react-aria in the component package).
|
||||
* (https://github.com/adobe/react-spectrum) to keep the pinned
|
||||
* baseline's `defaultWidth="Nfr"` weight semantics: static widths (px / %)
|
||||
* are taken first, fractional widths share the remaining space by weight,
|
||||
* min/max clamp with flexbox-style violation freezing, and the rounded
|
||||
* integer sizes sum exactly to the available width.
|
||||
*/
|
||||
|
||||
export type TableColumnWidthSpec = string | number | undefined;
|
||||
|
||||
export interface TableColumnSizeInput {
|
||||
/** Resolved width spec: px number, "N%", "Nfr" or undefined (= 1fr here). */
|
||||
width?: TableColumnWidthSpec;
|
||||
minWidth?: TableColumnWidthSpec;
|
||||
maxWidth?: TableColumnWidthSpec;
|
||||
}
|
||||
|
||||
/** Static widths are numbers or integer percents, matching the baseline parser. */
|
||||
export function isStaticWidth(width: TableColumnWidthSpec): boolean {
|
||||
return (
|
||||
width != null && (!isNaN(Number(width)) || /^\d+%$/.test(String(width)))
|
||||
);
|
||||
}
|
||||
|
||||
/** "Nfr" weight; invalid fr strings fall back to 1 like the baseline. */
|
||||
export function parseFractionalUnit(width: TableColumnWidthSpec): number {
|
||||
if (!width || typeof width === "number") return 1;
|
||||
const match = String(width).match(/^(.+)(?=fr$)/);
|
||||
const parsed = match ? Number(match[0]) : 1;
|
||||
// A NaN/Infinity factor prevents violation freezing from converging.
|
||||
return Number.isFinite(parsed) ? parsed : 1;
|
||||
}
|
||||
|
||||
/** Resolve a static width against the available width (percent support). */
|
||||
export function parseStaticWidth(
|
||||
width: TableColumnWidthSpec,
|
||||
availableWidth: number,
|
||||
): number {
|
||||
if (typeof width === "string") {
|
||||
const match = width.match(/^(\d+)(?=%$)/);
|
||||
if (!match)
|
||||
throw new Error(
|
||||
"Only percentages or numbers are supported for static column widths",
|
||||
);
|
||||
return availableWidth * (parseFloat(match[0]) / 100);
|
||||
}
|
||||
return width as number;
|
||||
}
|
||||
|
||||
export function resolveMaxWidth(
|
||||
maxWidth: TableColumnWidthSpec,
|
||||
availableWidth: number,
|
||||
): number {
|
||||
return maxWidth != null
|
||||
? parseStaticWidth(maxWidth, availableWidth)
|
||||
: Number.MAX_SAFE_INTEGER;
|
||||
}
|
||||
|
||||
export function resolveMinWidth(
|
||||
minWidth: TableColumnWidthSpec,
|
||||
availableWidth: number,
|
||||
): number {
|
||||
return minWidth != null ? parseStaticWidth(minWidth, availableWidth) : 0;
|
||||
}
|
||||
|
||||
interface FlexItem {
|
||||
frozen: boolean;
|
||||
baseSize: number;
|
||||
hypotheticalMainSize: number;
|
||||
min: number;
|
||||
max: number;
|
||||
flex: number;
|
||||
targetMainSize: number;
|
||||
violation: number;
|
||||
}
|
||||
|
||||
function cascadeRounding(items: FlexItem[]): number[] {
|
||||
// Rounds floats that sum to an integer into integers with the same sum.
|
||||
let fpTotal = 0;
|
||||
let intTotal = 0;
|
||||
const rounded: number[] = [];
|
||||
for (const item of items) {
|
||||
const float = item.targetMainSize;
|
||||
const integer = Math.round(float + fpTotal) - intTotal;
|
||||
fpTotal += float;
|
||||
intTotal += integer;
|
||||
rounded.push(integer);
|
||||
}
|
||||
return rounded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve every column width (px) for the given available width.
|
||||
* Unset widths count as `1fr`, matching the pinned TableColumnLayout default.
|
||||
*/
|
||||
export function calculateColumnSizes(
|
||||
availableWidth: number,
|
||||
columns: TableColumnSizeInput[],
|
||||
): number[] {
|
||||
const originalWidth = availableWidth;
|
||||
const flooredWidth = Math.floor(availableWidth);
|
||||
const hasFractionalWidth = availableWidth - flooredWidth > 0;
|
||||
availableWidth = flooredWidth;
|
||||
|
||||
let hasNonFrozenItems = false;
|
||||
const flexItems: FlexItem[] = columns.map((column) => {
|
||||
const width = column.width ?? "1fr";
|
||||
let frozen = false;
|
||||
let baseSize = 0;
|
||||
let flex = 0;
|
||||
let targetMainSize = 0;
|
||||
if (isStaticWidth(width)) {
|
||||
baseSize = parseStaticWidth(width, availableWidth);
|
||||
frozen = true;
|
||||
} else {
|
||||
flex = parseFractionalUnit(width);
|
||||
if (flex <= 0) frozen = true;
|
||||
}
|
||||
const min = resolveMinWidth(column.minWidth, availableWidth);
|
||||
const max = resolveMaxWidth(column.maxWidth, availableWidth);
|
||||
const hypotheticalMainSize = Math.max(min, Math.min(baseSize, max));
|
||||
// Flexbox §9.7 grow-only resolution.
|
||||
if (frozen) targetMainSize = hypotheticalMainSize;
|
||||
else if (baseSize > hypotheticalMainSize) {
|
||||
frozen = true;
|
||||
targetMainSize = hypotheticalMainSize;
|
||||
}
|
||||
if (!frozen) hasNonFrozenItems = true;
|
||||
return {
|
||||
frozen,
|
||||
baseSize,
|
||||
hypotheticalMainSize,
|
||||
min,
|
||||
max,
|
||||
flex,
|
||||
targetMainSize,
|
||||
violation: 0,
|
||||
};
|
||||
});
|
||||
|
||||
while (hasNonFrozenItems) {
|
||||
let usedWidth = 0;
|
||||
let flexFactors = 0;
|
||||
for (const item of flexItems) {
|
||||
if (item.frozen) usedWidth += item.targetMainSize;
|
||||
else {
|
||||
usedWidth += item.baseSize;
|
||||
flexFactors += item.flex;
|
||||
}
|
||||
}
|
||||
const remainingFreeSpace = availableWidth - usedWidth;
|
||||
if (remainingFreeSpace > 0)
|
||||
for (const item of flexItems) {
|
||||
if (!item.frozen) {
|
||||
const ratio = item.flex / flexFactors;
|
||||
item.targetMainSize = item.baseSize + ratio * remainingFreeSpace;
|
||||
}
|
||||
}
|
||||
let totalViolation = 0;
|
||||
for (const item of flexItems) {
|
||||
item.violation = 0;
|
||||
if (!item.frozen) {
|
||||
const { min, max, targetMainSize } = item;
|
||||
item.targetMainSize = Math.max(min, Math.min(targetMainSize, max));
|
||||
item.violation = item.targetMainSize - targetMainSize;
|
||||
totalViolation += item.violation;
|
||||
}
|
||||
}
|
||||
hasNonFrozenItems = false;
|
||||
for (const item of flexItems) {
|
||||
if (
|
||||
totalViolation === 0 ||
|
||||
Math.sign(totalViolation) === Math.sign(item.violation)
|
||||
)
|
||||
item.frozen = true;
|
||||
else if (!item.frozen) hasNonFrozenItems = true;
|
||||
}
|
||||
}
|
||||
|
||||
const columnSizes = cascadeRounding(flexItems);
|
||||
// Give the leftover sub-pixel width to the last column so the sizes sum
|
||||
// exactly to the (possibly fractional) available width.
|
||||
if (hasFractionalWidth && columnSizes.length > 0) {
|
||||
const tableFractionalWidth = String(originalWidth).split(".")[1];
|
||||
const columnWidth = String(columnSizes[columnSizes.length - 1]);
|
||||
columnSizes[columnSizes.length - 1] = Number(
|
||||
`${columnWidth}.${tableFractionalWidth}`,
|
||||
);
|
||||
}
|
||||
return columnSizes;
|
||||
}
|
||||
@@ -1,10 +1,17 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent } from "vue";
|
||||
import { textFieldProps, useTextField } from "../field/useTextField";
|
||||
import { defineComponent, type SlotsType, type VNode } from "vue";
|
||||
import {
|
||||
textFieldProps,
|
||||
useTextField,
|
||||
type TextFieldRenderProps,
|
||||
} from "../field/useTextField";
|
||||
export default defineComponent({
|
||||
name: "TextField",
|
||||
inheritAttrs: false,
|
||||
props: textFieldProps,
|
||||
slots: Object as SlotsType<{
|
||||
default: (state: TextFieldRenderProps) => VNode[];
|
||||
}>,
|
||||
emits: { "update:modelValue": (_value: string) => true },
|
||||
setup(props, context) {
|
||||
return useTextField(props, context).render;
|
||||
|
||||
@@ -38,6 +38,11 @@ export {
|
||||
badgeVariants,
|
||||
alertVariants,
|
||||
inputGroupVariants,
|
||||
labelVariants,
|
||||
descriptionVariants,
|
||||
fieldErrorVariants,
|
||||
textFieldVariants,
|
||||
switchGroupVariants,
|
||||
type ButtonVariants,
|
||||
type CardVariants,
|
||||
type InputVariants,
|
||||
@@ -56,6 +61,11 @@ export {
|
||||
type BadgeVariants,
|
||||
type AlertVariants,
|
||||
type InputGroupVariants,
|
||||
type LabelVariants,
|
||||
type DescriptionVariants,
|
||||
type FieldErrorVariants,
|
||||
type TextFieldVariants,
|
||||
type SwitchGroupVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type {
|
||||
ButtonProps,
|
||||
@@ -439,6 +449,27 @@ export {
|
||||
} from "./composables/useOverlayState";
|
||||
export { default as ConfigProvider } from "./providers/ConfigProvider.vue";
|
||||
export { useLocale } from "./providers/context";
|
||||
/**
|
||||
* Locale-aware base-sensitivity substring matcher (case + diacritic folding,
|
||||
* e.g. `cafe` matches `Café`). Same implementation as the Autocomplete /
|
||||
* ComboBox default filter; use it when a caller filters its own data for the
|
||||
* component (virtualized or async sources) and wants matching semantics.
|
||||
*/
|
||||
export { createBaseContains } from "./components/collection/match";
|
||||
/**
|
||||
* Row geometry for virtualized table/list windows (px units): variable row
|
||||
* heights, loader rows, gap/padding and scroll-to-index. Pure measurement —
|
||||
* selection, identity and focus stay with the existing collection models.
|
||||
*/
|
||||
export {
|
||||
useVirtualRows,
|
||||
bindVirtualRows,
|
||||
type UseVirtualRowsOptions,
|
||||
type UseVirtualRows,
|
||||
type VirtualRowHeight,
|
||||
type VirtualRowWindow,
|
||||
type VirtualRowsBindingOptions,
|
||||
} from "./components/collection/virtual-rows";
|
||||
export type { ConfigProviderProps } from "./types";
|
||||
|
||||
export { default as Modal } from "./components/modal/Modal";
|
||||
@@ -1500,3 +1531,6 @@ export type {
|
||||
TooltipRootProps,
|
||||
TypographyRootProps,
|
||||
} from "./types";
|
||||
|
||||
export type { TextFieldRenderProps } from "./components/field/useTextField";
|
||||
export type { SearchFieldRenderProps } from "./components/search-field/context";
|
||||
|
||||
@@ -187,7 +187,7 @@ export type BreadcrumbsProps = InstanceType<typeof Breadcrumbs>["$props"];
|
||||
/** Public item props; Root injects `isLast` / `separatorSlot` internally. */
|
||||
export type BreadcrumbsItemProps = Omit<
|
||||
InstanceType<typeof BreadcrumbsItem>["$props"],
|
||||
"isLast" | "separatorSlot"
|
||||
"isLast" | "separatorSlot" | "itemKey"
|
||||
>;
|
||||
|
||||
import type SearchFieldGroup from "./components/search-field/SearchFieldGroup.vue";
|
||||
|
||||
@@ -110,7 +110,9 @@ const browser = ids.includes("b02-pickers")
|
||||
? "b01"
|
||||
: ids.includes("color-picker")
|
||||
? "color-picker"
|
||||
: null;
|
||||
: ids.includes("shared-styles")
|
||||
? "shared-styles"
|
||||
: null;
|
||||
if (browser) {
|
||||
for (const file of ["index.html", "main.js", "style.css"])
|
||||
fs.copyFileSync(
|
||||
|
||||
@@ -1316,3 +1316,205 @@ it("menu-level close policy wins over the section mode default", async () => {
|
||||
await nextTick();
|
||||
expect(document.querySelector('[data-slot="menu-item"]')).not.toBeNull();
|
||||
});
|
||||
|
||||
function mountSubmenuWithDelay(
|
||||
delay?: number,
|
||||
itemProps: () => Record<string, unknown> = () => ({}),
|
||||
menuProps: Record<string, unknown> = {},
|
||||
rootProps: () => Record<string, unknown> = () => ({}),
|
||||
) {
|
||||
return mountApp(
|
||||
() => () =>
|
||||
h(DropdownRoot, { defaultOpen: true, ...rootProps() }, () => [
|
||||
h(DropdownTrigger, {}, () => h(Button, () => "菜单")),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, menuProps, () => [
|
||||
h(DropdownSubmenuTrigger, { delay }, () => [
|
||||
h(
|
||||
DropdownItem,
|
||||
{ id: "share", textValue: "分享", ...itemProps() },
|
||||
() => [h(Label, () => "分享"), h(DropdownSubmenuIndicator)],
|
||||
),
|
||||
h(DropdownPopover, {}, () =>
|
||||
h(DropdownMenu, {}, () =>
|
||||
h(
|
||||
DropdownItem,
|
||||
{ id: "whatsapp", textValue: "WhatsApp" },
|
||||
() => h(Label, () => "WhatsApp"),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
function hoverMove(node: Element) {
|
||||
node.dispatchEvent(pointer("pointermove", { pointerType: "mouse" }));
|
||||
}
|
||||
|
||||
function subContent() {
|
||||
return document.querySelector("[data-submenu-content]");
|
||||
}
|
||||
|
||||
it("submenu hover opens after the baseline delay (200ms), not Reka's fixed 100ms", async () => {
|
||||
vi.useFakeTimers();
|
||||
mountSubmenuWithDelay();
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const trigger = document.querySelector(
|
||||
'[data-slot="menu-item"][data-has-submenu="true"]',
|
||||
) as HTMLElement;
|
||||
hoverMove(trigger);
|
||||
// Reka's own 100ms timer requests the open; the configured delay defers it.
|
||||
await vi.advanceTimersByTimeAsync(150);
|
||||
await nextTick();
|
||||
expect(subContent()).toBeNull();
|
||||
await vi.advanceTimersByTimeAsync(100);
|
||||
await nextTick();
|
||||
expect(subContent()).toBeTruthy();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("submenu hover honors a custom delay and pointer leave cancels it", async () => {
|
||||
vi.useFakeTimers();
|
||||
mountSubmenuWithDelay(600);
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const trigger = document.querySelector(
|
||||
'[data-slot="menu-item"][data-has-submenu="true"]',
|
||||
) as HTMLElement;
|
||||
hoverMove(trigger);
|
||||
await vi.advanceTimersByTimeAsync(400);
|
||||
await nextTick();
|
||||
expect(subContent()).toBeNull();
|
||||
trigger.dispatchEvent(pointer("pointerleave", { pointerType: "mouse" }));
|
||||
await vi.advanceTimersByTimeAsync(500);
|
||||
await nextTick();
|
||||
expect(subContent()).toBeNull();
|
||||
// A fresh hover re-arms the full delay.
|
||||
hoverMove(trigger);
|
||||
await vi.advanceTimersByTimeAsync(300);
|
||||
await nextTick();
|
||||
expect(subContent()).toBeNull();
|
||||
await vi.advanceTimersByTimeAsync(350);
|
||||
await nextTick();
|
||||
expect(subContent()).toBeTruthy();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("keyboard submenu open is immediate and cancels the pending hover open", async () => {
|
||||
vi.useFakeTimers();
|
||||
mountSubmenuWithDelay();
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
const trigger = document.querySelector(
|
||||
'[data-slot="menu-item"][data-has-submenu="true"]',
|
||||
) as HTMLElement;
|
||||
hoverMove(trigger);
|
||||
await vi.advanceTimersByTimeAsync(50);
|
||||
trigger.focus();
|
||||
trigger.dispatchEvent(
|
||||
new KeyboardEvent("keydown", {
|
||||
key: "ArrowRight",
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
}),
|
||||
);
|
||||
await flushPromises();
|
||||
await nextTick();
|
||||
expect(subContent()).toBeTruthy();
|
||||
// The cancelled hover timer must not produce a second open request later.
|
||||
await vi.advanceTimersByTimeAsync(400);
|
||||
await nextTick();
|
||||
expect(subContent()).toBeTruthy();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("click during the hover delay opens immediately", async () => {
|
||||
vi.useFakeTimers();
|
||||
mountSubmenuWithDelay(600);
|
||||
await flushPromises();
|
||||
const trigger = document.querySelector(
|
||||
'[data-has-submenu="true"]',
|
||||
) as HTMLElement;
|
||||
hoverMove(trigger);
|
||||
await vi.advanceTimersByTimeAsync(50);
|
||||
trigger.click();
|
||||
await flushPromises();
|
||||
expect(subContent()).toBeTruthy();
|
||||
});
|
||||
|
||||
it.each(["item", "menu"])(
|
||||
"disabled submenu (%s) never opens from hover",
|
||||
async (source) => {
|
||||
vi.useFakeTimers();
|
||||
mountSubmenuWithDelay(
|
||||
200,
|
||||
() => ({ isDisabled: source === "item" }),
|
||||
source === "menu" ? { disabledKeys: ["share"] } : {},
|
||||
);
|
||||
await flushPromises();
|
||||
const trigger = document.querySelector(
|
||||
'[data-has-submenu="true"]',
|
||||
) as HTMLElement;
|
||||
expect(trigger.getAttribute("aria-disabled")).toBe("true");
|
||||
hoverMove(trigger);
|
||||
await vi.advanceTimersByTimeAsync(500);
|
||||
expect(subContent()).toBeNull();
|
||||
},
|
||||
);
|
||||
|
||||
it("disabling a submenu during its hover delay prevents the pending open", async () => {
|
||||
vi.useFakeTimers();
|
||||
const disabled = ref(false);
|
||||
mountSubmenuWithDelay(600, () => ({ isDisabled: disabled.value }));
|
||||
await flushPromises();
|
||||
const trigger = document.querySelector(
|
||||
'[data-has-submenu="true"]',
|
||||
) as HTMLElement;
|
||||
hoverMove(trigger);
|
||||
await vi.advanceTimersByTimeAsync(150);
|
||||
disabled.value = true;
|
||||
await nextTick();
|
||||
await vi.advanceTimersByTimeAsync(600);
|
||||
expect(subContent()).toBeNull();
|
||||
});
|
||||
|
||||
it("closing the parent cancels a pending submenu hover", async () => {
|
||||
vi.useFakeTimers();
|
||||
const open = ref(true);
|
||||
mountSubmenuWithDelay(
|
||||
600,
|
||||
() => ({}),
|
||||
{},
|
||||
() => ({ open: open.value }),
|
||||
);
|
||||
await flushPromises();
|
||||
hoverMove(document.querySelector('[data-has-submenu="true"]')!);
|
||||
await vi.advanceTimersByTimeAsync(50);
|
||||
open.value = false;
|
||||
await nextTick();
|
||||
await vi.advanceTimersByTimeAsync(700);
|
||||
open.value = true;
|
||||
await flushPromises();
|
||||
expect(subContent()).toBeNull();
|
||||
});
|
||||
|
||||
it("a cancelled submenu click does not bypass the hover delay", async () => {
|
||||
vi.useFakeTimers();
|
||||
const click = vi.fn((event: MouseEvent) => event.preventDefault());
|
||||
mountSubmenuWithDelay(600, () => ({ onClick: click }));
|
||||
await flushPromises();
|
||||
const trigger = document.querySelector(
|
||||
'[data-has-submenu="true"]',
|
||||
) as HTMLElement;
|
||||
hoverMove(trigger);
|
||||
await vi.advanceTimersByTimeAsync(50);
|
||||
trigger.click();
|
||||
await flushPromises();
|
||||
expect(click).toHaveBeenCalledOnce();
|
||||
expect(subContent()).toBeNull();
|
||||
});
|
||||
|
||||
@@ -218,3 +218,113 @@ describe("ComboBox docs and demos", () => {
|
||||
mounted.pop();
|
||||
});
|
||||
});
|
||||
|
||||
describe("asynchronous loading demo", () => {
|
||||
class FakeIntersectionObserver {
|
||||
static instances: FakeIntersectionObserver[] = [];
|
||||
callback: (entries: unknown[]) => void;
|
||||
constructor(callback: (entries: unknown[]) => void) {
|
||||
this.callback = callback;
|
||||
FakeIntersectionObserver.instances.push(this);
|
||||
}
|
||||
observe() {}
|
||||
unobserve() {}
|
||||
disconnect() {}
|
||||
trigger(isIntersecting: boolean) {
|
||||
this.callback([{ isIntersecting }]);
|
||||
}
|
||||
static last() {
|
||||
return FakeIntersectionObserver.instances.at(-1)!;
|
||||
}
|
||||
static reset() {
|
||||
FakeIntersectionObserver.instances = [];
|
||||
}
|
||||
}
|
||||
|
||||
async function mountAsyncDemo() {
|
||||
vi.useFakeTimers();
|
||||
vi.stubGlobal("IntersectionObserver", FakeIntersectionObserver);
|
||||
FakeIntersectionObserver.reset();
|
||||
const demo = (
|
||||
await import("../apps/docs/demos/combo-box-asynchronous-loading.vue")
|
||||
).default;
|
||||
const w = mount(demo, { attachTo: document.body });
|
||||
mounted.push(w);
|
||||
// Initial page resolves on the simulated latency.
|
||||
await vi.advanceTimersByTimeAsync(350);
|
||||
await nextTick();
|
||||
(w.get('[data-slot="input"]').element as HTMLInputElement).focus();
|
||||
await nextTick();
|
||||
return w;
|
||||
}
|
||||
|
||||
const optionNames = () =>
|
||||
[...document.querySelectorAll('[role="option"]')].map((node) =>
|
||||
node.textContent?.trim(),
|
||||
);
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
vi.unstubAllGlobals();
|
||||
FakeIntersectionObserver.reset();
|
||||
});
|
||||
|
||||
it("auto-loads the next page when the sentinel intersects, without duplicate requests", async () => {
|
||||
const w = await mountAsyncDemo();
|
||||
expect(optionNames()).toHaveLength(4);
|
||||
// Two intersections in the same tick must start one request only: a
|
||||
// duplicated fetch would append the same offset twice.
|
||||
FakeIntersectionObserver.last().trigger(true);
|
||||
FakeIntersectionObserver.last().trigger(true);
|
||||
await vi.advanceTimersByTimeAsync(350);
|
||||
await nextTick();
|
||||
const afterFirst = optionNames();
|
||||
expect(afterFirst).toHaveLength(8);
|
||||
expect(new Set(afterFirst).size).toBe(8);
|
||||
// The chain fills the remaining page while the sentinel stays visible.
|
||||
await vi.advanceTimersByTimeAsync(350);
|
||||
await nextTick();
|
||||
expect(optionNames()).toHaveLength(12);
|
||||
expect(document.body.textContent).not.toContain("加载更多…");
|
||||
void w;
|
||||
});
|
||||
|
||||
it("drops stale responses when the query switches mid-flight", async () => {
|
||||
await mountAsyncDemo();
|
||||
const input = document.querySelector<HTMLInputElement>(
|
||||
'[data-slot="input"]',
|
||||
)!;
|
||||
input.value = "vader";
|
||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
await vi.advanceTimersByTimeAsync(100);
|
||||
input.value = "solo";
|
||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
await vi.advanceTimersByTimeAsync(800);
|
||||
await nextTick();
|
||||
const names = optionNames();
|
||||
expect(names).toEqual(["Han Solo"]);
|
||||
});
|
||||
|
||||
it("retries a failed page from the error state", async () => {
|
||||
const w = await mountAsyncDemo();
|
||||
const checkbox = w.get('input[type="checkbox"]');
|
||||
await checkbox.setValue(true);
|
||||
FakeIntersectionObserver.last().trigger(true);
|
||||
await vi.advanceTimersByTimeAsync(350);
|
||||
await nextTick();
|
||||
// The error row renders inside the teleported popover surface.
|
||||
expect(document.body.textContent).toContain("重试");
|
||||
expect(optionNames()).toHaveLength(4);
|
||||
await checkbox.setValue(false);
|
||||
const retry = [...document.querySelectorAll("button")].find(
|
||||
(button) => button.textContent?.trim() === "重试",
|
||||
)!;
|
||||
expect(retry).toBeTruthy();
|
||||
retry.click();
|
||||
await vi.advanceTimersByTimeAsync(350);
|
||||
await nextTick();
|
||||
expect(document.body.textContent).not.toContain("重试");
|
||||
expect(optionNames()).toHaveLength(8);
|
||||
void w;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -118,3 +118,35 @@ describe("DatePicker documentation", () => {
|
||||
expect(document.querySelectorAll('[name="time"]')).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["date-picker", "date-range-picker"])(
|
||||
"%s trigger uses actual focus-visible state",
|
||||
async (name) => {
|
||||
const Demo =
|
||||
name === "date-picker"
|
||||
? (await import("../apps/docs/demos/date-picker-basic.vue")).default
|
||||
: (await import("../apps/docs/demos/date-range-picker-basic.vue"))
|
||||
.default;
|
||||
const w = mount(Demo, { attachTo: document.body });
|
||||
wrappers.push(w);
|
||||
const trigger = w.get(`[data-slot="${name}-trigger"]`);
|
||||
let visible = false;
|
||||
const original = trigger.element.matches.bind(trigger.element);
|
||||
const spy = vi
|
||||
.spyOn(trigger.element, "matches")
|
||||
.mockImplementation((selector) =>
|
||||
selector === ":focus-visible" ? visible : original(selector),
|
||||
);
|
||||
try {
|
||||
await trigger.trigger("focus");
|
||||
expect(trigger.attributes("data-focus-visible")).toBeUndefined();
|
||||
visible = true;
|
||||
await trigger.trigger("focus");
|
||||
expect(trigger.attributes("data-focus-visible")).toBe("true");
|
||||
await trigger.trigger("blur");
|
||||
expect(trigger.attributes("data-focus-visible")).toBeUndefined();
|
||||
} finally {
|
||||
spy.mockRestore();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -463,3 +463,141 @@ it("native Switch overrides an aria Form and blocks invalid submission", async (
|
||||
expect(w.get("[role=switch]").attributes("aria-invalid")).toBe("true");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("TextField autoFocus and focus-within cover moves between child controls", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(
|
||||
TextField,
|
||||
{ autoFocus: true },
|
||||
{
|
||||
default: (state: Record<string, unknown>) => [
|
||||
h(Input),
|
||||
h("button", { type: "button" }, "inside"),
|
||||
h("output", String(state.isFocusWithin)),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
try {
|
||||
await settle();
|
||||
expect(document.activeElement).toBe(w.get("input").element);
|
||||
expect(
|
||||
w.get('[data-slot="textfield"]').attributes("data-focus-within"),
|
||||
).toBe("true");
|
||||
(w.get("button").element as HTMLButtonElement).focus();
|
||||
await settle();
|
||||
expect(w.get("output").text()).toBe("true");
|
||||
(w.get("button").element as HTMLButtonElement).blur();
|
||||
await settle();
|
||||
expect(w.get("output").text()).toBe("false");
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
it("field and Form errors merge in order, dismiss on edit/reset, and a new response reappears", async () => {
|
||||
const local = ref(["local"]),
|
||||
server = ref({ name: "server" });
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Form, { validationErrors: server.value }, () =>
|
||||
h(TextField, { name: "name", validationErrors: local.value }, () => [
|
||||
h(Input),
|
||||
h(
|
||||
FieldError,
|
||||
{},
|
||||
{
|
||||
default: (s: {
|
||||
validationErrors: string[];
|
||||
validationDetails?: ValidityState;
|
||||
}) =>
|
||||
`${s.validationErrors.join("|")}:${s.validationDetails?.customError}`,
|
||||
},
|
||||
),
|
||||
]),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
try {
|
||||
await settle();
|
||||
expect(w.get('[role="alert"]').text()).toBe("local|server:true");
|
||||
expect((w.get("input").element as HTMLInputElement).checkValidity()).toBe(
|
||||
false,
|
||||
);
|
||||
await w.get("input").setValue("edit");
|
||||
await settle();
|
||||
expect(w.find('[role="alert"]').exists()).toBe(false);
|
||||
local.value = ["new local"];
|
||||
server.value = { name: "new server" };
|
||||
await settle();
|
||||
expect(w.get('[role="alert"]').text()).toBe("new local|new server:true");
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await settle();
|
||||
expect(w.find('[role="alert"]').exists()).toBe(false);
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
it("TextField FieldError exposes native validity flags for required input", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(TextField, { isRequired: true }, () => [
|
||||
h(Input),
|
||||
h(
|
||||
FieldError,
|
||||
{},
|
||||
{
|
||||
default: (s: { validationDetails?: ValidityState }) =>
|
||||
String(s.validationDetails?.valueMissing),
|
||||
},
|
||||
),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
try {
|
||||
await settle();
|
||||
(w.get("input").element as HTMLInputElement).checkValidity();
|
||||
await settle();
|
||||
expect(w.get('[role="alert"]').text()).toBe("true");
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("TextField validity details update when native constraints change without an edit", async () => {
|
||||
const pattern = ref("[0-9]+");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(
|
||||
TextField,
|
||||
{ defaultValue: "123", pattern: pattern.value },
|
||||
{
|
||||
default: (state: { validationDetails: ValidityState }) => [
|
||||
h(Input),
|
||||
h("output", String(state.validationDetails.patternMismatch)),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
);
|
||||
try {
|
||||
await settle();
|
||||
expect(w.get("output").text()).toBe("false");
|
||||
pattern.value = "[a-z]+";
|
||||
await settle();
|
||||
expect(w.get("output").text()).toBe("true");
|
||||
pattern.value = "[0-9]+";
|
||||
await settle();
|
||||
expect(w.get("output").text()).toBe("false");
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -509,3 +509,40 @@ it.each(["changed-query", "x"])(
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("SearchField exposes value and shares field-level validation errors with Form", async () => {
|
||||
const local = ref(["local search"]),
|
||||
formErrors = ref({ q: "form search" });
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Form, { validationErrors: formErrors.value }, () =>
|
||||
h(
|
||||
SearchField,
|
||||
{ name: "q", validationErrors: local.value },
|
||||
{
|
||||
default: (s: { value: string }) => [
|
||||
h(SearchFieldGroup, {}, () => h(SearchFieldInput)),
|
||||
h(FieldError),
|
||||
h("output", s.value),
|
||||
],
|
||||
},
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
try {
|
||||
await settle();
|
||||
expect(w.get('[role="alert"]').text()).toBe("local search form search");
|
||||
await w.get("input").setValue("query");
|
||||
await settle();
|
||||
expect(w.get("output").text()).toBe("query");
|
||||
expect(w.find('[role="alert"]').exists()).toBe(false);
|
||||
local.value = ["new search"];
|
||||
await settle();
|
||||
expect(w.get('[role="alert"]').text()).toBe("new search");
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
Vendored
+97
@@ -0,0 +1,97 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, defineComponent, h, ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
ConfigProvider,
|
||||
DropdownItem,
|
||||
DropdownMenu,
|
||||
DropdownPopover,
|
||||
DropdownRoot,
|
||||
DropdownSubmenuIndicator,
|
||||
DropdownSubmenuTrigger,
|
||||
DropdownTrigger,
|
||||
Label,
|
||||
useLocale,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
/**
|
||||
* HD-10 submenu verification harness: the pinned RTL behaviour (submenu flips
|
||||
* to the left of its trigger) and the configurable hover delay, driven through
|
||||
* the public ConfigProvider direction contract.
|
||||
*/
|
||||
const rtl = ref(true);
|
||||
const disabledShare = ref(false);
|
||||
const opened = ref(0);
|
||||
const localeDir = useLocale().dir;
|
||||
const probe = computed(() => `outer-dir=${localeDir.value}`);
|
||||
const InnerProbe = defineComponent({
|
||||
setup() {
|
||||
const dir = useLocale().dir;
|
||||
return () =>
|
||||
h("output", { "data-probe-inner": "" }, `inner-dir=${dir.value}`);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main style="padding: 24px; display: grid; gap: 16px; justify-items: center">
|
||||
<label>
|
||||
<input v-model="rtl" type="checkbox" />
|
||||
RTL(ConfigProvider dir)
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="disabledShare" type="checkbox" />
|
||||
禁用分享子菜单
|
||||
</label>
|
||||
<output data-probe>{{ probe }}</output>
|
||||
<ConfigProvider :dir="rtl ? 'rtl' : 'ltr'">
|
||||
<InnerProbe />
|
||||
<div style="width: 700px; display: flex; justify-content: center">
|
||||
<DropdownRoot :dir="rtl ? 'rtl' : 'ltr'" @open-change="opened++">
|
||||
<DropdownTrigger>
|
||||
<Button aria-label="菜单">菜单</Button>
|
||||
</DropdownTrigger>
|
||||
<DropdownPopover>
|
||||
<DropdownMenu aria-label="示例菜单">
|
||||
<DropdownItem id="copy" text-value="复制">
|
||||
<Label>复制</Label>
|
||||
</DropdownItem>
|
||||
<!-- Baseline default delay: 200ms. -->
|
||||
<DropdownSubmenuTrigger>
|
||||
<DropdownItem
|
||||
id="share"
|
||||
text-value="分享"
|
||||
:is-disabled="disabledShare"
|
||||
>
|
||||
<Label>分享(默认延迟)</Label>
|
||||
<DropdownSubmenuIndicator />
|
||||
</DropdownItem>
|
||||
<DropdownPopover>
|
||||
<DropdownMenu aria-label="分享">
|
||||
<DropdownItem id="mail" text-value="邮件">
|
||||
<Label>邮件</Label>
|
||||
</DropdownItem>
|
||||
</DropdownMenu>
|
||||
</DropdownPopover>
|
||||
</DropdownSubmenuTrigger>
|
||||
<!-- Custom delay: 600ms. -->
|
||||
<DropdownSubmenuTrigger :delay="600">
|
||||
<DropdownItem id="more" text-value="更多">
|
||||
<Label>更多(600ms 延迟)</Label>
|
||||
<DropdownSubmenuIndicator />
|
||||
</DropdownItem>
|
||||
<DropdownPopover>
|
||||
<DropdownMenu aria-label="更多">
|
||||
<DropdownItem id="report" text-value="举报">
|
||||
<Label>举报</Label>
|
||||
</DropdownItem>
|
||||
</DropdownMenu>
|
||||
</DropdownPopover>
|
||||
</DropdownSubmenuTrigger>
|
||||
</DropdownMenu>
|
||||
</DropdownPopover>
|
||||
</DropdownRoot>
|
||||
</div>
|
||||
</ConfigProvider>
|
||||
</main>
|
||||
</template>
|
||||
Vendored
+134
@@ -0,0 +1,134 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
TextField,
|
||||
SearchField,
|
||||
SearchFieldGroup,
|
||||
SearchFieldInput,
|
||||
SearchFieldClearButton,
|
||||
Form,
|
||||
Label,
|
||||
Input,
|
||||
FieldError,
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSlot,
|
||||
} from "@heroui-vue/components";
|
||||
const local = ref(["字段错误"]),
|
||||
server = ref({ name: "Form错误" });
|
||||
const mounted = ref(false),
|
||||
accepted = ref(true),
|
||||
disabled = ref(false),
|
||||
readonly = ref(false);
|
||||
const otp = ref(""),
|
||||
completes = ref<string[]>([]),
|
||||
proposals = ref<string[]>([]);
|
||||
const align = ref<"left" | "center" | "right">("left");
|
||||
const strip = (text: string) => text.replaceAll("-", "");
|
||||
</script>
|
||||
<template>
|
||||
<main style="padding: 24px; display: grid; gap: 20px">
|
||||
<Form :validation-errors="server">
|
||||
<TextField
|
||||
v-slot="state"
|
||||
auto-focus
|
||||
name="name"
|
||||
:validation-errors="local"
|
||||
>
|
||||
<Label>姓名</Label>
|
||||
<Input />
|
||||
<button type="button">字段内按钮</button>
|
||||
<output id="field-state">
|
||||
{{
|
||||
JSON.stringify({
|
||||
value: state.value,
|
||||
within: state.isFocusWithin,
|
||||
visible: state.isFocusVisible,
|
||||
})
|
||||
}}
|
||||
</output>
|
||||
<FieldError v-slot="errors">
|
||||
{{ errors.validationErrors.join("|") }} /
|
||||
{{ errors.validationDetails?.customError }}
|
||||
</FieldError>
|
||||
</TextField>
|
||||
<SearchField v-slot="state" name="query">
|
||||
<Label>搜索</Label>
|
||||
<SearchFieldGroup>
|
||||
<SearchFieldInput />
|
||||
<SearchFieldClearButton />
|
||||
</SearchFieldGroup>
|
||||
<output id="search-value">{{ state.value }}</output>
|
||||
</SearchField>
|
||||
<button type="reset">重置字段</button>
|
||||
<button
|
||||
type="button"
|
||||
@click="
|
||||
local = ['新字段错误'];
|
||||
server = { name: '新Form错误' };
|
||||
"
|
||||
>
|
||||
新错误响应
|
||||
</button>
|
||||
</Form>
|
||||
<div>
|
||||
<button @click="mounted = true">挂载验证码</button>
|
||||
<label>
|
||||
<input v-model="accepted" type="checkbox" />
|
||||
接受验证码
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="disabled" type="checkbox" />
|
||||
禁用验证码
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="readonly" type="checkbox" />
|
||||
只读验证码
|
||||
</label>
|
||||
<label>
|
||||
输入对齐
|
||||
<select v-model="align">
|
||||
<option>left</option>
|
||||
<option>center</option>
|
||||
<option>right</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<Form @submit.prevent>
|
||||
<InputOTP
|
||||
v-if="mounted"
|
||||
:model-value="otp"
|
||||
:max-length="4"
|
||||
auto-focus
|
||||
required
|
||||
aria-label="验证码"
|
||||
name="code"
|
||||
:is-disabled="disabled"
|
||||
:is-read-only="readonly"
|
||||
:text-align="align"
|
||||
:paste-transformer="strip"
|
||||
pattern="^\d+$"
|
||||
@update:model-value="
|
||||
proposals.push($event);
|
||||
accepted && (otp = $event);
|
||||
"
|
||||
@complete="completes.push($event)"
|
||||
>
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot v-for="index in 4" :key="index" :index="index - 1" />
|
||||
</InputOTPGroup>
|
||||
<FieldError v-slot="state">
|
||||
{{ state.validationErrors.join("|") }} / missing={{
|
||||
state.validationDetails?.valueMissing
|
||||
}}
|
||||
</FieldError>
|
||||
</InputOTP>
|
||||
<button type="submit">校验验证码</button>
|
||||
<button type="reset">重置验证码</button>
|
||||
<button type="button" @click="otp = ''">清空验证码</button>
|
||||
</Form>
|
||||
<output id="otp-state">
|
||||
{{ JSON.stringify({ value: otp, completes, proposals }) }}
|
||||
</output>
|
||||
</main>
|
||||
</template>
|
||||
Vendored
+66
@@ -0,0 +1,66 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Link,
|
||||
Breadcrumbs,
|
||||
BreadcrumbsItem,
|
||||
ConfigProvider,
|
||||
} from "@heroui-vue/components";
|
||||
import SinglePicker from "../../apps/docs/demos/date-picker-basic.vue";
|
||||
import RangePicker from "../../apps/docs/demos/date-range-picker-basic.vue";
|
||||
const disabled = ref(true),
|
||||
locale = ref("zh-CN");
|
||||
const nativeLink = ref<{ focus: () => void }>();
|
||||
const actions = ref<(string | number)[]>([]);
|
||||
const clicks = ref(0),
|
||||
childClicks = ref(0);
|
||||
</script>
|
||||
<template>
|
||||
<main style="padding: 24px; display: grid; gap: 24px">
|
||||
<label>
|
||||
<input v-model="disabled" type="checkbox" />
|
||||
禁用链接
|
||||
</label>
|
||||
<label>
|
||||
语言
|
||||
<select v-model="locale">
|
||||
<option>zh-CN</option>
|
||||
<option>en-US</option>
|
||||
<option>fr-FR</option>
|
||||
</select>
|
||||
</label>
|
||||
<Link
|
||||
ref="nativeLink"
|
||||
id="native-link"
|
||||
href="#link-destination"
|
||||
target="_blank"
|
||||
download="example.txt"
|
||||
:is-disabled="disabled"
|
||||
@click="clicks++"
|
||||
>
|
||||
原生链接
|
||||
</Link>
|
||||
<Link id="child-link" as-child :is-disabled="disabled" @click="clicks++">
|
||||
<a
|
||||
href="#child-destination"
|
||||
target="_blank"
|
||||
download="child.txt"
|
||||
@click="childClicks++"
|
||||
>
|
||||
子链接
|
||||
</a>
|
||||
</Link>
|
||||
<button @click="nativeLink?.focus()">聚焦原生链接</button>
|
||||
<output id="link-counts">{{ clicks }}/{{ childClicks }}</output>
|
||||
<ConfigProvider :locale="locale">
|
||||
<Breadcrumbs :is-disabled="disabled" @action="actions.push($event)">
|
||||
<BreadcrumbsItem :key="0">数字零</BreadcrumbsItem>
|
||||
<BreadcrumbsItem key="">空标识</BreadcrumbsItem>
|
||||
<BreadcrumbsItem>当前页</BreadcrumbsItem>
|
||||
</Breadcrumbs>
|
||||
</ConfigProvider>
|
||||
<output id="actions">{{ JSON.stringify(actions) }}</output>
|
||||
<section id="single"><SinglePicker /></section>
|
||||
<section id="range"><RangePicker /></section>
|
||||
</main>
|
||||
</template>
|
||||
Vendored
+136
@@ -0,0 +1,136 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from "vue";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableColumn,
|
||||
TableColumnResizer,
|
||||
TableContent,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableResizableContainer,
|
||||
TableScrollContainer,
|
||||
TableSortableColumnHeader,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
/**
|
||||
* HD-08 column width verification harness: managed `fr` widths share the
|
||||
* remaining space by weight next to fixed/percent columns, min/max clamp the
|
||||
* shares, container resizing re-shares, dragging freezes the touched column
|
||||
* and RTL keeps geometry (only drag direction flips).
|
||||
*/
|
||||
const widths = [620, 900, 1400];
|
||||
const hostWidth = ref(900);
|
||||
const rtl = ref(false);
|
||||
const dark = ref(false);
|
||||
const layoutCase = ref("baseline");
|
||||
const showRows = ref(true);
|
||||
const extraColumn = ref(false);
|
||||
watch(
|
||||
dark,
|
||||
(value) => {
|
||||
document.documentElement.dataset.theme = value ? "dark" : "light";
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
const rows = [
|
||||
{ id: "1", email: "kate@acme.com", name: "Kate Moore", role: "首席执行官" },
|
||||
{ id: "2", email: "john@acme.com", name: "John Smith", role: "首席技术官" },
|
||||
{ id: "3", email: "sara@acme.com", name: "Sara Johnson", role: "首席营销官" },
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main style="padding: 24px; display: grid; gap: 16px">
|
||||
<div style="display: flex; gap: 16px">
|
||||
<label>
|
||||
边界场景
|
||||
<select v-model="layoutCase">
|
||||
<option value="baseline">常规列宽</option>
|
||||
<option value="fixed-max">固定列超出上限</option>
|
||||
<option value="invalid-fr">无效 fr 回退</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
容器宽度
|
||||
<select v-model.number="hostWidth">
|
||||
<option v-for="width in widths" :key="width" :value="width">
|
||||
{{ width }}px
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="rtl" type="checkbox" />
|
||||
RTL
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="dark" type="checkbox" />
|
||||
深色主题
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="showRows" type="checkbox" />
|
||||
显示数据
|
||||
</label>
|
||||
<label>
|
||||
<input v-model="extraColumn" type="checkbox" />
|
||||
增加列
|
||||
</label>
|
||||
</div>
|
||||
<div
|
||||
id="table-host"
|
||||
:dir="rtl ? 'rtl' : 'ltr'"
|
||||
:style="{ width: `${hostWidth}px` }"
|
||||
>
|
||||
<Table>
|
||||
<TableResizableContainer>
|
||||
<TableScrollContainer>
|
||||
<TableContent aria-label="列宽验证表格">
|
||||
<TableHeader>
|
||||
<TableColumn
|
||||
id="name"
|
||||
allows-sorting
|
||||
default-width="1fr"
|
||||
:width="layoutCase === 'invalid-fr' ? 'oopsfr' : undefined"
|
||||
:min-width="120"
|
||||
>
|
||||
<TableSortableColumnHeader>姓名</TableSortableColumnHeader>
|
||||
<TableColumnResizer />
|
||||
</TableColumn>
|
||||
<TableColumn id="role" default-width="2fr" :min-width="100">
|
||||
角色
|
||||
<TableColumnResizer />
|
||||
</TableColumn>
|
||||
<TableColumn
|
||||
id="status"
|
||||
:width="180"
|
||||
:max-width="layoutCase === 'fixed-max' ? 100 : undefined"
|
||||
>
|
||||
状态
|
||||
</TableColumn>
|
||||
<TableColumn id="email" width="20%" :max-width="240">
|
||||
邮箱
|
||||
</TableColumn>
|
||||
<TableColumn v-if="extraColumn" id="extra">附加列</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow
|
||||
v-for="row in showRows ? rows : []"
|
||||
:key="row.id"
|
||||
:row-key="row.id"
|
||||
>
|
||||
<TableCell>{{ row.name }}</TableCell>
|
||||
<TableCell>{{ row.role }}</TableCell>
|
||||
<TableCell>在职</TableCell>
|
||||
<TableCell>{{ row.email }}</TableCell>
|
||||
<TableCell v-if="extraColumn">附加内容</TableCell>
|
||||
</TableRow>
|
||||
<template #empty>未找到结果</template>
|
||||
</TableBody>
|
||||
</TableContent>
|
||||
</TableScrollContainer>
|
||||
</TableResizableContainer>
|
||||
</Table>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
Vendored
+394
@@ -0,0 +1,394 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
ref,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import {
|
||||
Button,
|
||||
Description,
|
||||
Header,
|
||||
Input,
|
||||
Label,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
ListBoxItemIndicator,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableColumn,
|
||||
TableContent,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
TableScrollContainer,
|
||||
bindVirtualRows,
|
||||
useVirtualRows,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
/**
|
||||
* HD-09 virtual layout harness: variable row heights, heading rows, loader
|
||||
* rows, gap/padding, container resizing, scroll positioning and keyboard
|
||||
* navigation across unmounted windows — with selection identity kept over
|
||||
* filtering and appends.
|
||||
*/
|
||||
const headingHeight = 32;
|
||||
const fallbackRow = 48;
|
||||
const rowHeight = (index: number) =>
|
||||
index % 3 === 0 ? 40 : index % 3 === 1 ? 64 : 80;
|
||||
|
||||
const query = ref("");
|
||||
const allItems = ref(
|
||||
Array.from({ length: 800 }, (_, index) => ({
|
||||
id: index + 1,
|
||||
textValue: `条目 ${index + 1}`,
|
||||
heading: index % 5 === 0 ? `分组 ${Math.floor(index / 5) + 1}` : undefined,
|
||||
})),
|
||||
);
|
||||
const filteredItems = computed(() => {
|
||||
const text = query.value.trim();
|
||||
if (!text) return allItems.value;
|
||||
return allItems.value.filter((item) => item.textValue.includes(text));
|
||||
});
|
||||
const selected = ref<(string | number)[]>([]);
|
||||
const listHeight = ref(320);
|
||||
const loading = ref(false);
|
||||
const estimatedRows = ref(false);
|
||||
const resolvedRowHeight = (index: number) =>
|
||||
estimatedRows.value ? undefined : rowHeight(index);
|
||||
const mixedItems = ref([
|
||||
{ id: 0, textValue: "数字零" },
|
||||
{ id: "0", textValue: "字符串零" },
|
||||
]);
|
||||
const delayedItems = ref<{ id: number; textValue: string }[]>([]);
|
||||
const StatefulItem = defineComponent({
|
||||
props: {
|
||||
item: {
|
||||
type: Object as PropType<{ id: string | number; textValue: string }>,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const born = `${typeof props.item.id}:${props.item.id}`;
|
||||
return () =>
|
||||
h(
|
||||
ListBoxItem,
|
||||
{ id: props.item.id, textValue: props.item.textValue },
|
||||
() => `当前 ${typeof props.item.id}:${props.item.id} / 创建时 ${born}`,
|
||||
);
|
||||
},
|
||||
});
|
||||
function appendItems() {
|
||||
loading.value = true;
|
||||
setTimeout(() => {
|
||||
const start = allItems.value.length;
|
||||
allItems.value = [
|
||||
...allItems.value,
|
||||
...Array.from({ length: 100 }, (_, index) => ({
|
||||
id: start + index + 1,
|
||||
textValue: `条目 ${start + index + 1}`,
|
||||
heading:
|
||||
(start + index) % 5 === 0
|
||||
? `分组 ${Math.floor((start + index) / 5) + 1}`
|
||||
: undefined,
|
||||
})),
|
||||
];
|
||||
loading.value = false;
|
||||
}, 300);
|
||||
}
|
||||
function selectFarItem() {
|
||||
selected.value = [allItems.value[600]?.id ?? 601];
|
||||
listboxRef.value?.focus(selected.value[0] as never);
|
||||
}
|
||||
const listboxRef = ref<{ focus: (key?: never) => void } | null>(null);
|
||||
|
||||
// ---- variable-height table window ----
|
||||
const tableCount = ref(300);
|
||||
const unknownTableRows = ref(false);
|
||||
const tableWidth = ref(800);
|
||||
const tableRowHeight = (index: number) =>
|
||||
unknownTableRows.value ? undefined : index % 2 ? 44 : 72;
|
||||
const tableRows = useVirtualRows({
|
||||
count: () => tableCount.value,
|
||||
keys: () => Array.from({ length: tableCount.value }, (_, i) => i + 1),
|
||||
rowHeight: tableRowHeight,
|
||||
estimatedRowHeight: fallbackRow,
|
||||
loaderHeight: 40,
|
||||
gap: 4,
|
||||
padding: 12,
|
||||
overscan: 6,
|
||||
});
|
||||
const tableWindow = tableRows.window;
|
||||
const tableItems = computed(() =>
|
||||
Array.from({ length: tableCount.value }, (_, index) => ({
|
||||
id: index + 1,
|
||||
name: `行 ${index + 1}`,
|
||||
})),
|
||||
);
|
||||
const visibleTableRows = computed(() =>
|
||||
tableItems.value.slice(tableWindow.value.start, tableWindow.value.end),
|
||||
);
|
||||
const scrollRef = ref<HTMLElement | null>(null);
|
||||
const scrollElement = () => scrollRef.value;
|
||||
function jumpToRow(index: number) {
|
||||
const element = scrollElement();
|
||||
if (element) tableRows.scrollToIndex(element, index);
|
||||
}
|
||||
let detach: (() => void) | undefined;
|
||||
onMounted(() => {
|
||||
const element = scrollElement();
|
||||
if (element)
|
||||
detach = bindVirtualRows(tableRows, element, {
|
||||
content: element.querySelector("tbody") ?? undefined,
|
||||
});
|
||||
});
|
||||
onUnmounted(() => detach?.());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main style="padding: 24px; display: grid; gap: 24px">
|
||||
<section style="display: grid; gap: 8px">
|
||||
<h2>可变行高 / 分组 / 加载行 / gap / padding</h2>
|
||||
<div style="display: flex; gap: 8px; align-items: center">
|
||||
<Label for="virtual-filter">过滤</Label>
|
||||
<Input
|
||||
id="virtual-filter"
|
||||
:model-value="query"
|
||||
placeholder="按文本过滤…"
|
||||
@update:model-value="query = $event"
|
||||
/>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
@click="listHeight = listHeight === 320 ? 520 : 320"
|
||||
>
|
||||
容器高度 {{ listHeight }}
|
||||
</Button>
|
||||
<Button size="sm" variant="secondary" @click="appendItems">
|
||||
追加 100 项
|
||||
</Button>
|
||||
<Button size="sm" variant="secondary" @click="selectFarItem">
|
||||
选中并定位第 601 项
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
@click="estimatedRows = !estimatedRows"
|
||||
>
|
||||
切换未知行高
|
||||
</Button>
|
||||
</div>
|
||||
<ListBox
|
||||
id="virtual-listbox"
|
||||
ref="listboxRef"
|
||||
:items="filteredItems"
|
||||
v-model="selected"
|
||||
selection-mode="multiple"
|
||||
virtualized
|
||||
:row-height="resolvedRowHeight"
|
||||
:estimated-row-height="fallbackRow"
|
||||
:heading-height="estimatedRows ? () => undefined : headingHeight"
|
||||
:estimated-heading-height="32"
|
||||
:loader-height="40"
|
||||
:gap="8"
|
||||
:padding="12"
|
||||
:style="{
|
||||
height: listHeight + 'px',
|
||||
width: '320px',
|
||||
overflowY: 'auto',
|
||||
}"
|
||||
aria-label="虚拟行验证列表"
|
||||
>
|
||||
<template #default="{ item }">
|
||||
<ListBoxItem
|
||||
:id="item.id"
|
||||
:text-value="item.textValue"
|
||||
:style="{ height: estimatedRows ? 'auto' : '100%' }"
|
||||
>
|
||||
<div style="display: flex; flex-direction: column">
|
||||
<Label>{{ item.textValue }}</Label>
|
||||
<Description>高度随索引变化</Description>
|
||||
<Description v-if="estimatedRows">
|
||||
{{ "这是一段需要自动换行的未知高度内容。".repeat(6) }}
|
||||
</Description>
|
||||
</div>
|
||||
<ListBoxItemIndicator />
|
||||
</ListBoxItem>
|
||||
</template>
|
||||
<template #loader>
|
||||
<div
|
||||
data-slot="virtual-loader"
|
||||
style="display: flex; align-items: center; justify-content: center"
|
||||
>
|
||||
<Button size="sm" variant="ghost" @click="appendItems">
|
||||
加载更多…
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
</ListBox>
|
||||
<p data-probe-selected>已选:{{ selected.join(",") || "无" }}</p>
|
||||
</section>
|
||||
<section>
|
||||
<h2>不同类型 key 的局部状态</h2>
|
||||
<Button @click="mixedItems = [...mixedItems].reverse()">
|
||||
反转零标识
|
||||
</Button>
|
||||
<ListBox
|
||||
:items="mixedItems"
|
||||
virtualized
|
||||
:row-height="50"
|
||||
:overscan="5"
|
||||
style="height: 160px; overflow-y: auto"
|
||||
aria-label="零标识列表"
|
||||
>
|
||||
<template #default="{ item }"><StatefulItem :item="item" /></template>
|
||||
</ListBox>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<Button
|
||||
@click="
|
||||
delayedItems = Array.from({ length: 200 }, (_, i) => ({
|
||||
id: i + 1,
|
||||
textValue: `延后条目 ${i + 1}`,
|
||||
}))
|
||||
"
|
||||
>
|
||||
加载父容器列表
|
||||
</Button>
|
||||
<div
|
||||
data-probe-late-viewport
|
||||
style="height: 200px; width: 320px; overflow-y: auto"
|
||||
>
|
||||
<div style="height: 48px; position: sticky; top: 0">固定搜索区域</div>
|
||||
<ListBox
|
||||
:items="delayedItems"
|
||||
virtualized
|
||||
:row-height="50"
|
||||
aria-label="延后加载列表"
|
||||
>
|
||||
<template #default="{ item }">
|
||||
<ListBoxItem
|
||||
:id="item.id"
|
||||
:text-value="item.textValue"
|
||||
style="height: 50px"
|
||||
>
|
||||
{{ item.textValue }}
|
||||
</ListBoxItem>
|
||||
</template>
|
||||
</ListBox>
|
||||
</div>
|
||||
</section>
|
||||
<section style="display: grid; gap: 8px">
|
||||
<h2>表格虚拟窗口(useVirtualRows)</h2>
|
||||
<div style="display: flex; gap: 8px">
|
||||
<Button @click="unknownTableRows = !unknownTableRows">
|
||||
切换表格未知行高
|
||||
</Button>
|
||||
<Button @click="tableWidth = tableWidth === 800 ? 520 : 800">
|
||||
表格宽度 {{ tableWidth }}
|
||||
</Button>
|
||||
<Button size="sm" variant="secondary" @click="jumpToRow(149)">
|
||||
定位第 150 行
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
@click="tableCount = tableCount === 300 ? 600 : 300"
|
||||
>
|
||||
行数 {{ tableCount }}
|
||||
</Button>
|
||||
</div>
|
||||
<Table>
|
||||
<TableScrollContainer>
|
||||
<div
|
||||
ref="scrollRef"
|
||||
data-slot="table-virtual-viewport"
|
||||
:style="{
|
||||
height: '300px',
|
||||
width: `${tableWidth}px`,
|
||||
overflow: 'auto',
|
||||
}"
|
||||
>
|
||||
<TableContent
|
||||
aria-label="可变行高表格"
|
||||
style="min-width: 520px; table-layout: fixed"
|
||||
:aria-rowcount="tableCount + 1"
|
||||
:row-keys="tableItems.map((row) => row.id)"
|
||||
@focus-row="(_key, index) => jumpToRow(index)"
|
||||
>
|
||||
<TableHeader aria-rowindex="1">
|
||||
<TableColumn id="name" is-row-header :min-width="160">
|
||||
名称
|
||||
</TableColumn>
|
||||
<TableColumn id="info" :min-width="200">说明</TableColumn>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<tr
|
||||
aria-hidden="true"
|
||||
:style="{ height: tableWindow.padTop + 'px' }"
|
||||
/>
|
||||
<template v-for="row in visibleTableRows" :key="row.id">
|
||||
<TableRow
|
||||
:row-key="row.id"
|
||||
:aria-rowindex="row.id + 1"
|
||||
:ref="(node) => tableRows.measureRow(row.id - 1, node)"
|
||||
:height="tableRowHeight(row.id - 1)"
|
||||
>
|
||||
<TableCell>{{ row.name }}</TableCell>
|
||||
<TableCell>
|
||||
{{
|
||||
unknownTableRows
|
||||
? "需要测量的表格内容,宽度改变后会重新换行。".repeat(
|
||||
10,
|
||||
)
|
||||
: "行高 44/72 交替"
|
||||
}}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<tr
|
||||
v-if="row.id < tableCount"
|
||||
aria-hidden="true"
|
||||
style="height: 4px"
|
||||
/>
|
||||
</template>
|
||||
<tr
|
||||
v-if="tableWindow.end < tableCount"
|
||||
aria-hidden="true"
|
||||
:style="{ height: tableWindow.padBottom + 'px' }"
|
||||
/>
|
||||
<template v-else>
|
||||
<tr
|
||||
v-if="tableCount"
|
||||
aria-hidden="true"
|
||||
style="height: 4px"
|
||||
/>
|
||||
<tr role="presentation">
|
||||
<td colspan="2" style="padding: 0">
|
||||
<div
|
||||
role="status"
|
||||
data-probe-table-loader
|
||||
style="
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
"
|
||||
>
|
||||
加载更多…
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr aria-hidden="true" style="height: 12px" />
|
||||
</template>
|
||||
</TableBody>
|
||||
</TableContent>
|
||||
</div>
|
||||
</TableScrollContainer>
|
||||
</Table>
|
||||
</section>
|
||||
</main>
|
||||
</template>
|
||||
+250
-1
@@ -219,7 +219,7 @@ describe("InputOTP value model", () => {
|
||||
});
|
||||
|
||||
describe("InputOTP pattern and states", () => {
|
||||
it("filters characters with REGEXP_ONLY_CHARS and digits constants", async () => {
|
||||
it("checks candidates with REGEXP_ONLY_CHARS and digits constants", async () => {
|
||||
expect(REGEXP_ONLY_DIGITS).toBe("^\\d+$");
|
||||
expect(REGEXP_ONLY_CHARS).toBe("^[a-zA-Z]+$");
|
||||
expect(REGEXP_ONLY_DIGITS_AND_CHARS).toBe("^[a-zA-Z0-9]+$");
|
||||
@@ -540,3 +540,252 @@ describe("InputOTP types", () => {
|
||||
expect((bad as { variant?: string }).variant).toBe("ghost");
|
||||
});
|
||||
});
|
||||
|
||||
function pasteInto(input: Element, text: string) {
|
||||
const event = new Event("paste", { bubbles: true, cancelable: true });
|
||||
Object.defineProperty(event, "clipboardData", {
|
||||
value: { getData: () => text },
|
||||
});
|
||||
input.dispatchEvent(event);
|
||||
}
|
||||
const settleOtp = async () => {
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
};
|
||||
function enhancedOtp(
|
||||
props: Record<string, unknown> = {},
|
||||
slots: Record<string, unknown> = {},
|
||||
) {
|
||||
return mount(InputOTP, {
|
||||
props: { maxLength: 4, ...props },
|
||||
slots: {
|
||||
default: () =>
|
||||
h(InputOTPGroup, {}, () =>
|
||||
[0, 1, 2, 3].map((index) => h(InputOTPSlot, { index })),
|
||||
),
|
||||
...slots,
|
||||
},
|
||||
attachTo: document.body,
|
||||
});
|
||||
}
|
||||
it("OTP autoFocus and textAlign reach actual inputs without leaking root props", async () => {
|
||||
const w = enhancedOtp({ autoFocus: true, textAlign: "right" });
|
||||
try {
|
||||
await settleOtp();
|
||||
expect(document.activeElement).toBe(slotInputs(w)[0].element);
|
||||
expect((slotInputs(w)[0].element as HTMLInputElement).style.textAlign).toBe(
|
||||
"right",
|
||||
);
|
||||
expect(w.attributes("textalign")).toBeUndefined();
|
||||
await w.setProps({ textAlign: "center" });
|
||||
expect((slotInputs(w)[3].element as HTMLInputElement).style.textAlign).toBe(
|
||||
"center",
|
||||
);
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
it.each(["isDisabled", "isReadOnly"])(
|
||||
"OTP %s prevents paste transformation and edits",
|
||||
async (flag) => {
|
||||
const transform = vi.fn((text: string) => text.replaceAll("-", ""));
|
||||
const w = enhancedOtp({
|
||||
[flag]: true,
|
||||
defaultValue: "12",
|
||||
pasteTransformer: transform,
|
||||
autoFocus: true,
|
||||
});
|
||||
try {
|
||||
await settleOtp();
|
||||
pasteInto(slotInputs(w)[0].element, "34-56");
|
||||
await settleOtp();
|
||||
expect(transform).not.toHaveBeenCalled();
|
||||
expect(
|
||||
slotInputs(w)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("12");
|
||||
if (flag === "isDisabled")
|
||||
expect(w.element.contains(document.activeElement)).toBe(false);
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
},
|
||||
);
|
||||
it("OTP transforms paste before whole-value pattern checking and restores rejected DOM values", async () => {
|
||||
const w = enhancedOtp({
|
||||
pattern: "^12[0-9]*$",
|
||||
defaultValue: "12",
|
||||
pasteTransformer: (t: string) => t.replaceAll("-", ""),
|
||||
});
|
||||
try {
|
||||
pasteInto(slotInputs(w)[0].element, "12-34");
|
||||
await settleOtp();
|
||||
expect(
|
||||
slotInputs(w).map((i) => (i.element as HTMLInputElement).value),
|
||||
).toEqual(["1", "2", "3", "4"]);
|
||||
expect(document.activeElement).toBe(slotInputs(w)[3].element);
|
||||
expect((slotInputs(w)[3].element as HTMLInputElement).selectionStart).toBe(
|
||||
0,
|
||||
);
|
||||
await slotInputs(w)[2].setValue("8");
|
||||
await settleOtp();
|
||||
expect(
|
||||
slotInputs(w)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("1284");
|
||||
await slotInputs(w)[0].setValue("9");
|
||||
await settleOtp();
|
||||
expect(
|
||||
slotInputs(w)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("1284");
|
||||
pasteInto(slotInputs(w)[0].element, "90-12");
|
||||
await settleOtp();
|
||||
expect(
|
||||
slotInputs(w)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("1284");
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
it("OTP rejects an invalid paste as one edit and honors consumer cancellation", async () => {
|
||||
const w = enhancedOtp({ pattern: REGEXP_ONLY_DIGITS, defaultValue: "12" });
|
||||
try {
|
||||
pasteInto(slotInputs(w)[0].element, "3a45");
|
||||
await settleOtp();
|
||||
expect(
|
||||
slotInputs(w)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("12");
|
||||
const transform = vi.fn((t: string) => t);
|
||||
await w.setProps({ pasteTransformer: transform });
|
||||
const slot = w.element;
|
||||
slot.addEventListener("paste", (e: Event) => e.preventDefault(), {
|
||||
capture: true,
|
||||
});
|
||||
pasteInto(slotInputs(w)[0].element, "5678");
|
||||
await settleOtp();
|
||||
expect(transform).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
it("OTP complete follows accepted threshold crossings, including external updates, rather than rejected drafts", async () => {
|
||||
const w = enhancedOtp({ modelValue: "12" });
|
||||
try {
|
||||
pasteInto(slotInputs(w)[0].element, "1234");
|
||||
await settleOtp();
|
||||
pasteInto(slotInputs(w)[0].element, "1234");
|
||||
await settleOtp();
|
||||
expect(w.emitted("update:modelValue")).toHaveLength(2);
|
||||
expect(w.emitted("complete")).toBeUndefined();
|
||||
expect(
|
||||
slotInputs(w)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("12");
|
||||
await w.setProps({ modelValue: "1234" });
|
||||
await settleOtp();
|
||||
expect(w.emitted("complete")).toEqual([["1234"]]);
|
||||
await w.setProps({ modelValue: "9876" });
|
||||
await settleOtp();
|
||||
pasteInto(slotInputs(w)[0].element, "9876");
|
||||
await settleOtp();
|
||||
expect(w.emitted("complete")).toHaveLength(1);
|
||||
await w.setProps({ modelValue: "" });
|
||||
await settleOtp();
|
||||
await w.setProps({ modelValue: "4567" });
|
||||
await settleOtp();
|
||||
expect(w.emitted("complete")).toEqual([["1234"], ["4567"]]);
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
it("OTP passes caller ValidityState through shared FieldError without emitting it on the DOM", async () => {
|
||||
const { FieldError } = await import("../packages/vue/src");
|
||||
const details = {
|
||||
badInput: false,
|
||||
customError: true,
|
||||
patternMismatch: false,
|
||||
rangeOverflow: false,
|
||||
rangeUnderflow: false,
|
||||
stepMismatch: false,
|
||||
tooLong: false,
|
||||
tooShort: false,
|
||||
typeMismatch: false,
|
||||
valid: false,
|
||||
valueMissing: false,
|
||||
};
|
||||
const w = enhancedOtp(
|
||||
{
|
||||
isInvalid: true,
|
||||
validationDetails: details,
|
||||
validationErrors: ["server"],
|
||||
},
|
||||
{
|
||||
default: () => [
|
||||
h(InputOTPGroup, {}, () =>
|
||||
[0, 1, 2, 3].map((index) => h(InputOTPSlot, { index })),
|
||||
),
|
||||
h(
|
||||
FieldError,
|
||||
{},
|
||||
{
|
||||
default: (s: { validationDetails?: ValidityState }) =>
|
||||
String(s.validationDetails?.customError),
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
);
|
||||
try {
|
||||
await settleOtp();
|
||||
expect(w.get('[data-slot="field-error"]').text()).toBe("true");
|
||||
expect(w.attributes("validationdetails")).toBeUndefined();
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("OTP native required validation shares FieldError details and clears on an effective edit", async () => {
|
||||
const { FieldError } = await import("../packages/vue/src");
|
||||
const w = enhancedOtp(
|
||||
{ required: true },
|
||||
{
|
||||
default: () => [
|
||||
h(InputOTPGroup, {}, () =>
|
||||
[0, 1, 2, 3].map((index) => h(InputOTPSlot, { index })),
|
||||
),
|
||||
h(
|
||||
FieldError,
|
||||
{},
|
||||
{
|
||||
default: (s: { validationDetails?: ValidityState }) =>
|
||||
String(s.validationDetails?.valueMissing),
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
);
|
||||
try {
|
||||
await settleOtp();
|
||||
const proxy = w.get('input[aria-hidden="true"]')
|
||||
.element as HTMLInputElement;
|
||||
expect(proxy.checkValidity()).toBe(false);
|
||||
await settleOtp();
|
||||
expect(w.get('[role="alert"]').text()).toBe("true");
|
||||
await slotInputs(w)[0].setValue("1");
|
||||
await settleOtp();
|
||||
expect(w.find('[role="alert"]').exists()).toBe(false);
|
||||
expect(proxy.checkValidity()).toBe(true);
|
||||
} finally {
|
||||
w.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
MenuItemIndicator,
|
||||
MenuItemSubmenuIndicator,
|
||||
MenuSection,
|
||||
type DropdownSubmenuTriggerProps,
|
||||
type DropdownRootProps,
|
||||
type DropdownMenuProps,
|
||||
type DropdownItemProps,
|
||||
@@ -103,3 +104,9 @@ export const values = {
|
||||
badVariant,
|
||||
badIndicator,
|
||||
};
|
||||
|
||||
const submenuDelay: DropdownSubmenuTriggerProps = { delay: 600 };
|
||||
// @ts-expect-error submenu hover delay is a number of milliseconds
|
||||
const badSubmenuDelay: DropdownSubmenuTriggerProps = { delay: "slow" };
|
||||
void submenuDelay;
|
||||
void badSubmenuDelay;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user