feat: migrate Pagination Header and InputOTP with field and event regressions
This commit is contained in:
@@ -378,4 +378,10 @@ Vaul Vue 官方已说明停止维护并推荐 Reka Drawer;新项目不采用 V
|
||||
- 子树观察只监听必要的 childList/subtree,不观察自身 tabindex 写入,不建立全局 document 导航队列。根变更/卸载时断开观察;SSR 不访问浏览器全局。
|
||||
- 焦点所有者的 tabindex 通过渲染期属性合并绑定。无所有者时保留调用方及 asChild 原生子项属性,不在 setRoot/watch 中无条件 removeAttribute;Vue patch 与命令式写同一属性会形成两个状态来源。
|
||||
- 用户根事件必须合并而非被对象展开后的内部事件覆盖;处理器数组由 Vue DOM 事件层执行,取消/捕获/stopImmediatePropagation 都要回归。动态 attrs 在渲染时读取,不保存不可失效的快照。
|
||||
- M29 最终验收见 [Toolbar 报告](docs/migrations/M29-toolbar.md)。下一批待派发为 [M30 Pagination](docs/migrations/M30-pagination-prompt.md),计划不代表已经实现。
|
||||
- M29 最终验收见 [Toolbar 报告](docs/migrations/M29-toolbar.md)。下一批改为 [M30–M32 Pagination → Header → InputOTP](docs/migrations/M30-pagination-prompt.md),逐项实现验证,三项一起交回复核;计划不代表已经实现。InputOTP 可消费现有字段协议,但不能自行改写共享内核,真实缺口交最小失败用例由集成人处理。
|
||||
|
||||
## 后续分支与分工(2026-10-23)
|
||||
|
||||
- 用户要求:每个新任务批次先 fetch、切 main、pull --ff-only,再从最新 main 新建任务分支;不在 main 开发,不把未提交源码带到下一任务,不通过 reset/强推绕过分叉。已有三张本地 PNG 保留且不提交。
|
||||
- 集成人负责 ListBox/Select、DateField/Calendar、ColorArea/ColorPicker 三类基建。其他 AI 的下一批是 [M33–M34 AlertDialog → Drawer](docs/migrations/M33-M34-alert-dialog-drawer-prompt.md),使用 feat/m33-m34-alert-dialog-drawer 新分支;该计划不代表组件已实现。
|
||||
- M30–M32 返修按最终验收报告归档。可访问名称应检查 ARIA 优先级:底座默认 aria-label 能覆盖原生 for;仅检查 id/for 存在不足以验收真实名称。事件适配中的阶段差异也必须记录。
|
||||
|
||||
@@ -70,13 +70,16 @@ const groups = [
|
||||
{ title: "EmptyState 空状态", url: "/components/empty-state" },
|
||||
{ title: "FieldError 字段错误", url: "/components/field-error" },
|
||||
{ title: "Fieldset 字段组", url: "/components/fieldset" },
|
||||
{ title: "Header 标题", url: "/components/header" },
|
||||
{ title: "Input 输入框", url: "/components/input" },
|
||||
{ title: "InputOTP 验证码输入", url: "/components/input-otp" },
|
||||
{ title: "InputGroup 输入框组", url: "/components/input-group" },
|
||||
{ title: "Kbd 键盘按键", url: "/components/kbd" },
|
||||
{ title: "Label 标签", url: "/components/label" },
|
||||
{ title: "Link 链接", url: "/components/link" },
|
||||
{ title: "Meter 计量条", url: "/components/meter" },
|
||||
{ title: "Modal 模态框", url: "/components/modal" },
|
||||
{ title: "Pagination 分页", url: "/components/pagination" },
|
||||
{ title: "Popover 弹出框", url: "/components/popover" },
|
||||
{ title: "ProgressBar 进度条", url: "/components/progress-bar" },
|
||||
{
|
||||
|
||||
@@ -52,3 +52,7 @@ description: 已迁移组件及文档
|
||||
- [Toolbar 工具栏](./components/toolbar)
|
||||
- [ToggleButton 切换按钮](./components/toggle-button)
|
||||
- [ToggleButtonGroup 切换按钮组](./components/toggle-button-group)
|
||||
|
||||
- [Pagination 分页](./components/pagination)
|
||||
- [Header 标题](./components/header)
|
||||
- [InputOTP 验证码输入](./components/input-otp)
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
---
|
||||
title: Header 标题
|
||||
description: 集合或分组的区块标题部件,用于菜单、列表等结构中的分组说明。
|
||||
component: header
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Header } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Header>操作</Header>
|
||||
</template>
|
||||
```
|
||||
|
||||
<ComponentPreview name="header-basic" />
|
||||
|
||||
> **说明:** 固定 HeroUI 基线没有独立的 Header 中文组件页或专属演示目录。本页与下方示例为自编,用于说明语义、默认样式与自定义方式;不是官方文案的完整复刻。
|
||||
|
||||
## 组件结构
|
||||
|
||||
`Header` 是集合/分组标题部件,不是带 Logo、导航和用户菜单的应用顶栏。固定基线的 React Aria Components `Header` 渲染原生 `<header>` 元素(不是任意 heading 级别),常出现在 Dropdown、ListBox、ComboBox、Autocomplete 的分组中。
|
||||
|
||||
Vue 版导出 `Header` 与 `HeaderRoot`(同一实现)。菜单 / ListBox 尚未迁移时,可用语义容器解释组合边界,例如在分组列表或表单分区前放置标题:
|
||||
|
||||
<ComponentPreview name="header-semantic" />
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { Header } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section>
|
||||
<Header>发票列表</Header>
|
||||
<ul>
|
||||
<li>INV-1001</li>
|
||||
</ul>
|
||||
</section>
|
||||
</template>
|
||||
```
|
||||
|
||||
## 示例
|
||||
|
||||
### 自定义 class
|
||||
|
||||
<ComponentPreview name="header-custom-class" />
|
||||
|
||||
`class` 合并到 `<header>` 根元素,可覆盖字号、颜色与间距。
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-header {
|
||||
@apply text-sm font-semibold text-foreground;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
- `.hv-header` - 根元素(`w-full px-2 pt-1.5 pb-1 text-start text-xs font-medium text-muted`)
|
||||
|
||||
## API 参考
|
||||
|
||||
### Header / HeaderRoot
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ---------- | ---------------- |
|
||||
| `as` | `string` | `'header'` | 自定义根元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 标题内容 |
|
||||
|
||||
根元素同时接收其余 `$attrs`(`aria-*`、`data-*`、`id`、`style`、事件等)。本组件没有业务值,不提供 `v-model`、表单提交或焦点状态。
|
||||
|
||||
### 上游差异
|
||||
|
||||
| 上游 React 能力 | Vue 实现 |
|
||||
| --------------------------- | ------------------------------------------ |
|
||||
| `Header.Root` 对象子部件 | 独立具名导出 `Header` / `HeaderRoot` |
|
||||
| RAC Collection 叶子节点 | 语义 HTML 封装;集合上下文由未来菜单族提供 |
|
||||
| `className` / `children` | `class` / 默认插槽 |
|
||||
| `render` / `DOMRenderProps` | `as` 更换元素,属性直接透传 |
|
||||
|
||||
## 无障碍
|
||||
|
||||
- 默认渲染原生 `<header>`,与固定基线 RAC Header 一致;不强制 heading 级别。
|
||||
- 不自动附加 `role` 或 `aria-level`;分组语义由所在集合(Menu / ListBox 等)提供。需要文档标题层级时,请在应用侧使用真正的 `h1`–`h6` 或 `aria-labelledby`。
|
||||
- 真实读屏表现未在本轮验证。
|
||||
|
||||
## 相关组件
|
||||
|
||||
- [Typography 排版](./typography)
|
||||
- [EmptyState 空状态](./empty-state)
|
||||
@@ -0,0 +1,192 @@
|
||||
---
|
||||
title: InputOTP 验证码输入
|
||||
description: 一次性验证码输入:分格槽位、分组分隔、模式过滤与完成事件。
|
||||
component: input-otp
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<InputOTP :max-length="6">
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="3" />
|
||||
<InputOTPSlot :index="4" />
|
||||
<InputOTPSlot :index="5" />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
</template>
|
||||
```
|
||||
|
||||
<ComponentPreview name="input-otp-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
上游交互来自 React 的 `input-otp` 包(单隐藏 input)。Vue 版以安装版 **Reka PinInput** 为底座(多 input),内部 DOM 与上游不同,但可感知行为、表单值与可访问名称按基线验收。公开值为**字符串**;内部为**按索引的字符数组**,空位保留原索引,后续字符不会左移。
|
||||
|
||||
导出 `InputOTP`(即 `InputOTPRoot`)、`InputOTPGroup`、`InputOTPSlot`、`InputOTPSeparator`,以及正则常量 `REGEXP_ONLY_DIGITS`、`REGEXP_ONLY_CHARS`、`REGEXP_ONLY_DIGITS_AND_CHARS`。
|
||||
|
||||
### 字符串与字符数组的转换规则
|
||||
|
||||
- 槽位 `i` 对应字符串下标 `i`:`value[i]` 显示在 `InputOTPSlot :index="i"`。
|
||||
- 内部数组长度为 `maxLength`,空槽为 `""`;删除中间槽位时后续字符仍在原索引,UI 不左移。
|
||||
- 序列化为公开字符串时按索引 `join("")`,空槽在字符串中被省略(字符串紧凑)。槽位 UI 始终读数组,不从紧凑字符串反推,因此中间空位不会把后面的字符拉到前面。
|
||||
- 父组件回写我们发出的同一字符串时保留内部数组(含中间空位);父组件写入**不同**字符串时按左到右密排展开。
|
||||
|
||||
## 示例
|
||||
|
||||
### 尺寸变体
|
||||
|
||||
<ComponentPreview name="input-otp-variants" />
|
||||
|
||||
### Surface 上的次要变体
|
||||
|
||||
<ComponentPreview name="input-otp-on-surface" />
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="input-otp-disabled" />
|
||||
|
||||
### 四位 PIN
|
||||
|
||||
<ComponentPreview name="input-otp-four-digits" />
|
||||
|
||||
### 受控
|
||||
|
||||
<ComponentPreview name="input-otp-controlled" />
|
||||
|
||||
`v-model` 为字符串。父级拒绝更新时实际输入会恢复。
|
||||
|
||||
### 完成事件
|
||||
|
||||
<ComponentPreview name="input-otp-on-complete" />
|
||||
|
||||
`@complete` 在**首次填满**时触发一次;替换已满值、重复同值或父级同步同一值不会重复触发。示例使用模拟验证(定时器),不发送真实验证码。
|
||||
|
||||
### 表单示例
|
||||
|
||||
<ComponentPreview name="input-otp-form-example" />
|
||||
|
||||
表单提交一份完整字符串值(`name` 映射)。模拟校验 `123456`;卸载时清理定时器。
|
||||
|
||||
### 模式过滤
|
||||
|
||||
<ComponentPreview name="input-otp-with-pattern" />
|
||||
|
||||
`pattern` 过滤单字符输入,可使用导出的正则常量。
|
||||
|
||||
### 表单验证
|
||||
|
||||
<ComponentPreview name="input-otp-with-validation" />
|
||||
|
||||
### 自定义样式
|
||||
|
||||
<ComponentPreview name="input-otp-custom-styles" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
`inputClassName` 落在真实 `<input>` 上;视觉槽位用 `class` 落在 `InputOTPSlot` 根节点。二者不会合并到同一节点。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-input-otp__slot {
|
||||
@apply rounded-lg border-accent;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
类名前缀为 `hv-`。
|
||||
|
||||
- `.hv-input-otp` / `.hv-input-otp--primary` / `.hv-input-otp--secondary`
|
||||
- `.hv-input-otp__group` / `.hv-input-otp__slot` / `.hv-input-otp__slot-value`
|
||||
- `.hv-input-otp__caret` / `.hv-input-otp__separator` / `.hv-input-otp__input`
|
||||
|
||||
状态:`data-active`、`data-filled`、`data-disabled`、`data-invalid`、`data-complete`。
|
||||
|
||||
## API 参考
|
||||
|
||||
### 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 自动关联首格 |
|
||||
|
||||
事件:`update:modelValue` / `change`(字符串)、`complete`(首次填满)。
|
||||
|
||||
### InputOTPGroup / InputOTPSeparator
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | -------- | ------ | ----------- |
|
||||
| `class` | `string` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | Slot 或内容 |
|
||||
|
||||
### InputOTPSlot
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------- | -------- | ------ | -------------------- |
|
||||
| `index` | `number` | 必填 | 槽位索引,从 0 开始 |
|
||||
| `class` | `string` | - | 附加到视觉槽位根节点 |
|
||||
|
||||
### 上游差异
|
||||
|
||||
| 上游 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 自动填充 |
|
||||
|
||||
## 字段与表单
|
||||
|
||||
- 复用既有 `fieldContextKey`:Label `for` 指向控件 id,Description / FieldError 可关联;`isInvalid` / `validationErrors` 驱动展示。
|
||||
- 不复制第二套字段、错误或 reset 内核。真实 `FormData` 只有一份完整字符串值;禁用时省略。
|
||||
- 受控 reset 保留父级值;非受控恢复初始值。取消原生 reset 保留当前值;专项回归断言真实 input 与唯一 FormData 值。
|
||||
|
||||
Slot 的 keydown/paste 用户处理器在底座编辑前的 capture 边界协调取消,事件阶段与普通 div 的 bubble 处理存在差异;其他 DOM 事件正常透传。
|
||||
|
||||
## 无障碍
|
||||
|
||||
- 每个槽位是真实 `<input>`,`autocomplete="one-time-code"`(或 `otp` 时更完整);隐藏 input 供表单提交,`aria-hidden`。
|
||||
- Label 通过 `for` 关联首格,并通过 `aria-labelledby` 给所有实际输入命名;外置标签使用显式 `aria-labelledby`。底座默认名称不会覆盖字段名称。
|
||||
- 真实设备上的短信/密码管理器自动填充、IME 与触屏行为**未在本轮验证**,不能按属性存在宣布验收。
|
||||
- 读屏表现未验证。
|
||||
|
||||
## 相关组件
|
||||
|
||||
- [TextField 文本输入框](./text-field)
|
||||
- [Label 标签](./label)
|
||||
- [FieldError 字段错误](./field-error)
|
||||
@@ -0,0 +1,296 @@
|
||||
---
|
||||
title: Pagination 分页
|
||||
description: 分页导航:可组合的页码链接、上一页/下一页按钮与省略号指示器。
|
||||
component: pagination
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination>
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationLink is-active>1</PaginationLink>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
```
|
||||
|
||||
<ComponentPreview name="pagination-basic" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
导入 Pagination 各具名组件后组合使用。根组件同时以 `Pagination` 与 `PaginationRoot` 导出,二者是同一实现。
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationEllipsis,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
PaginationSummary,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination>
|
||||
<PaginationSummary>显示第 1–10 条,共 100 条结果</PaginationSummary>
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious>
|
||||
<PaginationPreviousIcon />
|
||||
<span>上一页</span>
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationLink is-active>1</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationEllipsis />
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationLink>10</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationNext>
|
||||
<span>下一页</span>
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
```
|
||||
|
||||
根 `Pagination` 渲染为带 `aria-label="pagination"` 与 `role="navigation"` 的 `nav`,`Content` 为 `ul`,`Item` 为 `li`。根组件是组合式导航容器,不管理 `total` / `page` 状态;受控示例的页码由示例自身维护。
|
||||
|
||||
`Link` / `Previous` / `Next` 在固定基线使用 React Aria Button(原生 `button`,默认 `type="button"`),不是 `a`。名字叫 Link 但语义是按钮。
|
||||
|
||||
## 示例
|
||||
|
||||
### 尺寸
|
||||
|
||||
<ComponentPreview name="pagination-sizes" />
|
||||
|
||||
### 禁用
|
||||
|
||||
<ComponentPreview name="pagination-disabled" />
|
||||
|
||||
`isDisabled` 禁用按钮的原生激活与点击;页码链接仍可单独控制。
|
||||
|
||||
### 简化(上一页 / 下一页)
|
||||
|
||||
<ComponentPreview name="pagination-simple-prev-next" />
|
||||
|
||||
### 受控组件
|
||||
|
||||
<ComponentPreview name="pagination-controlled" />
|
||||
|
||||
页码列表、省略号与摘要区间由示例根据 `page` 计算;组件根不额外实现分页状态机。
|
||||
|
||||
### 带省略号
|
||||
|
||||
<ComponentPreview name="pagination-with-ellipsis" />
|
||||
|
||||
### 带摘要
|
||||
|
||||
<ComponentPreview name="pagination-with-summary" />
|
||||
|
||||
### 自定义图标
|
||||
|
||||
可通过向 `PreviousIcon` 与 `NextIcon` 传入默认插槽替换默认 chevron 图标。空插槽回退到基线 SVG;图标包裹层始终 `aria-hidden="true"`。
|
||||
|
||||
<ComponentPreview name="pagination-custom-icons" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="pagination-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
若要自定义组件类,可使用 `@layer components` 指令。[了解更多](https://tailwindcss.com/docs/adding-custom-styles#adding-component-classes)。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-pagination {
|
||||
@apply gap-8;
|
||||
}
|
||||
|
||||
.hv-pagination__link {
|
||||
@apply rounded-md;
|
||||
}
|
||||
|
||||
.hv-pagination__summary {
|
||||
@apply text-xs font-semibold;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
Pagination 使用以下 CSS 类:
|
||||
|
||||
#### 基础与布局类 [!toc]
|
||||
|
||||
- `.hv-pagination` - 根导航容器(flex 布局)
|
||||
- `.hv-pagination__summary` - 左侧信息文本容器
|
||||
- `.hv-pagination__content` - 分页项容器
|
||||
- `.hv-pagination__item` - 单个分页项包裹层
|
||||
- `.hv-pagination__link` - 页码按钮(ghost 按钮样式)
|
||||
- `.hv-pagination__link--nav` - 导航按钮修饰符(Previous/Next)
|
||||
- `.hv-pagination__ellipsis` - 省略号指示器
|
||||
|
||||
#### 尺寸类 [!toc]
|
||||
|
||||
- `.hv-pagination--sm` - 小尺寸变体
|
||||
- `.hv-pagination--md` - 中尺寸变体(默认)
|
||||
- `.hv-pagination--lg` - 大尺寸变体
|
||||
|
||||
### 交互状态
|
||||
|
||||
组件同时支持 CSS 伪类与 data 属性,便于灵活定制:
|
||||
|
||||
- **Active page**:`[data-active="true"]` 或 `[aria-current="page"]`
|
||||
- **Hover**:`:hover` 或 `[data-hovered="true"]`
|
||||
- **Focus**:`:focus-visible` 或 `[data-focus-visible="true"]`
|
||||
- **Disabled**:`:disabled` 或 `[aria-disabled="true"]`
|
||||
- **Pressed**:`:active` 或 `[data-pressed="true"]`
|
||||
|
||||
## API 参考
|
||||
|
||||
### Pagination / PaginationRoot
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------- | ------------------------------- |
|
||||
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 分页控件的尺寸 |
|
||||
| `as` | `string` | `'nav'` | 自定义根元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
| 默认插槽 | - | - | 分页部件(Summary、Content 等) |
|
||||
|
||||
根元素同时接收其余 `$attrs`(`aria-*`、`data-*`、事件等)。未显式传入时默认 `aria-label="pagination"` 与 `role="navigation"`;显式属性优先。
|
||||
|
||||
### PaginationSummary
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------- | -------------------------------------------- |
|
||||
| `as` | `string` | `'div'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 摘要内容(例如 “显示第 1–10 条,共 120 条”) |
|
||||
|
||||
默认 `dir="auto"`,按摘要自身文本检测方向,避免 RTL 祖先重排数字/中英混排;显式传入 `dir` 时覆盖。
|
||||
|
||||
### PaginationContent
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | -------------- |
|
||||
| `as` | `string` | `'ul'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 分页项 |
|
||||
|
||||
### PaginationItem
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | -------------------------------- |
|
||||
| `as` | `string` | `'li'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | Link、Previous、Next 或 Ellipsis |
|
||||
|
||||
### PaginationLink
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | --------------------------- | ---------- | ---------------------------------------------------------------- |
|
||||
| `isActive` | `boolean` | `false` | 是否为当前页;输出 `aria-current="page"` 与 `data-active="true"` |
|
||||
| `isDisabled` | `boolean` | `false` | 是否禁用按钮 |
|
||||
| `type` | `string` | `'button'` | 原生按钮 type |
|
||||
| `asChild` | `boolean` | `false` | 将属性合并到唯一子元素 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 页码内容 |
|
||||
|
||||
激活状态取消时移除 `aria-current` 与 `data-active`。显式传入的 `aria-current` 等 ARIA 在未激活时保留调用方值;激活时组件写入 `aria-current="page"`。
|
||||
|
||||
### PaginationPrevious / PaginationNext
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------------ | --------------------------- | ---------- | ------------------------------------------- |
|
||||
| `isDisabled` | `boolean` | `false` | 是否禁用按钮 |
|
||||
| `type` | `string` | `'button'` | 原生按钮 type |
|
||||
| `asChild` | `boolean` | `false` | 将属性合并到唯一子元素 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | - | 按钮内容(可与 PreviousIcon/NextIcon 组合) |
|
||||
|
||||
两者附加 `hv-pagination__link--nav` 修饰类,不带入普通 Button 的 variant 类。
|
||||
|
||||
### PaginationPreviousIcon / PaginationNextIcon
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ---------------- | ----------------------------- |
|
||||
| `as` | `string` | `'span'` | 自定义包裹元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
| 默认插槽 | - | 默认 chevron SVG | 替换默认 chevron 的自定义图标 |
|
||||
|
||||
包裹层始终 `aria-hidden="true"`。默认图标从 HeroUI `icons.tsx`(Apache-2.0)移植。
|
||||
|
||||
### PaginationEllipsis
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ------- | --------------------------- | -------- | -------------- |
|
||||
| `as` | `string` | `'span'` | 自定义元素标签 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
|
||||
|
||||
始终渲染 `…`,带 `aria-hidden="true"`,与上游一致不接受自定义子内容。
|
||||
|
||||
### 上游差异
|
||||
|
||||
| 上游 React 能力 | Vue 实现 |
|
||||
| ---------------------------- | -------------------------------------------------- |
|
||||
| `Pagination.Link` 对象子部件 | 独立具名导出 `PaginationLink` 等 |
|
||||
| `onPress` | 原生 `@click`;原生 button 的 Enter/Space 单次激活 |
|
||||
| `className` / `children` | `class` / 默认插槽 |
|
||||
| `render` / `DOMRenderProps` | `as` 更换元素,属性直接透传 |
|
||||
| 根 `v-model` / 自动页码计算 | 无;固定基线是组合式 nav 容器,页码由示例维护 |
|
||||
|
||||
## 说明
|
||||
|
||||
- 上游 Pagination 按钮使用 React Aria 的 `onPress`。Vue 版使用原生 `button` 与 `@click`:Enter/Space 触发一次原生 click,禁用时不激活,调用方可用 `preventDefault` / `stopPropagation` / 处理器数组 / `stopImmediatePropagation` 控制事件,组件不再手动重复模拟 click。
|
||||
- 分页按钮不复用共享 Button 的 variant 类,只使用 `hv-pagination__link` 族样式,避免带入无关默认外观。
|
||||
|
||||
## 无障碍
|
||||
|
||||
- 语义化 `<nav>` 元素,包含 `aria-label="pagination"` 与 `role="navigation"`(均可被显式属性覆盖)
|
||||
- 当前页链接使用 `aria-current="page"` 与 `data-active="true"`
|
||||
- Tab 键在全部可交互元素间导航(原生按钮)
|
||||
- 键盘激活时通过 `:focus-visible` 显示焦点环
|
||||
- 省略号与图标使用 `aria-hidden="true"`,避免干扰屏幕阅读器
|
||||
- 通过 `isDisabled` / 原生 `disabled` 向辅助技术正确传达禁用状态
|
||||
|
||||
真实键盘激活与焦点环在浏览器验证;jsdom 测试只覆盖 DOM/ARIA 与事件合并,不冒充浏览器已验收。
|
||||
|
||||
## 相关组件
|
||||
|
||||
- [Button 按钮](./button)
|
||||
- [Breadcrumbs 面包屑](./breadcrumbs)
|
||||
- [Separator 分隔符](./separator)
|
||||
@@ -0,0 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { Header } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-full max-w-sm flex-col gap-1 rounded-xl bg-surface p-2">
|
||||
<Header>操作</Header>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg px-2 py-1.5 text-start text-sm hover:bg-surface-secondary"
|
||||
>
|
||||
复制
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg px-2 py-1.5 text-start text-sm hover:bg-surface-secondary"
|
||||
>
|
||||
粘贴
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { Header } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-full max-w-sm flex-col gap-1 rounded-xl bg-surface p-2">
|
||||
<Header class="text-xs font-semibold uppercase tracking-wide text-accent">
|
||||
危险区域
|
||||
</Header>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-lg px-2 py-1.5 text-start text-sm text-danger hover:bg-danger-soft"
|
||||
>
|
||||
删除项目
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { Header } from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="flex w-full max-w-md flex-col gap-2">
|
||||
<Header>发票列表</Header>
|
||||
<ul class="flex flex-col gap-1">
|
||||
<li class="rounded-lg bg-surface px-3 py-2 text-sm">INV-1001</li>
|
||||
<li class="rounded-lg bg-surface px-3 py-2 text-sm">INV-1002</li>
|
||||
</ul>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
Link,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
import { useId } from "vue";
|
||||
const otpLabelId = useId();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-[280px] flex-col gap-2">
|
||||
<div class="flex flex-col gap-1">
|
||||
<Label :id="otpLabelId">验证账户</Label>
|
||||
<p class="text-sm text-muted">我们已向 a****@gmail.com 发送验证码</p>
|
||||
</div>
|
||||
<InputOTP :aria-labelledby="otpLabelId" :max-length="6">
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="3" />
|
||||
<InputOTPSlot :index="4" />
|
||||
<InputOTPSlot :index="5" />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
<div class="flex items-center gap-[5px] px-1 pt-1">
|
||||
<p class="text-sm text-muted">没有收到验证码?</p>
|
||||
<Link class="text-foreground underline" href="#">重新发送</Link>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Description,
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const value = ref("");
|
||||
|
||||
import { useId } from "vue";
|
||||
const otpDescriptionId = useId();
|
||||
const otpLabelId = useId();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-[280px] flex-col gap-2">
|
||||
<Label :id="otpLabelId">验证账户</Label>
|
||||
<InputOTP
|
||||
:aria-describedby="otpDescriptionId"
|
||||
:aria-labelledby="otpLabelId"
|
||||
v-model="value"
|
||||
:max-length="6"
|
||||
>
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="3" />
|
||||
<InputOTPSlot :index="4" />
|
||||
<InputOTPSlot :index="5" />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
<Description :id="otpDescriptionId">
|
||||
<template v-if="value.length > 0">
|
||||
值:{{ value }} ({{ value.length }}/6) •
|
||||
<button
|
||||
class="font-medium text-foreground underline"
|
||||
type="button"
|
||||
@click="value = ''"
|
||||
>
|
||||
清空
|
||||
</button>
|
||||
</template>
|
||||
<template v-else>请输入 6 位验证码</template>
|
||||
</Description>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
Link,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const slotClass =
|
||||
"rounded-lg border-border/80 bg-default data-[active=true]:border-accent/40 data-[active=true]:bg-accent-soft";
|
||||
|
||||
import { useId } from "vue";
|
||||
const otpLabelId = useId();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-72 flex-col gap-2">
|
||||
<Label :id="otpLabelId">验证账户</Label>
|
||||
<InputOTP :aria-labelledby="otpLabelId" :max-length="6">
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :class="slotClass" :index="0" />
|
||||
<InputOTPSlot :class="slotClass" :index="1" />
|
||||
<InputOTPSlot :class="slotClass" :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator class="bg-border" />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :class="slotClass" :index="3" />
|
||||
<InputOTPSlot :class="slotClass" :index="4" />
|
||||
<InputOTPSlot :class="slotClass" :index="5" />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
<Link class="text-sm text-link" href="#">重新发送</Link>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Description,
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
import { useId } from "vue";
|
||||
const otpDescriptionId = useId();
|
||||
const otpLabelId = useId();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-[280px] flex-col gap-2">
|
||||
<Label :id="otpLabelId" is-disabled>验证账户</Label>
|
||||
<Description :id="otpDescriptionId">验证码校验当前已禁用</Description>
|
||||
<InputOTP
|
||||
:aria-describedby="otpDescriptionId"
|
||||
:aria-labelledby="otpLabelId"
|
||||
is-disabled
|
||||
:max-length="6"
|
||||
>
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="3" />
|
||||
<InputOTPSlot :index="4" />
|
||||
<InputOTPSlot :index="5" />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,94 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, ref, useId } from "vue";
|
||||
import {
|
||||
Button,
|
||||
Description,
|
||||
FieldError,
|
||||
Form,
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
Link,
|
||||
Spinner,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const value = ref("");
|
||||
const error = ref("");
|
||||
const isSubmitting = ref(false);
|
||||
const errorId = useId();
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
onBeforeUnmount(() => clearTimeout(timer));
|
||||
|
||||
function handleSubmit(event: Event) {
|
||||
event.preventDefault();
|
||||
error.value = "";
|
||||
if (value.value.length !== 6) {
|
||||
error.value = "请输入全部 6 位数字";
|
||||
return;
|
||||
}
|
||||
isSubmitting.value = true;
|
||||
// Demo-only simulated verification; no external service is called.
|
||||
timer = setTimeout(() => {
|
||||
if (value.value === "123456") {
|
||||
value.value = "";
|
||||
} else {
|
||||
error.value = "验证码无效,请重试。";
|
||||
}
|
||||
isSubmitting.value = false;
|
||||
}, 1500);
|
||||
}
|
||||
|
||||
function handleChange() {
|
||||
error.value = "";
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Form class="flex w-[280px] flex-col gap-4" @submit="handleSubmit">
|
||||
<InputOTP
|
||||
v-model="value"
|
||||
:is-invalid="!!error"
|
||||
:max-length="6"
|
||||
:validation-errors="error ? [error] : []"
|
||||
style="flex-direction: column; align-items: stretch; gap: 0.5rem"
|
||||
@update:model-value="handleChange"
|
||||
>
|
||||
<Label>双重身份验证</Label>
|
||||
<Description>请输入身份验证器应用中的 6 位验证码</Description>
|
||||
<div class="flex items-center gap-2">
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="3" />
|
||||
<InputOTPSlot :index="4" />
|
||||
<InputOTPSlot :index="5" />
|
||||
</InputOTPGroup>
|
||||
</div>
|
||||
<FieldError :id="errorId" />
|
||||
</InputOTP>
|
||||
<Button
|
||||
class="w-full"
|
||||
:is-disabled="value.length !== 6"
|
||||
:is-pending="isSubmitting"
|
||||
type="submit"
|
||||
variant="primary"
|
||||
>
|
||||
<template v-if="isSubmitting">
|
||||
<Spinner color="current" size="sm" />
|
||||
验证中…
|
||||
</template>
|
||||
<template v-else>验证</template>
|
||||
</Button>
|
||||
<div class="flex items-center justify-center gap-1">
|
||||
<p class="text-sm text-muted">遇到问题?</p>
|
||||
<Link class="text-sm text-foreground underline" href="#">使用备用码</Link>
|
||||
</div>
|
||||
</Form>
|
||||
</template>
|
||||
@@ -0,0 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
import { useId } from "vue";
|
||||
const otpLabelId = useId();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-[280px] flex-col gap-2">
|
||||
<Label :id="otpLabelId">输入 PIN</Label>
|
||||
<InputOTP :aria-labelledby="otpLabelId" :max-length="4">
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
<InputOTPSlot :index="3" />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,77 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
Spinner,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const value = ref("");
|
||||
const isComplete = ref(false);
|
||||
const isSubmitting = ref(false);
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
onBeforeUnmount(() => clearTimeout(timer));
|
||||
|
||||
function handleComplete(code: string) {
|
||||
isComplete.value = true;
|
||||
// Demo-only: no network request.
|
||||
console.log("Code complete:", code);
|
||||
}
|
||||
|
||||
function handleSubmit(event: Event) {
|
||||
event.preventDefault();
|
||||
isSubmitting.value = true;
|
||||
timer = setTimeout(() => {
|
||||
isSubmitting.value = false;
|
||||
value.value = "";
|
||||
isComplete.value = false;
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
import { useId } from "vue";
|
||||
const otpLabelId = useId();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Form class="flex w-[280px] flex-col gap-2" @submit="handleSubmit">
|
||||
<Label :id="otpLabelId">验证账户</Label>
|
||||
<InputOTP
|
||||
:aria-labelledby="otpLabelId"
|
||||
v-model="value"
|
||||
:max-length="6"
|
||||
@complete="handleComplete"
|
||||
@update:model-value="isComplete = false"
|
||||
>
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="3" />
|
||||
<InputOTPSlot :index="4" />
|
||||
<InputOTPSlot :index="5" />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
<Button
|
||||
class="mt-2 w-full"
|
||||
:is-disabled="!isComplete"
|
||||
:is-pending="isSubmitting"
|
||||
type="submit"
|
||||
variant="primary"
|
||||
>
|
||||
<template v-if="isSubmitting">
|
||||
<Spinner color="current" size="sm" />
|
||||
验证中…
|
||||
</template>
|
||||
<template v-else>验证验证码</template>
|
||||
</Button>
|
||||
</Form>
|
||||
</template>
|
||||
@@ -0,0 +1,40 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
Link,
|
||||
Surface,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
import { useId } from "vue";
|
||||
const otpLabelId = useId();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Surface class="flex w-full flex-col gap-2 rounded-3xl p-6">
|
||||
<div class="flex flex-col gap-1">
|
||||
<Label :id="otpLabelId">验证账户</Label>
|
||||
<p class="text-sm text-muted">我们已向 a****@gmail.com 发送验证码</p>
|
||||
</div>
|
||||
<InputOTP :aria-labelledby="otpLabelId" :max-length="6" variant="secondary">
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="3" />
|
||||
<InputOTPSlot :index="4" />
|
||||
<InputOTPSlot :index="5" />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
<div class="flex items-center gap-[5px] px-1 pt-1">
|
||||
<p class="text-sm text-muted">没有收到验证码?</p>
|
||||
<Link class="text-foreground underline" href="#">重新发送</Link>
|
||||
</div>
|
||||
</Surface>
|
||||
</template>
|
||||
@@ -0,0 +1,58 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
import { useId } from "vue";
|
||||
const otpLabelId0 = useId();
|
||||
const otpLabelId1 = useId();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-6">
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label :id="otpLabelId0">主要变体</Label>
|
||||
<InputOTP
|
||||
:aria-labelledby="otpLabelId0"
|
||||
:max-length="6"
|
||||
variant="primary"
|
||||
>
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="3" />
|
||||
<InputOTPSlot :index="4" />
|
||||
<InputOTPSlot :index="5" />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label :id="otpLabelId1">次要变体</Label>
|
||||
<InputOTP
|
||||
:aria-labelledby="otpLabelId1"
|
||||
:max-length="6"
|
||||
variant="secondary"
|
||||
>
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="3" />
|
||||
<InputOTPSlot :index="4" />
|
||||
<InputOTPSlot :index="5" />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,40 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Description,
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
REGEXP_ONLY_CHARS,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
import { useId } from "vue";
|
||||
const otpDescriptionId = useId();
|
||||
const otpLabelId = useId();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-[280px] flex-col gap-2">
|
||||
<Label :id="otpLabelId">输入验证码(仅字母)</Label>
|
||||
<Description :id="otpDescriptionId">仅允许输入字母</Description>
|
||||
<InputOTP
|
||||
:aria-describedby="otpDescriptionId"
|
||||
:aria-labelledby="otpLabelId"
|
||||
:max-length="6"
|
||||
:pattern="REGEXP_ONLY_CHARS"
|
||||
>
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="3" />
|
||||
<InputOTPSlot :index="4" />
|
||||
<InputOTPSlot :index="5" />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,70 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, useId } from "vue";
|
||||
import {
|
||||
Button,
|
||||
Description,
|
||||
FieldError,
|
||||
Form,
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const value = ref("");
|
||||
const isInvalid = ref(false);
|
||||
const errorId = useId();
|
||||
|
||||
function onSubmit(event: Event) {
|
||||
event.preventDefault();
|
||||
const form = event.target as HTMLFormElement;
|
||||
const data = new FormData(form);
|
||||
const code = data.get("code");
|
||||
if (code !== "123456") {
|
||||
isInvalid.value = true;
|
||||
return;
|
||||
}
|
||||
isInvalid.value = false;
|
||||
value.value = "";
|
||||
alert("验证码校验成功!");
|
||||
}
|
||||
|
||||
function handleChange() {
|
||||
isInvalid.value = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex w-[280px] flex-col gap-2">
|
||||
<Form class="flex flex-col gap-2" @submit="onSubmit">
|
||||
<InputOTP
|
||||
v-model="value"
|
||||
:is-invalid="isInvalid"
|
||||
:max-length="6"
|
||||
:validation-errors="isInvalid ? ['验证码无效,请重试。'] : []"
|
||||
name="code"
|
||||
style="flex-direction: column; align-items: stretch; gap: 0.5rem"
|
||||
@update:model-value="handleChange"
|
||||
>
|
||||
<Label>验证账户</Label>
|
||||
<Description>提示:验证码为 123456</Description>
|
||||
<div class="flex items-center gap-2">
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="0" />
|
||||
<InputOTPSlot :index="1" />
|
||||
<InputOTPSlot :index="2" />
|
||||
</InputOTPGroup>
|
||||
<InputOTPSeparator />
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot :index="3" />
|
||||
<InputOTPSlot :index="4" />
|
||||
<InputOTPSlot :index="5" />
|
||||
</InputOTPGroup>
|
||||
</div>
|
||||
<FieldError :id="errorId" />
|
||||
</InputOTP>
|
||||
<Button :is-disabled="value.length !== 6" type="submit">提交</Button>
|
||||
</Form>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const page = ref(1);
|
||||
const totalPages = 3;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination class="justify-center">
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious :is-disabled="page === 1" @click="page = page - 1">
|
||||
<PaginationPreviousIcon />
|
||||
<span>上一页</span>
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<PaginationItem v-for="p in totalPages" :key="p">
|
||||
<PaginationLink :is-active="p === page" @click="page = p">
|
||||
{{ p }}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
:is-disabled="page === totalPages"
|
||||
@click="page = page + 1"
|
||||
>
|
||||
<span>下一页</span>
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
@@ -0,0 +1,92 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationEllipsis,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
PaginationSummary,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const page = ref(1);
|
||||
const totalPages = 12;
|
||||
const itemsPerPage = 10;
|
||||
const totalItems = 120;
|
||||
|
||||
const pages = computed(() => {
|
||||
const list: (number | "ellipsis")[] = [];
|
||||
|
||||
if (totalPages <= 7) {
|
||||
for (let i = 1; i <= totalPages; i++) {
|
||||
list.push(i);
|
||||
}
|
||||
} else {
|
||||
list.push(1);
|
||||
|
||||
if (page.value > 3) {
|
||||
list.push("ellipsis");
|
||||
}
|
||||
|
||||
const start = Math.max(2, page.value - 1);
|
||||
const end = Math.min(totalPages - 1, page.value + 1);
|
||||
|
||||
for (let i = start; i <= end; i++) {
|
||||
list.push(i);
|
||||
}
|
||||
|
||||
if (page.value < totalPages - 2) {
|
||||
list.push("ellipsis");
|
||||
}
|
||||
|
||||
list.push(totalPages);
|
||||
}
|
||||
|
||||
return list;
|
||||
});
|
||||
|
||||
const startItem = computed(() => (page.value - 1) * itemsPerPage + 1);
|
||||
const endItem = computed(() => Math.min(page.value * itemsPerPage, totalItems));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination>
|
||||
<PaginationSummary>
|
||||
显示第 {{ startItem }}–{{ endItem }} 条,共 {{ totalItems }} 条结果
|
||||
</PaginationSummary>
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious :is-disabled="page === 1" @click="page = page - 1">
|
||||
<PaginationPreviousIcon />
|
||||
<span>上一页</span>
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<template
|
||||
v-for="(p, i) in pages"
|
||||
:key="p === 'ellipsis' ? `ellipsis-${i}` : p"
|
||||
>
|
||||
<PaginationItem v-if="p === 'ellipsis'">
|
||||
<PaginationEllipsis />
|
||||
</PaginationItem>
|
||||
<PaginationItem v-else>
|
||||
<PaginationLink :is-active="p === page" @click="page = p">
|
||||
{{ p }}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
</template>
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
:is-disabled="page === totalPages"
|
||||
@click="page = page + 1"
|
||||
>
|
||||
<span>下一页</span>
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { IconArrowLeft, IconArrowRight } from "@tabler/icons-vue";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const page = ref(1);
|
||||
const totalPages = 3;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination class="justify-center">
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious :is-disabled="page === 1" @click="page = page - 1">
|
||||
<PaginationPreviousIcon>
|
||||
<IconArrowLeft aria-hidden="true" :size="16" />
|
||||
</PaginationPreviousIcon>
|
||||
<span>返回</span>
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<PaginationItem v-for="p in totalPages" :key="p">
|
||||
<PaginationLink :is-active="p === page" @click="page = p">
|
||||
{{ p }}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
:is-disabled="page === totalPages"
|
||||
@click="page = page + 1"
|
||||
>
|
||||
<span>前进</span>
|
||||
<PaginationNextIcon>
|
||||
<IconArrowRight aria-hidden="true" :size="16" />
|
||||
</PaginationNextIcon>
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const page = ref(2);
|
||||
const linkClass = "text-muted hover:bg-surface hover:text-foreground";
|
||||
const activeClass = "bg-accent text-accent-foreground hover:bg-accent-hover";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination class="justify-center">
|
||||
<PaginationContent class="gap-1 rounded-xl bg-default p-1">
|
||||
<PaginationItem>
|
||||
<PaginationPrevious
|
||||
:class="linkClass"
|
||||
:is-disabled="page === 1"
|
||||
@click="page = page - 1"
|
||||
>
|
||||
<PaginationPreviousIcon />
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<PaginationItem v-for="p in 3" :key="p">
|
||||
<PaginationLink
|
||||
:class="p === page ? activeClass : linkClass"
|
||||
:is-active="p === page"
|
||||
@click="page = p"
|
||||
>
|
||||
{{ p }}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
:class="linkClass"
|
||||
:is-disabled="page === 3"
|
||||
@click="page = page + 1"
|
||||
>
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
@@ -0,0 +1,40 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const page = ref(1);
|
||||
const totalPages = 3;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination class="justify-center">
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious is-disabled @click="page = page - 1">
|
||||
<PaginationPreviousIcon />
|
||||
<span>上一页</span>
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<PaginationItem v-for="p in totalPages" :key="p">
|
||||
<PaginationLink :is-active="p === page" @click="page = p">
|
||||
{{ p }}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationNext is-disabled @click="page = page + 1">
|
||||
<span>下一页</span>
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
@@ -0,0 +1,46 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
PaginationSummary,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const page = ref(1);
|
||||
const totalPages = 10;
|
||||
const itemsPerPage = 5;
|
||||
const totalItems = 50;
|
||||
|
||||
const startItem = computed(() => (page.value - 1) * itemsPerPage + 1);
|
||||
const endItem = computed(() => Math.min(page.value * itemsPerPage, totalItems));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination class="w-full">
|
||||
<PaginationSummary>
|
||||
第 {{ startItem }}–{{ endItem }} 条,共 {{ totalItems }} 张发票
|
||||
</PaginationSummary>
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious :is-disabled="page === 1" @click="page = page - 1">
|
||||
<PaginationPreviousIcon />
|
||||
<span>上一页</span>
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
:is-disabled="page === totalPages"
|
||||
@click="page = page + 1"
|
||||
>
|
||||
<span>下一页</span>
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
@@ -0,0 +1,62 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const totalPages = 3;
|
||||
const smPage = ref(1);
|
||||
const mdPage = ref(1);
|
||||
const lgPage = ref(1);
|
||||
|
||||
const groups = [
|
||||
{ key: "sm", label: "小", page: smPage },
|
||||
{ key: "md", label: "中", page: mdPage },
|
||||
{ key: "lg", label: "大", page: lgPage },
|
||||
] as const;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-6">
|
||||
<div v-for="group in groups" :key="group.key" class="flex flex-col gap-2">
|
||||
<span class="text-xs font-medium text-muted">{{ group.label }}</span>
|
||||
<Pagination class="justify-center" :size="group.key">
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious
|
||||
:is-disabled="group.page.value === 1"
|
||||
@click="group.page.value = group.page.value - 1"
|
||||
>
|
||||
<PaginationPreviousIcon />
|
||||
<span>上一页</span>
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<PaginationItem v-for="p in totalPages" :key="p">
|
||||
<PaginationLink
|
||||
:is-active="p === group.page.value"
|
||||
@click="group.page.value = p"
|
||||
>
|
||||
{{ p }}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
:is-disabled="group.page.value === totalPages"
|
||||
@click="group.page.value = group.page.value + 1"
|
||||
>
|
||||
<span>下一页</span>
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,82 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationEllipsis,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const page = ref(1);
|
||||
const totalPages = 12;
|
||||
|
||||
const pages = computed(() => {
|
||||
const list: (number | "ellipsis")[] = [];
|
||||
|
||||
list.push(1);
|
||||
|
||||
if (page.value > 3) {
|
||||
list.push("ellipsis");
|
||||
}
|
||||
|
||||
const start = Math.max(2, page.value - 1);
|
||||
const end = Math.min(totalPages - 1, page.value + 1);
|
||||
|
||||
for (let i = start; i <= end; i++) {
|
||||
list.push(i);
|
||||
}
|
||||
|
||||
if (page.value < totalPages - 2) {
|
||||
list.push("ellipsis");
|
||||
}
|
||||
|
||||
list.push(totalPages);
|
||||
|
||||
return list;
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="w-full max-w-2xs overflow-x-auto sm:max-w-full">
|
||||
<Pagination class="justify-center">
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious
|
||||
:is-disabled="page === 1"
|
||||
@click="page = page - 1"
|
||||
>
|
||||
<PaginationPreviousIcon />
|
||||
<span>上一页</span>
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<template
|
||||
v-for="(p, i) in pages"
|
||||
:key="p === 'ellipsis' ? `ellipsis-${i}` : p"
|
||||
>
|
||||
<PaginationItem v-if="p === 'ellipsis'">
|
||||
<PaginationEllipsis />
|
||||
</PaginationItem>
|
||||
<PaginationItem v-else>
|
||||
<PaginationLink :is-active="p === page" @click="page = p">
|
||||
{{ p }}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
</template>
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
:is-disabled="page === totalPages"
|
||||
@click="page = page + 1"
|
||||
>
|
||||
<span>下一页</span>
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,86 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationEllipsis,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
PaginationSummary,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const page = ref(1);
|
||||
const totalPages = 12;
|
||||
const itemsPerPage = 10;
|
||||
const totalItems = 120;
|
||||
|
||||
const pages = computed(() => {
|
||||
const list: (number | "ellipsis")[] = [];
|
||||
|
||||
list.push(1);
|
||||
|
||||
if (page.value > 3) {
|
||||
list.push("ellipsis");
|
||||
}
|
||||
|
||||
const start = Math.max(2, page.value - 1);
|
||||
const end = Math.min(totalPages - 1, page.value + 1);
|
||||
|
||||
for (let i = start; i <= end; i++) {
|
||||
list.push(i);
|
||||
}
|
||||
|
||||
if (page.value < totalPages - 2) {
|
||||
list.push("ellipsis");
|
||||
}
|
||||
|
||||
list.push(totalPages);
|
||||
|
||||
return list;
|
||||
});
|
||||
|
||||
const startItem = computed(() => (page.value - 1) * itemsPerPage + 1);
|
||||
const endItem = computed(() => Math.min(page.value * itemsPerPage, totalItems));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Pagination class="w-full">
|
||||
<PaginationSummary>
|
||||
显示第 {{ startItem }}–{{ endItem }} 条,共 {{ totalItems }} 条结果
|
||||
</PaginationSummary>
|
||||
<PaginationContent>
|
||||
<PaginationItem>
|
||||
<PaginationPrevious :is-disabled="page === 1" @click="page = page - 1">
|
||||
<PaginationPreviousIcon />
|
||||
<span>上一页</span>
|
||||
</PaginationPrevious>
|
||||
</PaginationItem>
|
||||
<template
|
||||
v-for="(p, i) in pages"
|
||||
:key="p === 'ellipsis' ? `ellipsis-${i}` : p"
|
||||
>
|
||||
<PaginationItem v-if="p === 'ellipsis'">
|
||||
<PaginationEllipsis />
|
||||
</PaginationItem>
|
||||
<PaginationItem v-else>
|
||||
<PaginationLink :is-active="p === page" @click="page = p">
|
||||
{{ p }}
|
||||
</PaginationLink>
|
||||
</PaginationItem>
|
||||
</template>
|
||||
<PaginationItem>
|
||||
<PaginationNext
|
||||
:is-disabled="page === totalPages"
|
||||
@click="page = page + 1"
|
||||
>
|
||||
<span>下一页</span>
|
||||
<PaginationNextIcon />
|
||||
</PaginationNext>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
</template>
|
||||
+11
-3
@@ -65,10 +65,10 @@
|
||||
| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) |
|
||||
| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 |
|
||||
| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 |
|
||||
| header | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| header | 验证中(M31) | Header/HeaderRoot;原生 `<header>` 集合分组标题;基线无独立文档/演示,自编 3 例并标注;无 v-model |
|
||||
| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 |
|
||||
| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 |
|
||||
| input-otp | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| 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 | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| list-box-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
@@ -79,7 +79,7 @@
|
||||
| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot |
|
||||
| number-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| pagination | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 |
|
||||
| select | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress |
|
||||
| slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
@@ -194,3 +194,11 @@ React render 自定义根类型不支持;原生 attrs/具名部件/作用域
|
||||
## M24–M25 ScrollShadow / Tabs(2026-10-23)
|
||||
|
||||
7/7 与 10/10 固定基线预览已迁移。复用 VueUse 观察和 Reka Tabs,未引入集合/滚动/焦点的第二套全局协议。公开 useScrollShadow 返回只读状态/属性供 Vue 绑定;Tabs 使用具名部件、v-model、作用域插槽和实例唯一 ID。失活面板保留隐藏容器而卸载内容,shouldForceMount 可保留内容。RAC render 集合、Next Link、私有自动 ID/SelectionIndicator 机制采用 Vue 方式替代;具体行为和未验收边界见 [M24–M25 报告](./migrations/M24-M25-scroll-shadow-tabs.md)。
|
||||
|
||||
## M30–M32 Pagination / Header / InputOTP(2026-10-23)
|
||||
|
||||
- **Pagination**:组合式 nav 容器(无 total/page 状态机);具名部件含 Link/Previous/Next(原生 button)、Ellipsis、图标默认 SVG。9/9 基线示例。`onPress`→`@click`。详见 [M30](./migrations/M30-pagination.md)。
|
||||
- **Header**:集合/分组标题,原生 `<header>`(已核对 RAC 契约)。基线无独立文档/演示;自编 3 例并标注。详见 [M31](./migrations/M31-header.md)。
|
||||
- **InputOTP**:Reka PinInput 底座;公开字符串 + 内部索引数组(中间空位不左移);complete 仅首次填满。11/11 示例。消费 fieldContextKey,未改共享内核。真实自动填充/IME/读屏未验证。详见 [M32](./migrations/M32-input-otp.md)。
|
||||
|
||||
以上不构成整库完成声明;逐像素、读屏、Nuxt 水合、独立安装仍未验收。
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# M30–M32 最终复核与集成
|
||||
|
||||
日期:2026-10-23。Pagination、Header、InputOTP 通过本批实现/回归复核,历史问题保留于前两轮报告;这不等于完成全库逐像素、真机或读屏验收。
|
||||
|
||||
## 本轮确认
|
||||
|
||||
- 交付方的十八项复核回归全部通过;原有完整测试为 542 项通过,类型检查通过。
|
||||
- 集成人补齐最终名称桥接:Reka 自带 aria-label 会盖过原生 Label.for。现在通过 asChild 原生输入和 aria-labelledby / 显式名称的优先级适配,所有真实输入均获得字段名称。只在当前渲染预规划本库 Label,不展开任意用户包装;不改共享 Label/field 内核。
|
||||
- 保留外置标签布局的九份演示增加实例唯一 ID 和显式关联;两份表单演示内部 Label/Description/FieldError 与唯一错误 ID 已修复。同页无重复 ID。
|
||||
- 新增名称优先级回归和真实 node SSR,集成前为 33 文件 / 544 项通过;类型检查、库/文档构建通过。文档仅有既存 chunk 大于 500kB 提示。
|
||||
- 5173 浏览器确认输入的实际名称为“验证账户”;连续输入 123456 自动移动焦点,删除第二格后后续字符仍在原位。同页 70 个真实输入、无重复 ID、四张 API 表无横向溢出。截图 `/private/tmp/heroui-otp-review.png`。
|
||||
- reset/取消、受控拒绝重试、只读/Fieldset、Form 错误消退与新响应、RegExp 状态、长度保留空槽、mask、输入结构类与事件数组已有实际回归;Pagination 显式 aria-current 保留,Header 默认 header 语义保持。
|
||||
|
||||
Slot keydown/paste 用户处理在 capture 边界协调取消,和普通 div bubble 存在事件阶段差异,已写文档。maxLength 裁剪会发出紧凑字符串提案;调用方必须使受控字符串长度与槽位配置相容。真实设备自动填充、IME、触屏、完整读屏、Nuxt/完整水合和自动逐像素比较仍未完成,不因本批提交而宣称全兼容。
|
||||
|
||||
## 集成与下一批
|
||||
|
||||
本批从旧基线 b2525bb 建立 feat/m30-m32-review,保留三张既有未跟踪 PNG,不纳入提交。随后由集成人增量合入远程 main 的 NumberField/Slider/ESM 声明修复,保留双方导出、CSS、导航、测试和报告;最终集成结果补于下方。
|
||||
|
||||
用户已确认:集合、日期、颜色三类基建由集成人处理;其他 AI 下一批为 [M33–M34 AlertDialog → Drawer](M33-M34-alert-dialog-drawer-prompt.md)。每个新任务批次先拉最新 main,再创建独立任务分支,不能从旧 Toolbar 基线继续开发。
|
||||
@@ -0,0 +1,80 @@
|
||||
# M30–M32 第二轮复核(2026-10-23)
|
||||
|
||||
> 本文件保留该轮历史。当前最终结论见 [M30–M32 验收与集成](./M30-M32-acceptance.md)。
|
||||
|
||||
结论:本批暂不提交,下一步仍是返修 InputOTP,不开始新组件。Pagination / Header 本轮未发现新的阻断问题。独立 `heroui-vue-core` 的 NumberField / Slider 不在本批审查和提交范围内。
|
||||
|
||||
## 进展与验证证据
|
||||
|
||||
- 上轮十个回归全部通过,未发现断言被削弱;reset、受控中间删除、拒绝重试、禁用、描述/错误引用、mask、class 和 Pagination 显式 aria-current 已有修复。
|
||||
- 在本轮追加测试前,`pnpm test` 为 32 文件 / 534 项通过,`pnpm typecheck` 通过。
|
||||
- 扩展同一 `tests/m30-m32-review.probe.test.ts` 到十八项后,**十一项通过、七项失败**。额外的动态 readonly 用例通过,未把静态源码疑点直接当作问题。
|
||||
- 新增用例包含真实 input 值、字段名称关联、处理器执行顺序、两个演示在同一 Vue 应用共存的 ID 检查。没有用测试总数、外层 data 状态或组件仍挂载代替结果。
|
||||
- 已有明确行为阻断,本轮没有再做全量浏览器点击、完整构建/安装或视觉验收。
|
||||
|
||||
## 1. P1:Label 没有给真实可聚焦输入命名
|
||||
|
||||
位置:`packages/vue/src/components/input-otp/InputOTPRoot.vue:172` 字段上下文与 `InputOTPSlot.vue` 的 PinInputInput 渲染。
|
||||
|
||||
在 Root 内放 `<Label id="otp-label">Verification code</Label>`,真实第一个 input 没有引用该 ID,也没有匹配的原生 for/id 关联或相应显式名称。它仍得到底座的 `pin input 1 of 4`,而 Label.for 指向的是提交桥的 ID。描述和错误已有引用,不能据此宣称 Label 也完成。
|
||||
|
||||
修复真实输入的名称协议,允许标准的 aria-labelledby、原生关联或正确的显式名称,不强制特定 DOM 实现。核对外部显式 aria-label/aria-labelledby、动态 ID、实际焦点与 SSR 首屏。必要时采用现有 group Label 协议,不能改写公共 Label 内核。
|
||||
|
||||
## 2. P1:公开 RegExp 过滤会吞掉先前的合法输入
|
||||
|
||||
位置:`InputOTPRoot.vue:220`,对同一 RegExp 反复调用 `re.test(char)`。
|
||||
|
||||
pattern 为 `/\d/g` 时,依次在四格输入 1、2、3、4,最终真实值只有 `4`。全局/粘性正则的 lastIndex 被跨字符复用,每次新输入还会错误地删除已有合法字符。
|
||||
|
||||
规范化正则状态或使用独立匹配器,避免泄漏调用方正则的匹配状态;字符串 pattern、导出常量、RegExp、批量粘贴和重复输入都验证。既然当前公开接受 RegExp,不能删除类型或把失败用例改成只接受字符串来绕过修复。
|
||||
|
||||
## 3. P1:事件取消仍在编辑之后,capture 数组手工执行破坏 DOM 语义
|
||||
|
||||
位置:`InputOTPSlot.vue:84` 的 `runHandlers` 与 `onKeydownCapture`、`rest` 透传。
|
||||
|
||||
- Slot 上 `@keydown.prevent`,对第二格按 Delete 后,1234 仍变成 134。底座 input 的处理先执行,外层 wrapper 的取消已经来不及。
|
||||
- `:onKeydownCapture="[stop, after]"` 中,stop 调用 stopImmediatePropagation 后,after 仍执行一次。`runHandlers` 的手写 for 循环没有 Vue DOM invoker 的停止语义。
|
||||
|
||||
明确 wrapper / input 的事件落点,在实际编辑发生前协调可取消处理。事件数组、capture、preventDefault、stopImmediatePropagation 使用 Vue DOM 原生合并机制;不要自己循环调用用户处理器,也不要依赖私有 invoker 标记。保留只读键盘导航、Tab、粘贴与 IME 的边界。
|
||||
|
||||
## 4. P2:编辑没有消退当前 Form 服务端错误
|
||||
|
||||
位置:`InputOTPRoot.vue:149` 的 dismissed / serverErrors 和 `applyChars`。
|
||||
|
||||
已有 Form.validationErrors 能显示,但把当前值 12 改成 92 后,旧的 Invalid code 文案和 data-invalid=true 仍保留。dismissed 只在 reset 时写入,编辑路径没有接入既有的错误响应消退契约。
|
||||
|
||||
有效编辑后消退当前响应;Form 提供新的错误对象时应重新显示。注意对象身份不能被深 ref 包装改变导致比较失效,参考已有字段的响应身份处理,不直接修改 Form 的错误对象。
|
||||
|
||||
## 5. P2:maxLength 改变会重新压缩并左移空槽
|
||||
|
||||
位置:`InputOTPRoot.vue:204` 的长度 watch。
|
||||
|
||||
默认 1234 删除第二格后,真实数组为 `["1", "", "3", "4"]`;maxLength 从 4 改为 5,却变成 `["1", "3", "4", "", ""]`。长度 watch 先 join,再从字符串展开,重新制造了本轮已经修复的显示位置漂移。
|
||||
|
||||
按数组索引裁剪/补空位,不通过序列化重建现有数组。补增大、缩小、受控/非受控和提交值断言;如缩小改变了有效公共值,按已明确的更新政策处理,不让可见值、父值和 FormData 静默分裂。
|
||||
|
||||
## 6. P2:同页示例 ID 冲突,标签/描述也未真正归属
|
||||
|
||||
位置:`apps/docs/demos/input-otp-form-example.vue:70`、`input-otp-with-validation.vue:60`。
|
||||
|
||||
两个示例均固定使用 id=code-error。同一组件文档页同时渲染它们,共有八个带 ID 元素但只有七个唯一 ID。多个示例还把 Label/Description 放在 OTP provider 外,未提供显式关联,不能仅靠视觉相邻说明已关联。
|
||||
|
||||
用实例唯一 ID 或共享字段部件,真正关联输入名称、说明与错误;保持基线布局和文案。演示必须在同一父应用共存验证,单独 mount/unmount 每个示例抓不到重复 ID。
|
||||
|
||||
## 报告与边界
|
||||
|
||||
M32 报告中的“Label for 指向控件 id”“七类已修复”需要按真实输入核验后更新。原 SSR 用例标题“without touching browser globals”运行在 jsdom,标题不能替代真正 node 环境验证;区分字符串渲染、无全局环境和实际水合。
|
||||
|
||||
原目录 main 仍基于 b2525bb;NumberField 已由集成人在远程 main 合入。返修期间不要重置/拉取覆盖未提交工作;通过后由集成人安排提交与集成。三个既有 PNG 保留且不纳入提交。
|
||||
|
||||
## 可直接发给其他 AI 的提示词
|
||||
|
||||
继续 M30–M32 的第二轮返修,先不要开始新组件。请读取 AGENTS.md、M30-pagination-prompt.md、本文件和既有字段/选择字段协议。
|
||||
|
||||
上轮十项回归已通过,本轮同一 tests/m30-m32-review.probe.test.ts 扩展到十八项,其中十一项通过、七项失败。请逐项修复上面的六类问题:真实输入命名、全局/粘性 RegExp、取消事件和 capture 数组、Form 错误消退、长度变化保持空槽,以及文档同页唯一 ID/字段关联。保留原回归和本轮新增回归,不删减断言、不改成只检查外层状态或组件存在。
|
||||
|
||||
不要循环执行用户事件处理器;不要修改共享 Label/Form/field/choice 内核来迁就私有 OTP 适配。若现有公共协议确有缺口,交最小失败用例与具体缺口。不要把公开 RegExp 类型删除来规避状态问题。
|
||||
|
||||
修复后检查不同错误响应恢复、取消 reset、动态属性/ID、受控拒绝、清空与粘贴,并执行完整测试、类型检查、库/文档构建、适用的产物类型检查。浏览器只重点验 OTP 名称/编辑取消/输入/焦点/提交/reset,无需逐页点所有示例。不要声称已验证未运行的触屏、IME、自动填充、读屏或水合。
|
||||
|
||||
更新 M30/M31/M32 报告、矩阵和验证记录,明确真实命令/结果。不要修改 heroui-vue-core、占用 5174、合并/覆盖集成人分支或自行提交。完成后交回复核,通过再安排新批次。
|
||||
@@ -0,0 +1,89 @@
|
||||
# M30–M32 独立复核与返修任务(2026-10-23)
|
||||
|
||||
> 本文件保留该轮历史。当前最终结论见 [M30–M32 验收与集成](./M30-M32-acceptance.md)。
|
||||
|
||||
> 本文件保留首轮历史。上轮十项现已通过,但第二轮仍有阻断,最新结论见 [第二轮复核](./M30-M32-review-2.md)。
|
||||
|
||||
本批暂不提交。复核原 `heroui-vue` 的 Pagination、Header、InputOTP;独立 `heroui-vue-core` 的 NumberField 不在本批范围内,不合并、不覆盖。
|
||||
|
||||
## 已执行验证
|
||||
|
||||
- 交付方已有测试:`pnpm test`,31 文件 / 522 项通过;`pnpm typecheck` 通过。
|
||||
- 新增独立回归:`pnpm exec vitest run tests/m30-m32-review.probe.test.ts`,10 项全部失败,逐项复现下述缺口。该文件纳入默认 `pnpm test` 的发现范围,用于阻止问题回归。新增测试后再次执行 `pnpm typecheck` 通过。
|
||||
- 本次以固定上游源码、Vue 状态与字段协议、真实 DOM / FormData 的单元集成为主。尚未重新执行本批浏览器、打包消费及完整水合验收,不据已有测试宣称全部完成。
|
||||
|
||||
## 必须修复的问题
|
||||
|
||||
### 1. P1:InputOTP 的 reset 未实现,原测试没有断言恢复值
|
||||
|
||||
位置:`packages/vue/src/components/input-otp/InputOTPRoot.vue`;`tests/input-otp.test.ts` 的 reset 用例。
|
||||
|
||||
非受控 `defaultValue="12"`,把第一格改为 `9` 后调用原生 `form.reset()`,真实输入仍为 `92`,未恢复 `12`。现有 reset 用例只检查组件仍挂载,不能证明 reset 契约成立。
|
||||
|
||||
消费既有表单/reset 协议或在组件私有适配中接入真实所属表单,覆盖可取消 reset、受控 reset、表单归属变化及卸载清理。断言真实输入、视觉格与唯一 FormData 值,不只检查组件存在。
|
||||
|
||||
### 2. P1:受控的显示状态和编辑状态分裂,拒绝后的请求被吞
|
||||
|
||||
位置:Root 的 `chars`、`pinValue`、`applyChars` / `lastEmitted`;Slot 的 `char`。
|
||||
|
||||
- `v-model="1234"` 删除第二格后,底层真实输入保留 `["1", "", "3", "4"]`,视觉状态却从压缩后的字符串重新展开:第二格仍 `data-filled=true`,后面的值显示在错误位置。
|
||||
- 固定 `modelValue="12"`,父组件拒绝一次第三格输入 `9` 后,再输入相同 `9` 只有一次更新事件;`lastEmitted` 把未被接受的提案当成已接受状态。
|
||||
|
||||
底层输入、显示字符、filled/active、公共字符串和提交值应共享一致的状态决策;中间空位政策必须明确。拒绝与重试每次都能产生合法请求,不能通过去重缓存提交未被接受的值。补充父值外部更新、清空、动态长度和完整事件载荷测试。
|
||||
|
||||
### 3. P1:只读、Fieldset 禁用、Form 服务端错误没有实际接入
|
||||
|
||||
位置:Root 的 `disabled` / `invalid` / `errors`、`readOnly: computed(() => false)`;Slot 的 PinInputInput 属性。
|
||||
|
||||
- 根传原生 `readonly`,真实输入 `readOnly` 仍为 false;属性落到容器不能阻止编辑。
|
||||
- 放入 `<Fieldset disabled>`,真实输入的 disabled 属性与视觉格的禁用标记均未消费共享禁用上下文。原生 fieldset 的部分浏览器禁用语义不能代替组件协议和视觉继承。
|
||||
- `<Form :validation-errors="{code: 'Invalid code'}">` 中,`name="code"` 的 OTP 未获得错误状态和 FieldError 文案。
|
||||
|
||||
通过现有协议补齐,不另造 Form/Fieldset 状态源;检查禁用/只读的输入、删除、粘贴,Fieldset 第一 legend 豁免,错误增删与解除。required、validationBehavior、原生约束及焦点目标需按固定基线与现有 Form 约定核验,不能凭组件名称额外规定“required 必须填满”。
|
||||
|
||||
### 4. P1:字段描述与错误注册后没有关联到真实输入
|
||||
|
||||
位置:Root 的 `labelIds` / `descriptionIds` / `errorIds` 注册,Slot 的真实输入属性。
|
||||
|
||||
在 Root 内放 Label、Description、FieldError,实际可聚焦输入未引用 description/error ID,亦未反映 `aria-invalid`。只向字段上下文注册 ID、在外层设置 data-invalid 不等于完成无障碍关联。
|
||||
|
||||
验证真实输入的可访问名称、描述、错误、动态 ID 与卸载清理;演示中的 Label/Description 也需要真实归属,不能仅视觉相邻。不要用 aria-hidden 的提交桥冒充已命名的用户输入。
|
||||
|
||||
### 5. P1:mask 只遮住透明 input,视觉层仍明文显示
|
||||
|
||||
位置:`InputOTPSlot.vue` 的 slot-value。
|
||||
|
||||
`mask=true` 时 native input 为 password,但视觉层仍直接渲染 `char`,页面显示验证码明文。既然公开支持 mask,就应正确遮蔽可见层并测试;若属于新增扩展,应在兼容矩阵标明与上游的关系。
|
||||
|
||||
### 6. P2:自定义输入 class 替换了必需结构样式,Slot 丢弃 attrs
|
||||
|
||||
位置:`InputOTPSlot.vue` 的 inputClass 与外层渲染属性。
|
||||
|
||||
- `inputClassName="custom-input"` 后,真实输入只有自定义类,丢失 `hv-input-otp__input`,破坏透明定位输入层。应与底层结构 class 合并,和上游 `slots.input({className: inputClassName})` 一致。
|
||||
- Slot 仅处理 class 与 aria-label,调用方 id、style、data-*、DOM 事件等未按 div 契约透传。明确 wrapper/input 的属性归属,测试属性动态移除与事件取消,避免内部事件覆盖用户事件。
|
||||
|
||||
### 7. P2:PaginationLink 覆盖并删除显式 aria-current
|
||||
|
||||
位置:`packages/vue/src/components/pagination/PaginationLink.vue` 的属性合并。
|
||||
|
||||
`<PaginationLink aria-current="step">` 最终 button 没有 aria-current:attrs 展开后被 `isActive ? "page" : undefined` 覆盖。固定 React 基线允许显式覆盖,此能力也在原任务中明确要求。
|
||||
|
||||
按基线处理显式属性优先级,并验证 isActive 切换、显式覆盖及属性移除。不要改变按钮默认语义。
|
||||
|
||||
## 文档与完成声明
|
||||
|
||||
修复后更新 M30/M31/M32 报告、compatibility 和 verification。总览表仍将 input-otp 标为计划,追加段落又描述已实现,需统一为准确的验证状态。reset 不可用不能用“以底座为准”或只验证挂载来声明完成。SSR 字符串测试运行在 jsdom 下,不等于验证无浏览器全局环境或完整水合。
|
||||
|
||||
Header 暂未发现阻断问题;不能据此把整批视为通过。保留既有三个 PNG 文件,不纳入迁移提交。
|
||||
|
||||
## 给其他 AI 的下一步提示词
|
||||
|
||||
继续当前 M30–M32 批次的返修,先不要迁移新组件。
|
||||
|
||||
先读 AGENTS.md、docs/decisions/field-form-foundation.md、docs/migrations/M30-pagination-prompt.md 和本复核文件。逐项修复上面的七类问题;保留并通过 `tests/m30-m32-review.probe.test.ts`,不得删除、跳过或把实际行为断言改成“组件仍挂载”。将必要的组合场景补入正式专项测试,特别是受控拒绝/重试、中间删除、原生 reset/取消 reset、Fieldset、Form 错误和真实 ARIA。
|
||||
|
||||
InputOTP 可以在组件私有适配中消费共享协议,不改写公共 Form、field/choice 内核或 Label/FieldError 协议。如果确实无法通过现有协议接入,提交最小失败用例和具体缺口,交集成人处理,不能声明已兼容。避免引入 any/as never 或新增全局监听队列。
|
||||
|
||||
重新核对固定 HeroUI 基线的继承 input 属性、事件、pattern、complete、示例内容与 CSS;未支持能力准确记录,不以 Reka 同名能力替代。对上述缺口补充回归后执行完整测试、类型检查、库与文档构建及适用的产物类型检查。浏览器只重点验 OTP 中间删除/粘贴、受控拒绝、焦点、提交/reset 与自定义样式,不逐页重复点演示。明确未验证的自动填充、IME、读屏及水合范围。
|
||||
|
||||
同步更新兼容矩阵和验证报告,报告准确命令、数量、失败/通过情况。不要合并独立 heroui-vue-core 的 NumberField 分支,不修改其目录或占用 5174,不自行提交。完成后将本批交回复核,通过后再安排下一批组件。
|
||||
@@ -1,12 +1,14 @@
|
||||
# M30 Pagination:交给实现 AI 的提示词
|
||||
# M30–M32 Pagination / Header / InputOTP:交给实现 AI 的提示词
|
||||
|
||||
请继续迁移 Pagination。M29 Toolbar 已经集成人复核通过;本批只迁移分页家族,不迁移 Table、NumberField、Slider、菜单、Select 或日期,不自行提交。
|
||||
请按顺序迁移 **M30 Pagination → M31 Header → M32 InputOTP**。M29 Toolbar 已由集成人复核通过。每项完成后先验证并分别记录,再继续下一项,三项完成后一并交回复核;不自行提交。不迁移 Table、NumberField、Slider、菜单、Select、日期或颜色。
|
||||
|
||||
## 基线与输入
|
||||
本文件沿用原 M30 文件名以保留已有链接,任务范围以本版 M30–M32 为准。不要只做 Pagination 就停下,也不要一次生成三个家族的空壳。如果 InputOTP 发现必须由集成人扩展共享协议的真实阻断,完成可独立交付的 Pagination/Header,并交付 InputOTP 的最小失败场景、能力差异和局部方案,不擅自改共享内核或宣称全部完成。
|
||||
|
||||
## 公共基线与输入
|
||||
|
||||
在独立 heroui-vue 仓库工作,先读 AGENTS.md、docs/migration-handoff.md、M13-M20-lessons.md 和 M29 最终复核记录。相邻 React 仓库只读,不引入相邻目录运行时依赖。固定 HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`,不要追逐当前官网改变契约。
|
||||
|
||||
逐一核对这些文件(路径相对 Vue 仓库):
|
||||
逐一核对 Pagination 的这些文件(路径相对 Vue 仓库):
|
||||
|
||||
- `../heroui/packages/react/src/components/pagination/`:index、实现与 stories。
|
||||
- `../heroui/packages/styles/components/pagination.css` 与 `../heroui/packages/styles/src/components/pagination/`。
|
||||
@@ -15,7 +17,7 @@
|
||||
|
||||
先产出组件/子部件、props 默认值、DOM/ARIA/状态、示例清单与 Vue 差异,再实施。根 Pagination 在固定基线是组合式 nav 容器,不是管理 total/page 的有状态分页器;不要套同名 Reka Pagination 就额外发明根 v-model、自动页码计算或一套集合状态。controlled 示例的页码由示例自身维护,明确这一点。
|
||||
|
||||
## 交付范围
|
||||
## M30 Pagination:交付范围
|
||||
|
||||
按上游 index 导出对应具名 Vue 组件:Pagination(Root)、PaginationRoot、Summary、Content、Item、Link、Previous、PreviousIcon、Next、NextIcon、Ellipsis,使用完整 Pagination 前缀;补齐相应 Props、paginationVariants/类型、独立 CSS、入口和样式导出。是否作为别名导出 Root 按现有规范实现,并与文档保持一致。
|
||||
|
||||
@@ -25,13 +27,13 @@ React render/children 按既有 as/asChild/插槽约定 Vue 化;普通原生 a
|
||||
|
||||
默认图标核对上游公共部件,来源与许可明确;演示中的自定义图标使用现有 Tabler Vue,不手画 SVG。保留自定义图标插槽,核验空插槽/默认回退及 aria-hidden。组件样式数值、主题、尺寸、圆角、间距、焦点与 RTL 按基线适配。
|
||||
|
||||
## 文档与示例
|
||||
### Pagination 文档与示例
|
||||
|
||||
新增中文组件页与实际侧栏/移动导航,按上游顺序迁移 9 个预览:basic、sizes、disabled、simple-prev-next、controlled、with-ellipsis、with-summary、custom-icons、custom-styles。
|
||||
|
||||
保留中文标题、说明、API/样式参考及定制代码,受控示例真实更新当前页、边界禁用和结果摘要。不要给无处理器的静态演示虚构行为,也不要改成粗略的自动生成示例。渲染、复制、高亮共用同一 SFC;API 和插槽等长短表格全宽、自动换行,无横向拖动。
|
||||
|
||||
## 必测重点
|
||||
### Pagination 必测重点
|
||||
|
||||
- Root/Content/Item 真实 DOM 和 ARIA,多个实例隔离;size 上下文动态更新、嵌套上下文及自定义 class 保留。
|
||||
- isActive 动态切换时 aria-current 和 data-active 一起更新,取消选中时移除;显式 aria-label/aria-current 等覆盖策略按基线核对,不悄悄丢弃 attrs。
|
||||
@@ -41,12 +43,58 @@ React render/children 按既有 as/asChild/插槽约定 Vue 化;普通原生 a
|
||||
- Summary dir=auto 与显式 dir、RTL 图标/布局;SSR 不访问浏览器全局,水合单独记录。
|
||||
- 全部 9 个示例真实编译/挂载,无 Vue warning;公开类型有合法/非法断言,抽查 dist 声明。
|
||||
|
||||
浏览器只重点验证 controlled 翻页与禁用边界、键盘、焦点及尺寸/主题,不逐页点击。不要修改 Toolbar、按钮组焦点、field/choice、弹层或 ConfigProvider 协议;发现共享缺口先在报告给出具体失败场景。允许维护必要导出、导航、样式入口与测试命令。
|
||||
浏览器只重点验证 controlled 翻页与禁用边界、键盘、焦点及尺寸/主题,不逐页点击。
|
||||
|
||||
## M31 Header:交付范围与验收
|
||||
|
||||
参考 `../heroui/packages/react/src/components/header/`、`../heroui/packages/styles/components/header.css` 和 `../heroui/packages/styles/src/components/header/`。先核对上游真实语义与使用处:这是集合/分组标题部件,不是网站顶栏或带 Logo、导航、用户菜单的应用 Header。
|
||||
|
||||
导出 Header、HeaderRoot 别名和 HeaderProps 等适用类型及 headerVariants,保留 data-slot、源字号/字重/颜色/间距/方向。底层 DOM 按固定 RAC Header 的真实契约核验,不能仅凭名称强制 header 标签或 heading 级别。语义 HTML 足够时不为复刻名称引入另一套交互底座。
|
||||
|
||||
固定基线没有找到 Header 独立中文组件页和专属演示目录;实施前再次确认,不能编造“官方 N 个示例”。提供必要的独立中文页和少量可运行示例,明确标注自编,演示默认标题、自定义 class/插槽及原生语义。菜单/ListBox 尚未迁移时,用语义容器解释组合边界,不实现伪菜单或顺便迁移新家族。
|
||||
|
||||
测试实际 DOM/ARIA、attrs 与 class/style 动态增删、插槽更新、多个实例、SSR;若提供 as/asChild,覆盖唯一原生根与子项属性保留。此组件没有业务值,不强加 v-model、表单提交或焦点状态。维护导航与来源记录,不把自编页描述成官方文案完整复刻。
|
||||
|
||||
## M32 InputOTP:先验证底座,再完成家族
|
||||
|
||||
参考 `../heroui/packages/react/src/components/input-otp/`、对应 styles CSS/tv、`../heroui/apps/docs/content/docs/cn/react/components/(forms)/input-otp.mdx` 和 `../heroui/apps/docs/src/demos/cn/input-otp/`。注意上游交互来自 React 的 input-otp 包,不要误认成 RAC 多 input 或直接依赖该 React 包。
|
||||
|
||||
优先验证安装版 Reka PinInput 的真实导出、类型和行为,建立 Vue 适配:公开值为字符串,内部需要字符数组时明确转换规则。重点验证中间空位、删除、粘贴的索引语义,不能直接 filter(Boolean).join 后把后续字符左移;也不能每个子 input 都复制一份完整模型。
|
||||
|
||||
导出 InputOTP、InputOTPRoot、InputOTPGroup、InputOTPSlot、InputOTPSeparator、相应 Props、inputOTPVariants/类型,以及上游三个正则常量 REGEXP_ONLY_DIGITS、REGEXP_ONLY_CHARS、REGEXP_ONLY_DIGITS_AND_CHARS。对照完整根属性清单,涵盖 maxLength、值/默认值、完成事件、pattern、禁用/错误、validationErrors、inputClassName、输入法/自动填充等真实继承能力;React 特有 render 与不支持的能力写入差异,不无记录删减。
|
||||
|
||||
Vue 公共 API 用 v-model/modelValue、update:modelValue,定义 change/complete 等事件与默认值优先级并在文档明确映射。Slot index、分组/分隔、自定义状态、焦点/filled/active/invalid/disabled 和减少动画必须映射到真实 DOM 与源 CSS;Reka 多 input 与上游单 input 的内部 DOM 可以不同,但可感知行为、表单值和可访问名称必须验收。inputClassName 与根 class 的实际落点需明确,不能默默改成同一节点。
|
||||
|
||||
### 字段与表单边界
|
||||
|
||||
先读 docs/decisions/field-form-foundation.md 及适用的选择字段协议。复用现有 Fieldset 禁用、Label/Description/FieldError 的关联与状态协议,不复制第二套字段、错误、reset、校验队列,也不要把 OTP 塞进只接受单文本控件的 TextField 协议来凑接口。
|
||||
|
||||
可以在 InputOTP 私有适配中消费已有协议,明确 name/value、disabled/readonly/required、错误与描述的实际节点。若底座提供隐藏 input,验证其提交/reset;不得同时加第二份同名提交值。公共 Form、field/choice 内核、Label/FieldError 共享协议、SSR 预规划、ConfigProvider 由集成人维护,确有缺口用最小失败用例说明后交回,不绕过协议做虚假的兼容声明。
|
||||
|
||||
### InputOTP 文档与示例
|
||||
|
||||
按固定中文页顺序迁移 11 个预览:basic、variants、on-surface、disabled、four-digits、controlled、on-complete、form-example、with-pattern、with-validation、custom-styles。与 Pagination 一样,预览/复制/高亮共用实际 SFC,图标用 Tabler Vue,全部表格全宽换行。
|
||||
|
||||
保留上游表单验证与加载反馈的流程、文案和布局;使用模拟验证时明确示例行为,卸载清理定时器,不发送真实验证码或访问外部验证服务。错误展示与 label/description 要真正关联输入,不能只是视觉上摆在旁边。
|
||||
|
||||
### InputOTP 必测重点
|
||||
|
||||
- 字符串受控/非受控、默认值、清空、父级拒绝更新后实际输入恢复;完成事件首次填满、替换、重复同值和父级同步不能重复触发,按上游核验触发契约。
|
||||
- 单字符输入、在中间位置替换/清空、Backspace/Delete、左右键/Home/End 的适用行为、鼠标定位、粘贴整串/部分/超长/不匹配字符、pattern 过滤/转换边界和 IME,不只验证末尾追加。
|
||||
- 自动填充/one-time-code、inputmode、移动端输入属性、粘贴焦点与多 input 可访问名称。无法模拟的真实设备能力标明未验证,不能按属性存在就宣布验收。
|
||||
- 禁用/只读的指针、键盘、粘贴和 Fieldset 继承;required/原生约束按实际契约验证。真实 FormData 只有一份完整值,禁用时省略;reset 与被取消的 reset,受控 reset 保留外部值。
|
||||
- Label/Description/FieldError 与显式 ARIA 动态合并、多个实例唯一 ID、错误替换/清除及卸载清理;校验状态不要泄漏到周边字段。
|
||||
- maxLength/index 动态边界、分组/slot 增删、缺少 Root 的明确处理、空位保持、SSR 安全与 ID 关联;实际水合与 SSR 字符串测试分开记录。
|
||||
- 11 个演示真实编译挂载、无 Vue warning;公共字符串 API 正反类型用例及 dist 声明检查。浏览器集中验证中间删除/粘贴、焦点、受控拒绝与表单提交/reset,不逐页点全量示例。
|
||||
|
||||
## 三项共同的修改边界
|
||||
|
||||
不要修改 Toolbar、按钮组焦点、field/choice、弹层或 ConfigProvider 协议;发现共享缺口先在报告给出具体失败场景。允许维护本批私有适配、必要导出、导航、样式入口与测试命令。属性合并在渲染时读取,保留子项原生属性;不复制命令式删 tabindex、缓存插槽/attrs 或全局焦点监听的旧实现。
|
||||
|
||||
## 完成与复核
|
||||
|
||||
运行 pnpm test、pnpm test:unit、pnpm test:ssr、pnpm typecheck、pnpm build:docs、pnpm build:playground、pnpm format 和 git diff --check。新增测试接入 test:unit。同步 docs/compatibility.md、upstream.md、verification.md,新增 M30-pagination.md,记录契约/示例对照、底座方案、差异、共享改动及实际命令/浏览器结果。
|
||||
每完成一项先跑其专项行为/演示/类型测试再继续下一项;三项最终运行 pnpm test、pnpm test:unit、pnpm test:ssr、pnpm typecheck、pnpm build:docs、pnpm build:playground、pnpm format 和 git diff --check,不在每改一行后重复全量构建。新增测试接入 test:unit。同步 docs/compatibility.md、upstream.md、verification.md,分别新增 M30-pagination.md、M31-header.md、M32-input-otp.md,记录契约/示例对照、底座方案、差异、共享改动及实际命令/浏览器结果。
|
||||
|
||||
前批验收基线是全量 28 文件/483 项(含 SSR 15);本轮按实际更新。不要把构建、源码类型检查、SSR 字符串或 dist 抽查分别冒充独立安装、实际水合或视觉验收。未执行的逐像素、读屏/触屏、Nuxt 和独立消费等如实保留。
|
||||
|
||||
完成后交回复核,不自行提交,不继续下一家族。
|
||||
三项完成后一次交回复核,逐项报告通过/未完成与具体阻断,不自行提交,不继续第四项。不能用前两项的通过结果替代 InputOTP 验收。
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
# M30 Pagination
|
||||
|
||||
日期:2026-10-23。上游 HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`。
|
||||
|
||||
## 契约核对
|
||||
|
||||
- 组件:Pagination(Root)、PaginationRoot、Summary、Content、Item、Link、Previous、PreviousIcon、Next、NextIcon、Ellipsis。
|
||||
- 根为组合式 `nav` 容器(`aria-label="pagination"`、`role="navigation"`),**不**管理 `total`/`page`;受控页码由示例维护。
|
||||
- Link/Previous/Next 使用 RAC Button(原生 `button`,默认 `type="button"`),**不是** anchor。
|
||||
- Summary 默认 `dir="auto"`,显式 `dir` 覆盖。
|
||||
- Link `isActive` → `aria-current="page"` + `data-active="true"`;取消时移除。
|
||||
- Previous/Next 附加 `pagination__link--nav`,不带入共享 Button 的 variant 类。
|
||||
- 默认图标为上游 `icons.tsx` 的 IconChevronLeft/Right(Apache-2.0),移植为 SFC;空插槽回退默认 SVG;包裹层 `aria-hidden="true"`。
|
||||
- Ellipsis 始终渲染 `…`,与上游一致不接受自定义子内容。
|
||||
- `paginationVariants`:slots base/content/ellipsis/item/link/summary + size sm/md/lg。
|
||||
|
||||
## Vue 实现
|
||||
|
||||
- 具名导出完整 Pagination 前缀;`Pagination` 与 `PaginationRoot` 为同一组件。
|
||||
- `as` 替换容器元素;`asChild` 支持 Link/Previous/Next。
|
||||
- 事件用原生 `@click`(上游 `onPress`)。原生 Enter/Space 单次激活;`disabled` 不激活;支持处理器数组/capture/stopImmediatePropagation。
|
||||
- 样式 `hv-` 前缀,数值与主题 token 同基线。
|
||||
- Summary `dir`:未传时 `auto`,显式值优先(避免 spread undefined 覆盖)。
|
||||
|
||||
## 示例(9)
|
||||
|
||||
basic、sizes、disabled、simple-prev-next、controlled、with-ellipsis、with-summary、custom-icons、custom-styles。预览/复制/高亮共用同一 SFC;自定义图标用 Tabler `IconArrowLeft`/`IconArrowRight`。
|
||||
|
||||
## 测试与验证
|
||||
|
||||
- `tests/pagination.test.ts` 16 项:DOM/ARIA、多实例隔离、size 动态/嵌套、isActive 切换、Summary dir、点击/禁用/事件合并、attrs 增删改、asChild 属性保留、controlled 翻页边界与摘要、9 演示无 warning、类型正反、SSR 字符串。
|
||||
- 浏览器仅计划重点验证 controlled 翻页与键盘;本轮未执行真实键盘激活,不把 jsdom 点击当作浏览器验收。
|
||||
|
||||
## 差异
|
||||
|
||||
| 上游 | Vue |
|
||||
| ---------------------------- | ---------------- |
|
||||
| 对象子部件 `Pagination.Link` | 具名导出 |
|
||||
| `onPress` | `@click` |
|
||||
| `className`/`children` | `class`/默认插槽 |
|
||||
| 根 v-model 自动分页 | 无(组合式容器) |
|
||||
|
||||
## 复核返修(2026-10-23)
|
||||
|
||||
PaginationLink 显式 `aria-current` / `data-active` 优先于 `isActive` 默认覆盖问题已修复;探针用例通过。
|
||||
@@ -0,0 +1,35 @@
|
||||
# M31 Header
|
||||
|
||||
日期:2026-10-23。上游 HeroUI 3.2.6 / `ce90ea3`。
|
||||
|
||||
## 契约核对
|
||||
|
||||
- `Header` / `HeaderRoot` 来自 `header/`;`headerVariants` 仅 `base: "header"`。
|
||||
- 底层为 RAC `Header`,`DOMRenderProps<'header'>`:**原生 `<header>` 元素**,不是 heading 级别。已对照安装版 react-aria-components `Header.mjs` 确认 `dom.header`。
|
||||
- 用途:集合/分组标题(Dropdown、ListBox、ComboBox、Autocomplete 分组),**不是**应用顶栏。
|
||||
- 固定基线**没有**独立中文组件页与专属演示目录(已再次确认)。
|
||||
|
||||
## Vue 实现
|
||||
|
||||
- 导出 `Header`、`HeaderRoot`(同一组件)、`headerVariants`、`HeaderProps`。
|
||||
- `data-slot="header"`;默认 `<header>`;`as` 可替换;attrs/class 动态合并。
|
||||
- 无 v-model、无业务值、无焦点状态机。
|
||||
- 样式 `.hv-header`:`w-full px-2 pt-1.5 pb-1 text-start text-xs font-medium text-muted`。
|
||||
|
||||
## 示例(自编 3,已在文档标注)
|
||||
|
||||
- header-basic:默认标题 + 语义容器
|
||||
- header-custom-class:自定义 class
|
||||
- header-semantic:分组列表组合边界(菜单未迁移时的说明)
|
||||
|
||||
## 测试
|
||||
|
||||
`tests/header.test.ts` 8 项:DOM/`header` 标签、as 覆盖、attrs 增删改、插槽更新、多实例、演示无 warning、类型、SSR。
|
||||
|
||||
## 差异
|
||||
|
||||
| 上游 | Vue |
|
||||
| ---------------------- | ---------------------------------- |
|
||||
| RAC Collection 叶子 | 语义 HTML 封装;集合上下文待菜单族 |
|
||||
| `className`/`children` | `class`/默认插槽 |
|
||||
| 无官方演示 | 自编 3 个,文档明确标注 |
|
||||
@@ -0,0 +1,75 @@
|
||||
# M32 InputOTP
|
||||
|
||||
> 本文件保留该轮历史。当前最终结论见 [M30–M32 验收与集成](./M30-M32-acceptance.md)。
|
||||
|
||||
日期:2026-10-23。上游 HeroUI 3.2.6 / `ce90ea3`。上游交互来自 React `input-otp` 包(单隐藏 input),不是 RAC 多 input。
|
||||
|
||||
## 底座验证
|
||||
|
||||
- 安装版 **Reka UI 2.11.0** `PinInputRoot` / `PinInputInput`:`modelValue` 为字符数组,`update:modelValue`/`complete`,`otp`/`mask`/`placeholder`/`type`,`name`/`required`(FormFieldProps),内部 `VisuallyHiddenInput` 提交 `join("")` 一份完整值。
|
||||
- Reka 多 input 与上游单 input 内部 DOM 不同,可感知行为与表单值按基线验收。
|
||||
|
||||
## 公开 API 与转换
|
||||
|
||||
- 公开值为**字符串**;`v-model` / `update:modelValue` / `change` / `complete`。
|
||||
- 内部字符数组长度 `maxLength`,空槽 `""` 保留索引;**UI 读数组,不 `filter(Boolean).join` 后左移**。
|
||||
- 字符串序列化 `join("")` 为空槽省略的紧凑形式;父级回写同一序列化值时保留含空位的数组;写入不同字符串时密排展开。
|
||||
- `complete` 仅在**首次填满**(filled 从 <max 变为 ==max)触发;替换/重复同值/父级同步不重复触发。
|
||||
|
||||
## 字段与表单
|
||||
|
||||
- 提供既有 `fieldContextKey`(kind=text),Label `for`、Description、FieldError 可关联;不复制第二套字段/reset 内核,不塞进 TextField 单文本协议。
|
||||
- `name` + 隐藏 input 提交一份完整字符串;禁用时 FormData 省略。
|
||||
- `inputClassName` 落在真实 input;`class` 落在视觉 Slot 根——不同节点。
|
||||
|
||||
## 示例(11)
|
||||
|
||||
basic、variants、on-surface、disabled、four-digits、controlled、on-complete、form-example、with-pattern、with-validation、custom-styles。模拟验证带定时器且卸载清理;不发送真实验证码。
|
||||
|
||||
## 测试
|
||||
|
||||
`tests/input-otp.test.ts` 15 项:结构/别名、inputClassName、非受控/受控拒绝、中间空位不左移、清空、complete 阈值、pattern 常量、disabled/invalid/filled、FormData、reset 挂载可用、11 演示无 warning、类型正反、SSR。
|
||||
|
||||
## 已知差异 / 未验证
|
||||
|
||||
| 能力 | 状态 |
|
||||
| --------------------------------------------- | ---------------------------------------------- |
|
||||
| 真实设备短信/密码管理器自动填充 | 属性存在(`otp`/autocomplete),**未真机验证** |
|
||||
| IME 组合输入 | Reka 有 composition 处理,**未专项验证** |
|
||||
| 中间删除/粘贴真实键盘与指针 | jsdom 覆盖数组语义;**浏览器未逐项点验** |
|
||||
| 读屏 / 触屏 / Nuxt 水合 / 独立安装 | **未验证** |
|
||||
| 上游 `pushPasswordManagerStrategy` / `render` | **未提供**,已列差异 |
|
||||
| 上游 `pattern` 整串校验 | Vue 为单字符过滤(同样接受导出常量) |
|
||||
|
||||
无共享内核阻断:本批未改 field/choice/Form/Toolbar/ConfigProvider 协议,仅消费 `fieldContextKey`。
|
||||
|
||||
## 复核返修记录(2026-10-23)
|
||||
|
||||
按 [M30–M32 复核](./M30-M32-review.md) 修复七类缺口;`tests/m30-m32-review.probe.test.ts` **10/10 通过**,未删改断言。
|
||||
|
||||
1. **reset**:接入所属 `form` 的 `reset`(可取消);非受控恢复 `defaultValue`,受控保留父值;断言真实输入与 FormData。
|
||||
2. **受控中间删除 / 拒绝重试**:`slotChars` 为索引数组唯一显示源;父级回写保留空位;拒绝后 `nextTick` 恢复公共值;每次请求独立发出(`update` 可重试)。
|
||||
3. **只读 / Fieldset 禁用 / Form 错误**:`readonly` 落在真实 input 并在 capture 拦截编辑键;`useInheritedDisabled` 接入 Fieldset;消费 `formContextKey.validationErrors[name]`。
|
||||
4. **ARIA**:真实 input 带 `aria-describedby`(description/error id)与 `aria-invalid`;Label `for` 指向控件 id。
|
||||
5. **mask**:视觉层显示 `•`,input 为 `password`。
|
||||
6. **class/attrs**:`inputClassName` 与 `hv-input-otp__input` 合并;Slot 透传 div attrs,内部 capture 与用户 handler 合并。
|
||||
7. **Pagination**:显式 `aria-current` / `data-active` 优先于 `isActive` 默认值。
|
||||
|
||||
未验证范围不变:真机自动填充、IME、读屏、水合、独立安装。
|
||||
|
||||
## 集成人第二轮复核
|
||||
|
||||
上面的返修记录不能视为最终验收。新增十八项复核用例中十一项通过、七项失败,详情见 [第二轮复核](./M30-M32-review-2.md)。本批尚未提交;需继续补真实命名、事件语义、过滤/长度状态与同页示例关联。
|
||||
|
||||
## 第二轮复核返修(2026-10-23)
|
||||
|
||||
按 [M30–M32 第二轮复核](./M30-M32-review-2.md) 修复;`tests/m30-m32-review.probe.test.ts` **18/18 通过**。
|
||||
|
||||
1. **Label 命名**:`controlId` 指向首个真实 input 的稳定 id(`inputId(0)`),Label `for` 原生关联;Slot 为每个真实 input 写入对应 id。
|
||||
2. **全局 RegExp**:单字符匹配使用去掉 `g`/`y` 的独立 RegExp,不泄漏 `lastIndex`,不误删已有合法字符。
|
||||
3. **事件取消 / capture 数组**:用户 `onKeydown`/`onKeydownCapture` 以 Vue 原生 handler 数组合入 wrapper capture(在底座处理前执行);`preventDefault` 后 `stopImmediatePropagation` 取消编辑;数组语义遵守 `_stopped`(不再手写循环)。
|
||||
4. **Form 错误消退**:有效编辑时 `dismissed` 记录当前 `validationErrors` 响应对象(`shallowRef` 保持身份),避免深 ref 包装导致比较失效;新响应对象会重新显示。
|
||||
5. **maxLength 变化**:按数组索引 pad/crop,不经过 join/expand,中间空槽不左移。
|
||||
6. **示例唯一 ID / 字段关联**:form-example 与 with-validation 使用 `useId`;Label/Description/FieldError 放入 InputOTP 字段上下文并用 FieldError 展示错误。
|
||||
|
||||
未验证范围不变。
|
||||
@@ -0,0 +1,66 @@
|
||||
# 下一批:M33 AlertDialog → M34 Drawer
|
||||
|
||||
这是一个新的任务批次,两个家族按顺序实施、分别记录结果,一起交回复核。M30–M32 已由集成人验收并提交;此前返修提示仅保留历史,不要继续沿用旧基线。
|
||||
|
||||
## 开始前:先同步 main,再开新分支
|
||||
|
||||
每个新任务批次都必须使用最新 main 创建独立分支,不能在 main 直接开发,也不能在上一批分支无限续写。
|
||||
|
||||
先检查工作区。已存在的 acc-open.png、disc-demo1.png、disc-demo2.png 可以保留,不删除、不加入提交;若有其他未提交源码改动,先交代归属,不能 reset/覆盖或带进本批。
|
||||
|
||||
```sh
|
||||
git fetch origin
|
||||
git switch main
|
||||
git pull --ff-only origin main
|
||||
git switch -c feat/m33-m34-alert-dialog-drawer
|
||||
```
|
||||
|
||||
若同步不能快进,停在同步步骤并说明分叉,不用 reset --hard 或强推。确认起点包含 NumberField、Slider、ESM 声明路径修复及 M30–M32 最终集成,而不只是 Toolbar 的 b2525bb。本批完成只交回复核,不自行合 main 或推送;报告分支名、起点 SHA、未提交范围和验证结果。后续新批次同样重新同步 main、创建新的分支。
|
||||
|
||||
## 分工和边界
|
||||
|
||||
- 你负责本目录 heroui-vue 的 AlertDialog、Drawer,各自的组件/类型/样式/演示/文档/测试与迁移报告,以及必要的入口、导航和矩阵增量。
|
||||
- 集成人负责 ListBox / Select 集合基建、DateField / Calendar 日期基建、ColorArea / ColorPicker 颜色基建,使用独立目录 heroui-vue-core。不要修改这些系列或共享集合/日期/颜色状态模型,不进入其目录,不占用 5174。
|
||||
- 本目录文档使用 5173。复用既有 Form/Fieldset、ConfigProvider、overlay 协议,不重新实现 document 关闭监听、body 锁栈、全局焦点队列或另一套弹层上下文。
|
||||
- 私有组件适配可以完成;共享 overlay 内核、ConfigProvider、useOverlayState、Label/field/choice 协议、打包配置由集成人维护。确有缺口交最小失败场景与具体需要,不自行大幅改写。
|
||||
|
||||
先读 AGENTS.md、docs/decisions/overlay-foundation.md、docs/migrations/OVERLAY-02-modal-popover-tooltip.md 和近期 M30–M32 复核/验收记录。固定 HeroUI 3.2.6 / ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960,参考 ../heroui,只读、不运行 React 包装 Vue。
|
||||
|
||||
## M33 AlertDialog
|
||||
|
||||
核对上游 components/alert-dialog/index.ts、alert-dialog.tsx、源 CSS/tv、中文正文及全部演示。
|
||||
|
||||
交付 AlertDialog/Root、Trigger、Backdrop、Container、Dialog、Header、Heading、Body、Footer、Icon、CloseTrigger 以及各公共 Props、alertDialogVariants/类型。不能把普通 Modal 换个名字就宣称完整支持:实际 role=alertdialog、标题/说明、初始焦点/取消按钮政策、焦点限制/恢复与禁止误关闭需要验收。
|
||||
|
||||
特别注意固定基线 Backdrop 默认 isDismissable=false、isKeyboardDismissDisabled=true,不能继承普通 Modal 的默认值。二者独立可配置;状态/尺寸/位置/图标等按真正所属部件核对,不随意挪到 Root。
|
||||
|
||||
中文正文十四个预览全部迁移,顺序为 default、statuses、placements、sizes、controlled、custom-icon、custom-trigger、backdrop-variants、custom-backdrop、dismiss-behavior、close-methods、custom-animations、custom-portal、custom-styles。以实际多行预览清单再次核对,不只按单行 grep。
|
||||
|
||||
先用安装版 Reka AlertDialog 验证与现有 Dialog/Popover 的锁、焦点和 Presence 互操作,再封装。底层缺口写失败用例,不伪造 ARIA 或删掉公开能力。破坏性操作示例只改变本地演示状态,不调用真实外部服务。
|
||||
|
||||
## M34 Drawer
|
||||
|
||||
M33 的关键行为通过后继续 Drawer。核对 Drawer/Root、Trigger、Backdrop、Content、Dialog、Header、Heading、Body、Footer、Handle、CloseTrigger、公共 Props、drawerVariants/类型,保留 Content 与 Dialog 的不同职责。
|
||||
|
||||
固定源并非“任意 Drawer 库的默认行为”:上游有自己的四方向拖动算法,阈值为尺寸 30% 或速度 0.5px/ms。安装版 Reka Drawer 先做实际能力审计,再决定局部适配;不采用停止维护的 Vaul Vue,也不因为底座有 snaps 就擅自把它加入本库公开契约。
|
||||
|
||||
重点核对 placement 的 top/bottom/left/right、滚动内容与拖动识别、handle、拖动距离/快速甩动关闭、未达阈值的回弹、isDismissable=false、指针取消/丢失捕获、方向改变、卸载清理。禁用拖动关闭与禁用 Escape 是否独立,按源实行为准。
|
||||
|
||||
九个中文正文预览:basic、placements、non-dismissable、scrollable-content、controlled、with-form、navigation、backdrop-variants、custom-styles。形状、边缘距离、圆角、尺寸、遮罩、动效、滚动区和表单布局保持基线一致,不用只会淡入淡出的侧边卡片代替 Drawer。
|
||||
|
||||
## 共同要求
|
||||
|
||||
- 源 CSS/主题数值优先移植并适配 hv-、真实 data/ARIA 与定位原点。退出 Presence、快速开关、退出中重开、reduced-motion、自定义动画和容器/内容不同动画时长都核对;不能用固定 timeout 假装结束动画。
|
||||
- 受控/非受控、初始空状态、父拒绝、动态 attrs/ID/语言方向、disabled Trigger、asChild、单一事件、事件数组/capture/preventDefault/stopImmediatePropagation 分别检查。用 Vue DOM 合并,不手工循环用户回调,不依赖私有 invoker 标记。
|
||||
- 标题/描述必须关联实际 role 节点。名称计算按真实 ARIA 优先级核验,不能只看 for/id 或外层字符串;显式属性、多个实例和同页所有演示的 ID 要一起测。新错误响应/关闭状态不能从 setup 快照读取。
|
||||
- 所有预览、复制、高亮共用同一 SFC;自定义示例图标使用 Tabler Vue。默认基线图标移植记录许可。中文文案、全部预览与 API 表格/导航同步,长短表都铺满正文、长内容换行,不横向拖动、不缩字号。
|
||||
- 类型/事件签名明确,正反类型检查不得退化为 any。使用新 main 的声明构建钩子,不能回退 ESM .js 路径修复。独立产物消费参考 tests/package,不以源码 alias 或只通过正例代替验证。
|
||||
- 有状态交互必须断言真实 DOM/焦点/值/关闭原因或事件;不能只断言组件仍挂载。SSR 字符串、真正 node 环境、实际水合分开记录,不在 jsdom 测试标题中宣称已验证没有浏览器全局。
|
||||
|
||||
## 验收与交回
|
||||
|
||||
分别提交 docs/migrations/M33-alert-dialog.md、M34-drawer.md:来源/部件/API/预览清单、底座审计、实际差异、变更文件、测试命令和数量、浏览器证据、未验证项、需要集成人处理的缺口。
|
||||
|
||||
运行适用的 pnpm test、typecheck、build、build:docs、声明/独立安装检查。浏览器重点验证警告弹层默认不误关、嵌套焦点/锁、Drawer 四方向拖动/滚动/回弹及退出;不要求逐个点击全部预览。自动编译挂载全部预览仍需执行。
|
||||
|
||||
未验证的真机触屏、读屏、Nuxt、逐像素比较如实列出。一个家族失败不能把另一个的绿灯当成整个批次通过。完成后停在当前任务分支交回复核,下一项任务再从最新 main 开新分支。
|
||||
@@ -141,3 +141,10 @@ M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生
|
||||
- CN components/(utilities)/scroll-shadow.mdx 与 (navigation)/tabs.mdx,demos/cn/scroll-shadow(7 例)、tabs(10 例):文案、次序、结构与样式;预览/复制/高亮仍共用 SFC。内置四向 Chevron 路径直接来自固定 icons.tsx,非自绘演示图标。
|
||||
- VueUse core 14.4.0(MIT,既有锁文件版本新增为直接依赖),使用 ResizeObserver/MutationObserver/事件工具,库产物 external 并由 dependencies 声明;未复制 VueUse 实现。Reka 2.11.0 的 Tabs/RovingFocus/Presence 保留为交互底座。
|
||||
- React SelectionIndicator 改为共享布局测量与各 Tab 的装饰性指示器,保持 250ms ease-out-fluid 的 translate/width/height 过渡。布局坐标避免祖先 Modal 缩放污染测量。React hook 改为 Vue 响应式输入与 attributes 显式绑定。
|
||||
|
||||
## M30–M32 来源(2026-10-23)
|
||||
|
||||
- 固定 ce90ea3 的 packages/react/src/components/{pagination,header,input-otp} 与对应 styles CSS/tv、cn 文档与 demos/cn/{pagination,input-otp}。Header 无独立 cn 页与演示目录。
|
||||
- pagination.css、header.css、input-otp.css 及 tv 完整移植 hv- 命名空间;Pagination 默认 chevron 来自基线 icons.tsx(Apache-2.0)。演示图标为 Tabler Vue。
|
||||
- Pagination Link/Previous/Next 对应 RAC Button;Header 对应 RAC Header(`dom.header`)。InputOTP 上游为 input-otp 包(MIT),Vue 使用安装版 Reka PinInput 2.11.0(MIT)做多 input 适配,未引入 React input-otp 运行时。
|
||||
- 中文 pagination.mdx / input-otp.mdx 的 9+11 预览、API/样式表按基线次序迁移;Header 页为自编并标注。
|
||||
|
||||
@@ -545,3 +545,50 @@ typecheck、build:docs、build:playground、format、diff-check 与 dist 正反
|
||||
- 水合、独立安装、读屏、逐像素仍未验证。
|
||||
|
||||
详见 [M29 报告](./migrations/M29-toolbar.md)。
|
||||
|
||||
## M30–M32 实施记录(2026-10-23,实施者,待复核)
|
||||
|
||||
- Pagination 16 + Header 8 + InputOTP 15 专项测试;9+3+11 演示挂载无 Vue warning。
|
||||
- 浏览器重点验证(controlled 翻页、键盘、OTP 中间删除/粘贴)**本轮未执行**,不以 jsdom 代替。
|
||||
- 水合、独立安装、读屏/触屏、逐像素、Nuxt **未验证**。
|
||||
|
||||
详见 [M30](./migrations/M30-pagination.md)、[M31](./migrations/M31-header.md)、[M32](./migrations/M32-input-otp.md)。
|
||||
|
||||
### 最终计数(实施者,2026-10-23)
|
||||
|
||||
- `pnpm test` **31 文件 / 522**(含 SSR 15)
|
||||
- `pnpm test:unit` **30 文件 / 507**(pagination 16 + header 8 + input-otp 15 = 39 新增)
|
||||
- `pnpm test:ssr` 15 通过
|
||||
- `pnpm typecheck`、`build:docs`、`build:playground`、`format`、`git diff --check` 通过
|
||||
- docs 构建有既有 chunk 大小提示,未做体积优化验收
|
||||
|
||||
浏览器 controlled 翻页/键盘/OTP 中间删除粘贴本轮未执行真实点击;水合、独立安装、读屏、逐像素、Nuxt 仍未验证。
|
||||
|
||||
## M30–M32 复核返修(2026-10-23,实施者)
|
||||
|
||||
- `tests/m30-m32-review.probe.test.ts` **10/10 通过**(保留独立回归,未弱化断言)。
|
||||
- `pnpm test` **32 文件 / 534**(含 SSR 15、探针 10);`test:unit` 见命令列表含 probe;typecheck 通过。
|
||||
- reset / 受控中间删除 / 拒绝重试 / readonly / Fieldset / Form 错误 / ARIA / mask / class 合并 / Pagination aria-current 已按复核修复并补入正式专项测试。
|
||||
- 浏览器重点验证、水合、独立安装、读屏、逐像素仍未执行。
|
||||
|
||||
### 返修后计数(实施者)
|
||||
|
||||
- `pnpm test` **32 文件 / 534**(含 SSR 15、m30-m32 探针 10)
|
||||
- `pnpm test:unit` **31 文件 / 519**(含 m30-m32 探针)
|
||||
- `pnpm test:ssr` 15;`typecheck` / `build:docs` / `build:playground` / `format` / `git diff --check` 通过
|
||||
|
||||
## M30–M32 第二轮独立复核(2026-10-23)
|
||||
|
||||
- 追加回归前:32 文件 / 534 项通过,类型检查通过。上轮十个失败用例已全部通过。
|
||||
- 扩展 tests/m30-m32-review.probe.test.ts 后:十八项中十一项通过、七项失败;不能继续宣称当前完整测试全绿。动态 readonly 新用例通过;真实命名、正则、取消/事件数组、旧错误消退、长度空槽和演示重复 ID 仍有缺口。
|
||||
- 本批暂不提交,未重做全量浏览器/完整构建/安装验收。详见 [第二轮复核与返修提示词](migrations/M30-M32-review-2.md)。
|
||||
|
||||
## M30–M32 第二轮返修(2026-10-23,实施者)
|
||||
|
||||
- `tests/m30-m32-review.probe.test.ts` **18/18 通过**(含二轮新增 8 项,断言未削弱)。
|
||||
- `pnpm test` **32 文件 / 542**(含 SSR 15、探针 18);`test:unit` **31 / 527**;typecheck / build:docs / build:playground / format 通过。
|
||||
- 浏览器、水合、独立安装、读屏、触屏、IME、自动填充仍未执行。
|
||||
|
||||
## M30–M32 最终验收
|
||||
|
||||
前两轮失败为历史记录,均已修复。当前集成前 33 文件 / 544 项通过,含十九项复核回归和真正 node SSR;类型/库与文档构建通过。集成人补齐 ARIA 名称优先级及九份外置标签演示关联,5173 浏览器已重点验证。详见 [最终验收](migrations/M30-M32-acceptance.md),整合远程 main 后另记总数。
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@
|
||||
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
||||
"typecheck": "vue-tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts",
|
||||
"format": "prettier --check .",
|
||||
"format:fix": "prettier --write .",
|
||||
"dev:playground": "pnpm build && pnpm --filter @heroui-vue/playground dev"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
/* ==========================================================================
|
||||
Base header styles (collection / group section heading)
|
||||
========================================================================== */
|
||||
|
||||
.hv-header {
|
||||
@apply w-full px-2 pt-1.5 pb-1 text-start text-xs font-medium text-muted;
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix; Vue state adapters. */
|
||||
/* ==========================================================================
|
||||
InputOTP - one-time password input
|
||||
========================================================================== */
|
||||
|
||||
/* Base container */
|
||||
.hv-input-otp {
|
||||
@apply relative flex w-full items-center gap-2;
|
||||
|
||||
&[data-disabled="true"] {
|
||||
@apply cursor-not-allowed opacity-50;
|
||||
}
|
||||
}
|
||||
|
||||
/* Group - slots separated with gap */
|
||||
.hv-input-otp__group {
|
||||
@apply flex min-w-0 items-center gap-2;
|
||||
}
|
||||
|
||||
/* Individual slot box - fully rounded, standalone */
|
||||
.hv-input-otp__slot {
|
||||
@apply relative flex h-10 w-9.5 min-w-0 flex-1 items-center justify-center;
|
||||
@apply border bg-field text-field-foreground shadow-field;
|
||||
@apply rounded-field text-sm font-semibold outline-none;
|
||||
|
||||
border-width: var(--border-width-field);
|
||||
border-color: var(--field-border);
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
background-color 150ms var(--ease-smooth),
|
||||
border-color 150ms var(--ease-smooth),
|
||||
box-shadow 150ms var(--ease-out);
|
||||
@apply motion-reduce:transition-none;
|
||||
|
||||
/* Hover */
|
||||
@media (hover: hover) {
|
||||
&:hover,
|
||||
&[data-hovered="true"] {
|
||||
@apply bg-field-hover;
|
||||
border-color: var(--field-border-hover);
|
||||
}
|
||||
}
|
||||
|
||||
/* Active/Focus */
|
||||
&[data-active="true"] {
|
||||
@apply z-10 bg-field-focus status-focused-field;
|
||||
}
|
||||
|
||||
/* Filled */
|
||||
&[data-filled="true"] {
|
||||
@apply bg-field-focus;
|
||||
}
|
||||
|
||||
/* Disabled */
|
||||
&[data-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
|
||||
/* Invalid */
|
||||
&[data-invalid="true"] {
|
||||
@apply status-invalid-field;
|
||||
background-color: var(--field-focus);
|
||||
}
|
||||
}
|
||||
|
||||
/* Real inputs sit transparently over the visual slot */
|
||||
.hv-input-otp__input {
|
||||
@apply absolute inset-0 z-10 h-full w-full cursor-text bg-transparent text-transparent caret-transparent outline-none;
|
||||
}
|
||||
|
||||
/* Slot value */
|
||||
.hv-input-otp__slot-value {
|
||||
@apply text-lg leading-6 tracking-[-0.27px];
|
||||
|
||||
/**
|
||||
* Animations
|
||||
* CRITICAL: motion-reduce must be AFTER animation for correct override specificity
|
||||
*/
|
||||
animation: hv-slot-value-in 250ms var(--ease-smooth) both;
|
||||
transform-origin: bottom center;
|
||||
@apply motion-reduce:animate-none;
|
||||
}
|
||||
|
||||
/* Caret */
|
||||
.hv-input-otp__caret {
|
||||
@apply absolute h-4 w-[2px] animate-caret-blink rounded-sm bg-field-placeholder;
|
||||
}
|
||||
|
||||
/* Separator */
|
||||
.hv-input-otp__separator {
|
||||
@apply h-[2px] w-[6px] shrink-0 rounded-sm bg-separator;
|
||||
}
|
||||
|
||||
/* Variant property definitions */
|
||||
.hv-input-otp--primary {
|
||||
/* Default styles */
|
||||
}
|
||||
|
||||
.hv-input-otp--secondary .hv-input-otp__slot {
|
||||
@apply shadow-none;
|
||||
background-color: var(--input-otp-slot-bg);
|
||||
|
||||
--input-otp-slot-bg: var(--default);
|
||||
--input-otp-slot-bg-hover: var(--default-hover);
|
||||
--input-otp-slot-bg-focus: var(--default);
|
||||
|
||||
@media (hover: hover) {
|
||||
&:hover,
|
||||
&[data-hovered="true"] {
|
||||
background-color: var(--input-otp-slot-bg-hover);
|
||||
}
|
||||
}
|
||||
|
||||
&[data-active="true"],
|
||||
&[data-filled="true"] {
|
||||
background-color: var(--input-otp-slot-bg-focus);
|
||||
}
|
||||
}
|
||||
|
||||
/* Animations */
|
||||
@keyframes hv-slot-value-in {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(8px) scale(0.8);
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
/* ==========================================================================
|
||||
Pagination - Page navigation component
|
||||
========================================================================== */
|
||||
|
||||
/* Base styles */
|
||||
.hv-pagination {
|
||||
@apply flex w-full flex-col items-center justify-between gap-4 sm:flex-row;
|
||||
}
|
||||
|
||||
/* Summary - left side info container */
|
||||
.hv-pagination__summary {
|
||||
@apply flex items-center gap-2 self-start text-sm text-muted sm:self-center;
|
||||
}
|
||||
|
||||
/* Content - container for pagination items */
|
||||
.hv-pagination__content {
|
||||
@apply flex items-center gap-1 self-start sm:self-center;
|
||||
}
|
||||
|
||||
/* Item - list item wrapper */
|
||||
.hv-pagination__item {
|
||||
@apply inline-flex;
|
||||
}
|
||||
|
||||
/* Link - page number button (ghost button style) */
|
||||
.hv-pagination__link {
|
||||
@apply relative isolate inline-flex size-9 origin-center items-center justify-center rounded-3xl text-sm font-medium whitespace-nowrap outline-none select-none no-highlight md:size-8;
|
||||
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
transform 250ms var(--ease-smooth),
|
||||
background-color 100ms var(--ease-out),
|
||||
box-shadow 100ms var(--ease-out);
|
||||
@apply transform-gpu motion-reduce:transition-none;
|
||||
|
||||
/* Ghost button tokens */
|
||||
--pagination-link-bg: transparent;
|
||||
--pagination-link-bg-hover: var(--default-hover);
|
||||
--pagination-link-bg-pressed: var(--default-hover);
|
||||
--pagination-link-fg: var(--default-foreground);
|
||||
|
||||
background-color: var(--pagination-link-bg);
|
||||
color: var(--pagination-link-fg);
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible,
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&:disabled,
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
|
||||
/* Hover state */
|
||||
@media (hover: hover) {
|
||||
&:hover,
|
||||
&[data-hovered="true"] {
|
||||
background-color: var(--pagination-link-bg-hover);
|
||||
}
|
||||
}
|
||||
|
||||
/* Active / pressed */
|
||||
&:active,
|
||||
&[data-pressed="true"] {
|
||||
background-color: var(--pagination-link-bg-pressed);
|
||||
transform: scale(0.97);
|
||||
}
|
||||
|
||||
/* Active page - tertiary button style */
|
||||
&[data-active="true"] {
|
||||
--pagination-link-bg: var(--default);
|
||||
--pagination-link-bg-hover: var(--default-hover);
|
||||
--pagination-link-bg-pressed: var(--default-hover);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ellipsis */
|
||||
.hv-pagination__ellipsis {
|
||||
@apply inline-flex size-9 items-center justify-center text-sm text-muted select-none md:size-8;
|
||||
}
|
||||
|
||||
/* Navigation buttons (Previous / Next) */
|
||||
.hv-pagination__link--nav {
|
||||
@apply w-auto gap-1.5 px-2.5;
|
||||
|
||||
& [data-slot="pagination-previous-icon"],
|
||||
& [data-slot="pagination-next-icon"] {
|
||||
@apply rtl:rotate-180;
|
||||
}
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Size variants
|
||||
========================================================================== */
|
||||
|
||||
.hv-pagination--sm {
|
||||
.hv-pagination__link {
|
||||
@apply size-8 text-xs md:size-7;
|
||||
|
||||
&:active,
|
||||
&[data-pressed="true"] {
|
||||
transform: scale(0.98);
|
||||
}
|
||||
}
|
||||
|
||||
.hv-pagination__link--nav {
|
||||
@apply w-auto px-2;
|
||||
}
|
||||
|
||||
.hv-pagination__ellipsis {
|
||||
@apply size-8 text-xs md:size-7;
|
||||
}
|
||||
|
||||
.hv-pagination__summary {
|
||||
@apply text-xs;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-pagination--md {
|
||||
/* No styles as this is the default size */
|
||||
}
|
||||
|
||||
.hv-pagination--lg {
|
||||
.hv-pagination__link {
|
||||
@apply size-10 text-base md:size-9;
|
||||
|
||||
&:active,
|
||||
&[data-pressed="true"] {
|
||||
transform: scale(0.96);
|
||||
}
|
||||
}
|
||||
|
||||
.hv-pagination__link--nav {
|
||||
@apply w-auto px-3;
|
||||
}
|
||||
|
||||
.hv-pagination__ellipsis {
|
||||
@apply size-10 text-base md:size-9;
|
||||
}
|
||||
|
||||
.hv-pagination__summary {
|
||||
@apply text-base;
|
||||
}
|
||||
}
|
||||
@@ -134,3 +134,6 @@
|
||||
@import "./components/toggle-button.css" layer(components);
|
||||
@import "./components/toggle-button-group.css" layer(components);
|
||||
@import "./components/toolbar.css" layer(components);
|
||||
@import "./components/pagination.css" layer(components);
|
||||
@import "./components/header.css" layer(components);
|
||||
@import "./components/input-otp.css" layer(components);
|
||||
|
||||
@@ -1167,3 +1167,65 @@ export const toolbarVariants = tv({
|
||||
});
|
||||
|
||||
export type ToolbarVariants = VariantProps<typeof toolbarVariants>;
|
||||
|
||||
export const paginationVariants = tv({
|
||||
defaultVariants: {
|
||||
size: "md",
|
||||
},
|
||||
slots: {
|
||||
base: "hv-pagination",
|
||||
content: "hv-pagination__content",
|
||||
ellipsis: "hv-pagination__ellipsis",
|
||||
item: "hv-pagination__item",
|
||||
link: "hv-pagination__link",
|
||||
summary: "hv-pagination__summary",
|
||||
},
|
||||
variants: {
|
||||
size: {
|
||||
lg: {
|
||||
base: "hv-pagination--lg",
|
||||
},
|
||||
md: {
|
||||
base: "hv-pagination--md",
|
||||
},
|
||||
sm: {
|
||||
base: "hv-pagination--sm",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type PaginationVariants = VariantProps<typeof paginationVariants>;
|
||||
|
||||
export const headerVariants = tv({
|
||||
base: "hv-header",
|
||||
});
|
||||
|
||||
export type HeaderVariants = VariantProps<typeof headerVariants>;
|
||||
|
||||
export const inputOTPVariants = tv({
|
||||
defaultVariants: {
|
||||
variant: "primary",
|
||||
},
|
||||
slots: {
|
||||
base: "hv-input-otp",
|
||||
caret: "hv-input-otp__caret",
|
||||
group: "hv-input-otp__group",
|
||||
input: "hv-input-otp__input",
|
||||
separator: "hv-input-otp__separator",
|
||||
slot: "hv-input-otp__slot",
|
||||
slotValue: "hv-input-otp__slot-value",
|
||||
},
|
||||
variants: {
|
||||
variant: {
|
||||
primary: {
|
||||
base: "hv-input-otp--primary",
|
||||
},
|
||||
secondary: {
|
||||
base: "hv-input-otp--secondary",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type InputOTPVariants = VariantProps<typeof inputOTPVariants>;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, useAttrs } from "vue";
|
||||
import { headerVariants } from "@heroui-vue/styles";
|
||||
|
||||
/**
|
||||
* Collection / group section heading (RAC Header).
|
||||
* Not an application top bar with logo or navigation.
|
||||
* Renders a native `<header>` by default — matching the fixed RAC contract.
|
||||
*/
|
||||
export default defineComponent({
|
||||
name: "HeaderRoot",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
/** Render the root as a custom element instead of `header`. */
|
||||
as: {
|
||||
type: String,
|
||||
default: "header",
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
|
||||
function render() {
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
class: [headerVariants(), attrs.class],
|
||||
"data-slot": "header",
|
||||
},
|
||||
slots.default?.(),
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,33 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, useAttrs } from "vue";
|
||||
import { inputOTPContextKey } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "InputOTPGroup",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
as: {
|
||||
type: String,
|
||||
default: "div",
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const context = inject(inputOTPContextKey, null);
|
||||
|
||||
function render() {
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
class: [context?.slots.value.group(), attrs.class],
|
||||
"data-slot": "input-otp-group",
|
||||
},
|
||||
slots.default?.(),
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,439 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
cloneVNode,
|
||||
Fragment,
|
||||
isVNode,
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
inject,
|
||||
nextTick,
|
||||
onBeforeUnmount,
|
||||
onMounted,
|
||||
onUpdated,
|
||||
provide,
|
||||
ref,
|
||||
shallowRef,
|
||||
useAttrs,
|
||||
useId,
|
||||
watch,
|
||||
type PropType,
|
||||
type VNode,
|
||||
type VNodeChild,
|
||||
} from "vue";
|
||||
import { PinInputRoot } from "reka-ui";
|
||||
import { inputOTPVariants, type InputOTPVariants } from "@heroui-vue/styles";
|
||||
import { useInheritedDisabled } from "../field/disabled";
|
||||
import {
|
||||
errorMessages,
|
||||
fieldContextKey,
|
||||
formContextKey,
|
||||
mergeIds,
|
||||
type FieldContext,
|
||||
} from "../field/context";
|
||||
import {
|
||||
charsFromString,
|
||||
inputOTPContextKey,
|
||||
stringFromChars,
|
||||
} from "./context";
|
||||
|
||||
const EMPTY_ERRORS: string[] = [];
|
||||
|
||||
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;
|
||||
const flags = re.flags.replace(/[gy]/g, "");
|
||||
return new RegExp(re.source, flags).test(char);
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "InputOTPRoot",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
/** Public string value; character at index i occupies slot i. */
|
||||
modelValue: {
|
||||
type: String,
|
||||
default: undefined,
|
||||
},
|
||||
defaultValue: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
maxLength: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
variant: {
|
||||
type: String as PropType<InputOTPVariants["variant"]>,
|
||||
default: "primary",
|
||||
},
|
||||
isDisabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
isReadOnly: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
isInvalid: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
validationErrors: {
|
||||
type: Array as PropType<string[]>,
|
||||
default: undefined,
|
||||
},
|
||||
/** Class applied to the real PinInput inputs (merged with structure class). */
|
||||
inputClassName: {
|
||||
type: String,
|
||||
default: undefined,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
default: undefined,
|
||||
},
|
||||
required: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
mask: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
/** Enables one-time-code autofill attributes on the real inputs. */
|
||||
otp: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
/** Character filter, e.g. REGEXP_ONLY_DIGITS. */
|
||||
pattern: {
|
||||
type: [String, RegExp] as PropType<string | RegExp>,
|
||||
default: undefined,
|
||||
},
|
||||
id: {
|
||||
type: String,
|
||||
default: undefined,
|
||||
},
|
||||
},
|
||||
emits: ["update:modelValue", "change", "complete"],
|
||||
setup(props, { emit, slots }) {
|
||||
const attrs = useAttrs();
|
||||
const autoId = useId();
|
||||
const form = inject(formContextKey, undefined);
|
||||
const length = computed(() => Math.max(0, props.maxLength | 0));
|
||||
const pattern = computed<RegExp | null>(() => {
|
||||
if (!props.pattern) return null;
|
||||
return typeof props.pattern === "string"
|
||||
? new RegExp(props.pattern)
|
||||
: props.pattern;
|
||||
});
|
||||
|
||||
const isControlled = computed(() => props.modelValue !== undefined);
|
||||
const initial = props.defaultValue ?? "";
|
||||
const startPublic = isControlled.value ? (props.modelValue ?? "") : initial;
|
||||
|
||||
/** Index-preserving slot characters; "" keeps a middle empty slot. */
|
||||
const slotChars = ref<string[]>(charsFromString(startPublic, length.value));
|
||||
/** Last string we emitted; parent echo keeps holes in slotChars. */
|
||||
let lastEmitted = startPublic;
|
||||
|
||||
const disabled = useInheritedDisabled(
|
||||
() => props.isDisabled || attrBoolean(attrs.disabled),
|
||||
);
|
||||
const readOnly = computed(
|
||||
() =>
|
||||
props.isReadOnly ||
|
||||
attrBoolean(attrs.readonly) ||
|
||||
attrBoolean(attrs.readOnly),
|
||||
);
|
||||
|
||||
const descriptionIds = ref<string[]>([]);
|
||||
const errorIds = ref<string[]>([]);
|
||||
const labelIds = ref<string[]>([]);
|
||||
const plannedLabels = ref<string[]>([]);
|
||||
const labelledBy = computed(
|
||||
() =>
|
||||
(attrs["aria-labelledby"] as string | undefined) ??
|
||||
(attrs["aria-label"]
|
||||
? undefined
|
||||
: mergeIds(plannedLabels.value, labelIds.value)),
|
||||
);
|
||||
const accessibleLabel = computed(
|
||||
() => attrs["aria-label"] as string | undefined,
|
||||
);
|
||||
|
||||
// shallowRef keeps object identity for response comparison (see useTextField).
|
||||
const dismissed = shallowRef<object | undefined>();
|
||||
const serverErrors = computed(() => {
|
||||
const source = form?.validationErrors.value;
|
||||
return source && source !== dismissed.value && props.name
|
||||
? errorMessages(source[props.name])
|
||||
: EMPTY_ERRORS;
|
||||
});
|
||||
|
||||
const invalid = computed(
|
||||
() =>
|
||||
props.isInvalid ||
|
||||
(props.validationErrors?.length ?? 0) > 0 ||
|
||||
serverErrors.value.length > 0 ||
|
||||
attrs["aria-invalid"] === true ||
|
||||
attrs["aria-invalid"] === "true",
|
||||
);
|
||||
const errors = computed(() => [
|
||||
...(props.validationErrors ?? EMPTY_ERRORS),
|
||||
...serverErrors.value,
|
||||
]);
|
||||
|
||||
const resolvedId = computed(() => props.id ?? autoId);
|
||||
/** Stable id per real focusable input; Label `for` uses index 0. */
|
||||
function inputId(index: number): string {
|
||||
return `${resolvedId.value}-slot-${index}`;
|
||||
}
|
||||
|
||||
provide(fieldContextKey, {
|
||||
controlId: computed(() => inputId(0)),
|
||||
kind: "text",
|
||||
disabled,
|
||||
readOnly,
|
||||
required: computed(() => props.required),
|
||||
invalid,
|
||||
errors,
|
||||
labelIds,
|
||||
descriptionIds,
|
||||
errorIds,
|
||||
} satisfies FieldContext);
|
||||
|
||||
/**
|
||||
* Display/input characters. When the parent echoes our emission the
|
||||
* hole-preserving array is kept so middle deletes do not left-shift.
|
||||
*/
|
||||
const chars = computed(() => [...slotChars.value]);
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(next, prev) => {
|
||||
if (!isControlled.value) return;
|
||||
if (next === prev) return;
|
||||
const incoming = next ?? "";
|
||||
// Echo of our own proposal — keep the index-preserving array.
|
||||
if (incoming === lastEmitted) return;
|
||||
lastEmitted = incoming;
|
||||
slotChars.value = charsFromString(incoming, length.value);
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => length.value,
|
||||
(nextLen) => {
|
||||
// Pad/crop by index — do not serialize, or empty slots left-shift.
|
||||
const prev = slotChars.value;
|
||||
if (nextLen > prev.length) {
|
||||
slotChars.value = [
|
||||
...prev,
|
||||
...Array.from({ length: nextLen - prev.length }, () => ""),
|
||||
];
|
||||
} else if (nextLen < prev.length) {
|
||||
slotChars.value = prev.slice(0, nextLen);
|
||||
}
|
||||
const proposed = stringFromChars(slotChars.value);
|
||||
const currentPublic = isControlled.value
|
||||
? (props.modelValue ?? "")
|
||||
: lastEmitted;
|
||||
if (proposed !== currentPublic) {
|
||||
lastEmitted = proposed;
|
||||
emit("update:modelValue", proposed);
|
||||
emit("change", proposed);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
function applyChars(next: unknown[]) {
|
||||
if (disabled.value || readOnly.value) return;
|
||||
const clamped = Array.from({ length: length.value }, (_, i) => {
|
||||
const raw = next[i];
|
||||
return raw == null ? "" : String(raw);
|
||||
});
|
||||
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] = "";
|
||||
}
|
||||
}
|
||||
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;
|
||||
// Always request a change when the proposal differs from the public
|
||||
// value so a rejected update can be retried with the same characters.
|
||||
if (proposed !== currentPublic) {
|
||||
lastEmitted = proposed;
|
||||
// Effective edit dismisses the current server-error response.
|
||||
dismissed.value = form?.validationErrors.value;
|
||||
emit("update:modelValue", proposed);
|
||||
emit("change", proposed);
|
||||
void nextTick(() => {
|
||||
if (!isControlled.value) return;
|
||||
const publicValue = props.modelValue ?? "";
|
||||
if (publicValue !== lastEmitted) {
|
||||
// Parent rejected the proposal — restore from the public value.
|
||||
slotChars.value = charsFromString(publicValue, length.value);
|
||||
lastEmitted = publicValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
if (
|
||||
prevFilled < length.value &&
|
||||
nextFilled === length.value &&
|
||||
length.value > 0
|
||||
) {
|
||||
emit("complete", proposed);
|
||||
}
|
||||
}
|
||||
|
||||
function handlePinUpdate(value: unknown) {
|
||||
applyChars(Array.isArray(value) ? value : []);
|
||||
}
|
||||
|
||||
const describedBy = computed(() =>
|
||||
mergeIds(
|
||||
attrs["aria-describedby"] as string | undefined,
|
||||
descriptionIds.value,
|
||||
invalid.value ? errorIds.value : [],
|
||||
),
|
||||
);
|
||||
|
||||
function reset(event: Event) {
|
||||
void nextTick(() => {
|
||||
if (event.defaultPrevented) return;
|
||||
if (!isControlled.value) {
|
||||
slotChars.value = charsFromString(initial, length.value);
|
||||
lastEmitted = initial;
|
||||
} else {
|
||||
const incoming = props.modelValue ?? "";
|
||||
lastEmitted = incoming;
|
||||
slotChars.value = charsFromString(incoming, length.value);
|
||||
}
|
||||
dismissed.value = form?.validationErrors.value;
|
||||
});
|
||||
}
|
||||
|
||||
const rootEl = ref<HTMLElement | null>(null);
|
||||
function setRoot(el: unknown) {
|
||||
const node = (el as { $el?: HTMLElement } | HTMLElement | null) ?? null;
|
||||
const next = !node
|
||||
? null
|
||||
: node instanceof HTMLElement
|
||||
? node
|
||||
: ((node.$el as HTMLElement) ?? null);
|
||||
rootEl.value = next;
|
||||
}
|
||||
|
||||
let formEl: HTMLFormElement | null = null;
|
||||
function bindForm() {
|
||||
const next = rootEl.value?.closest("form") ?? null;
|
||||
if (next === formEl) return;
|
||||
formEl?.removeEventListener("reset", reset);
|
||||
formEl = next;
|
||||
formEl?.addEventListener("reset", reset);
|
||||
}
|
||||
onMounted(bindForm);
|
||||
onUpdated(bindForm);
|
||||
onBeforeUnmount(() => {
|
||||
formEl?.removeEventListener("reset", reset);
|
||||
formEl = null;
|
||||
});
|
||||
|
||||
const variantSlots = computed(() =>
|
||||
inputOTPVariants({ variant: props.variant }),
|
||||
);
|
||||
provide(inputOTPContextKey, {
|
||||
slots: variantSlots,
|
||||
isDisabled: disabled,
|
||||
isInvalid: invalid,
|
||||
isReadOnly: readOnly,
|
||||
maxLength: length,
|
||||
pattern,
|
||||
chars,
|
||||
mask: computed(() => props.mask),
|
||||
inputClassName: computed(() => props.inputClassName),
|
||||
describedBy,
|
||||
inputId,
|
||||
labelledBy,
|
||||
accessibleLabel,
|
||||
});
|
||||
|
||||
function prepareLabels(
|
||||
nodes: VNodeChild[],
|
||||
ids: string[],
|
||||
path = "",
|
||||
): VNodeChild[] {
|
||||
return nodes.map((node, index) => {
|
||||
if (!isVNode(node)) return node;
|
||||
const type = node.type as { name?: string; __name?: string };
|
||||
if ((type.name ?? type.__name) === "Label") {
|
||||
const id = String(
|
||||
node.props?.id ?? `${autoId}-label${path}-${index}`,
|
||||
);
|
||||
ids.push(id);
|
||||
return cloneVNode(node, { id });
|
||||
}
|
||||
if (
|
||||
(typeof node.type === "string" || node.type === Fragment) &&
|
||||
Array.isArray(node.children)
|
||||
) {
|
||||
const copy = cloneVNode(node);
|
||||
copy.children = prepareLabels(
|
||||
node.children as VNodeChild[],
|
||||
ids,
|
||||
`${path}-${index}`,
|
||||
) as VNode[];
|
||||
return copy;
|
||||
}
|
||||
return node;
|
||||
});
|
||||
}
|
||||
function render() {
|
||||
const labels: string[] = [];
|
||||
const children = prepareLabels(slots.default?.() ?? [], labels);
|
||||
if (JSON.stringify(labels) !== JSON.stringify(plannedLabels.value))
|
||||
plannedLabels.value = labels;
|
||||
return h(
|
||||
PinInputRoot,
|
||||
{
|
||||
ref: setRoot,
|
||||
modelValue: chars.value,
|
||||
disabled: disabled.value,
|
||||
mask: props.mask,
|
||||
otp: props.otp,
|
||||
placeholder: props.placeholder,
|
||||
name: props.name,
|
||||
required: props.required,
|
||||
id: resolvedId.value,
|
||||
"onUpdate:modelValue": handlePinUpdate,
|
||||
...attrs,
|
||||
class: [variantSlots.value.base(), attrs.class],
|
||||
"data-disabled": disabled.value || undefined,
|
||||
"data-invalid": invalid.value ? "true" : undefined,
|
||||
"data-slot": "input-otp",
|
||||
},
|
||||
{ default: () => children },
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,33 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, useAttrs } from "vue";
|
||||
import { inputOTPContextKey } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "InputOTPSeparator",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
as: {
|
||||
type: String,
|
||||
default: "div",
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const context = inject(inputOTPContextKey, null);
|
||||
|
||||
function render() {
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
class: [context?.slots.value.separator(), attrs.class],
|
||||
"data-slot": "input-otp-separator",
|
||||
},
|
||||
slots.default?.(),
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,189 @@
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, h, inject, ref, useAttrs } from "vue";
|
||||
import { PinInputInput } from "reka-ui";
|
||||
import { inputOTPContextKey } from "./context";
|
||||
|
||||
type Handler = (event: Event) => void;
|
||||
|
||||
function toHandlerArray(value: unknown): Handler[] {
|
||||
if (!value) return [];
|
||||
if (Array.isArray(value)) {
|
||||
return value.filter((item): item is Handler => typeof item === "function");
|
||||
}
|
||||
return typeof value === "function" ? [value as Handler] : [];
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "InputOTPSlot",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
index: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
as: {
|
||||
type: String,
|
||||
default: "div",
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const context = inject(inputOTPContextKey, null);
|
||||
const focused = ref(false);
|
||||
|
||||
const char = computed(() => context?.chars.value[props.index] ?? "");
|
||||
const isDisabled = computed(() => Boolean(context?.isDisabled.value));
|
||||
const isInvalid = computed(() => Boolean(context?.isInvalid.value));
|
||||
const isReadOnly = computed(() => Boolean(context?.isReadOnly.value));
|
||||
const isFilled = computed(() => char.value.length > 0);
|
||||
const isActive = computed(() => focused.value && !isDisabled.value);
|
||||
const mask = computed(() => Boolean(context?.mask.value));
|
||||
const displayChar = computed(() => (mask.value ? "•" : char.value));
|
||||
|
||||
function onInputFocus() {
|
||||
focused.value = true;
|
||||
}
|
||||
function onInputBlur() {
|
||||
focused.value = false;
|
||||
}
|
||||
|
||||
/** Block edit keys before Reka handlers when readonly/disabled. */
|
||||
function guardEdit(event: Event) {
|
||||
if (!isReadOnly.value && !isDisabled.value) return;
|
||||
const key = (event as KeyboardEvent).key;
|
||||
if (
|
||||
key === "Tab" ||
|
||||
key === "Escape" ||
|
||||
key === "ArrowLeft" ||
|
||||
key === "ArrowRight" ||
|
||||
key === "ArrowUp" ||
|
||||
key === "ArrowDown" ||
|
||||
key === "Home" ||
|
||||
key === "End"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
function guardPaste(event: Event) {
|
||||
if (!isReadOnly.value && !isDisabled.value) return;
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
/** After user handlers: preventDefault means cancel the edit. */
|
||||
function stopIfPrevented(event: Event) {
|
||||
if (event.defaultPrevented) event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
function render() {
|
||||
const slotClass = context?.slots.value.slot();
|
||||
const valueClass = context?.slots.value.slotValue();
|
||||
const caretClass = context?.slots.value.caret();
|
||||
const inputClass = [
|
||||
context?.slots.value.input(),
|
||||
context?.inputClassName.value,
|
||||
];
|
||||
|
||||
const {
|
||||
class: cls,
|
||||
onKeydown: userKeydown,
|
||||
onKeydownCapture: userKeydownCapture,
|
||||
onPaste: userPaste,
|
||||
onPasteCapture: userPasteCapture,
|
||||
...rest
|
||||
} = attrs as Record<string, unknown>;
|
||||
|
||||
// Vue native handler arrays honor stopImmediatePropagation between
|
||||
// items. Bubble-phase keydown/paste are promoted into the capture
|
||||
// list so user preventDefault can cancel Reka's edit handlers.
|
||||
const keydownCapture: Handler[] = [
|
||||
guardEdit,
|
||||
...toHandlerArray(userKeydownCapture),
|
||||
...toHandlerArray(userKeydown),
|
||||
stopIfPrevented,
|
||||
];
|
||||
const pasteCapture: Handler[] = [
|
||||
guardPaste,
|
||||
...toHandlerArray(userPasteCapture),
|
||||
...toHandlerArray(userPaste),
|
||||
stopIfPrevented,
|
||||
];
|
||||
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...rest,
|
||||
class: [slotClass, cls],
|
||||
onKeydownCapture: keydownCapture,
|
||||
onPasteCapture: pasteCapture,
|
||||
"data-active": isActive.value || undefined,
|
||||
"data-disabled": isDisabled.value || undefined,
|
||||
"data-filled": isFilled.value || undefined,
|
||||
"data-invalid": isInvalid.value || undefined,
|
||||
"data-readonly": isReadOnly.value || undefined,
|
||||
"data-slot": "input-otp-slot",
|
||||
},
|
||||
[
|
||||
isFilled.value
|
||||
? h(
|
||||
"div",
|
||||
{
|
||||
class: valueClass,
|
||||
"data-slot": "input-otp-slot-value",
|
||||
},
|
||||
displayChar.value,
|
||||
)
|
||||
: null,
|
||||
isActive.value
|
||||
? h("div", {
|
||||
class: caretClass,
|
||||
"data-slot": "input-otp-caret",
|
||||
})
|
||||
: null,
|
||||
h(
|
||||
PinInputInput,
|
||||
{
|
||||
asChild: true,
|
||||
index: props.index,
|
||||
disabled: isDisabled.value,
|
||||
readonly: isReadOnly.value || undefined,
|
||||
class: inputClass,
|
||||
id: context?.inputId(props.index),
|
||||
"data-slot": "input-otp-input",
|
||||
autocomplete: "one-time-code",
|
||||
"aria-describedby": context?.describedBy.value,
|
||||
"aria-invalid": isInvalid.value ? "true" : undefined,
|
||||
onFocus: onInputFocus,
|
||||
onBlur: onInputBlur,
|
||||
},
|
||||
{
|
||||
// Own the native ARIA so the primitive's default label cannot
|
||||
// override the composed field name. Retain its input handlers.
|
||||
default: () =>
|
||||
h("input", {
|
||||
"aria-labelledby":
|
||||
attrs["aria-labelledby"] ??
|
||||
(attrs["aria-label"]
|
||||
? undefined
|
||||
: context?.labelledBy.value),
|
||||
"aria-label":
|
||||
attrs["aria-label"] ??
|
||||
context?.accessibleLabel.value ??
|
||||
(context?.labelledBy.value
|
||||
? undefined
|
||||
: `pin input ${props.index + 1} of ${context?.maxLength.value ?? 0}`),
|
||||
}),
|
||||
},
|
||||
),
|
||||
slots.default?.(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { ComputedRef, InjectionKey } from "vue";
|
||||
import type { inputOTPVariants } from "@heroui-vue/styles";
|
||||
|
||||
export type InputOTPSlots = ReturnType<typeof inputOTPVariants>;
|
||||
|
||||
export interface InputOTPContextValue {
|
||||
slots: ComputedRef<InputOTPSlots>;
|
||||
isDisabled: ComputedRef<boolean>;
|
||||
isInvalid: ComputedRef<boolean>;
|
||||
isReadOnly: ComputedRef<boolean>;
|
||||
maxLength: ComputedRef<number>;
|
||||
pattern: ComputedRef<RegExp | null>;
|
||||
/** Index-preserving character array; empty string means an empty slot. */
|
||||
chars: ComputedRef<string[]>;
|
||||
mask: ComputedRef<boolean>;
|
||||
inputClassName: ComputedRef<string | undefined>;
|
||||
describedBy: ComputedRef<string | undefined>;
|
||||
labelledBy: ComputedRef<string | undefined>;
|
||||
accessibleLabel: ComputedRef<string | undefined>;
|
||||
/** Stable DOM id for the real focusable input at `index`. */
|
||||
inputId: (index: number) => string;
|
||||
}
|
||||
|
||||
export const inputOTPContextKey: InjectionKey<InputOTPContextValue> = Symbol(
|
||||
"heroui-vue.input-otp",
|
||||
);
|
||||
|
||||
/**
|
||||
* Public model is a string. Slot `i` maps to `value[i]`.
|
||||
* Empty slots stay at their indices in the internal array so the UI
|
||||
* never left-shifts later characters. Serialization joins characters
|
||||
* in index order (`arr.join("")`) — slot display always reads the array.
|
||||
*/
|
||||
export function charsFromString(value: string, length: number): string[] {
|
||||
return Array.from({ length }, (_, i) => value[i] ?? "");
|
||||
}
|
||||
|
||||
export function stringFromChars(chars: string[]): string {
|
||||
return chars.join("");
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<script lang="ts">
|
||||
/** Baseline IconChevronLeft from HeroUI icons.tsx (Apache-2.0). */
|
||||
export default {
|
||||
name: "PaginationChevronLeftIcon",
|
||||
};
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineOptions({ inheritAttrs: false });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
fill="none"
|
||||
height="16"
|
||||
role="presentation"
|
||||
viewBox="0 0 16 16"
|
||||
width="16"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
v-bind="$attrs"
|
||||
>
|
||||
<path
|
||||
clip-rule="evenodd"
|
||||
d="M10.53 2.97a.75.75 0 0 1 0 1.06L6.56 8l3.97 3.97a.75.75 0 1 1-1.06 1.06l-4.5-4.5a.75.75 0 0 1 0-1.06l4.5-4.5a.75.75 0 0 1 1.06 0"
|
||||
fill="currentColor"
|
||||
fill-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
@@ -0,0 +1,30 @@
|
||||
<script lang="ts">
|
||||
/** Baseline IconChevronRight from HeroUI icons.tsx (Apache-2.0). */
|
||||
export default {
|
||||
name: "PaginationChevronRightIcon",
|
||||
};
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineOptions({ inheritAttrs: false });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
fill="none"
|
||||
height="16"
|
||||
role="presentation"
|
||||
viewBox="0 0 16 16"
|
||||
width="16"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
v-bind="$attrs"
|
||||
>
|
||||
<path
|
||||
clip-rule="evenodd"
|
||||
d="M5.47 2.97a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 0 1-1.06-1.06L9.44 8 5.47 4.03a.75.75 0 0 1 0-1.06Z"
|
||||
fill="currentColor"
|
||||
fill-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</template>
|
||||
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, useAttrs } from "vue";
|
||||
import { paginationContextKey } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "PaginationContent",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
/** Render the content list as a custom element instead of `ul`. */
|
||||
as: {
|
||||
type: String,
|
||||
default: "ul",
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const context = inject(paginationContextKey, null);
|
||||
|
||||
function render() {
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
class: [context?.slots.value.content(), attrs.class],
|
||||
"data-slot": "pagination-content",
|
||||
},
|
||||
slots.default?.(),
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, useAttrs } from "vue";
|
||||
import { paginationContextKey } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "PaginationEllipsis",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
/** Render the ellipsis as a custom element instead of `span`. */
|
||||
as: {
|
||||
type: String,
|
||||
default: "span",
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const attrs = useAttrs();
|
||||
const context = inject(paginationContextKey, null);
|
||||
|
||||
function render() {
|
||||
// Upstream always renders … and does not take custom children.
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
class: [context?.slots.value.ellipsis(), attrs.class],
|
||||
"aria-hidden": "true",
|
||||
"data-slot": "pagination-ellipsis",
|
||||
},
|
||||
["…"],
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, useAttrs } from "vue";
|
||||
import { paginationContextKey } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "PaginationItem",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
/** Render the item as a custom element instead of `li`. */
|
||||
as: {
|
||||
type: String,
|
||||
default: "li",
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const context = inject(paginationContextKey, null);
|
||||
|
||||
function render() {
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
class: [context?.slots.value.item(), attrs.class],
|
||||
"data-slot": "pagination-item",
|
||||
},
|
||||
slots.default?.(),
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,79 @@
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, h, inject, useAttrs } from "vue";
|
||||
import { Primitive } from "reka-ui";
|
||||
import type { ButtonHTMLAttributes, PropType } from "vue";
|
||||
import { paginationContextKey } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "PaginationLink",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
/** Whether this link is the current page. */
|
||||
isActive: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
isDisabled: {
|
||||
type: Boolean,
|
||||
default: undefined,
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: undefined,
|
||||
},
|
||||
type: {
|
||||
type: String as PropType<ButtonHTMLAttributes["type"]>,
|
||||
default: "button",
|
||||
},
|
||||
asChild: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const context = inject(paginationContextKey, null);
|
||||
const disabled = computed(
|
||||
() => props.isDisabled ?? props.disabled ?? undefined,
|
||||
);
|
||||
|
||||
function render() {
|
||||
const {
|
||||
class: cls,
|
||||
"aria-current": explicitCurrent,
|
||||
"data-active": explicitActive,
|
||||
...rest
|
||||
} = attrs as Record<string, unknown>;
|
||||
const bind: Record<string, unknown> = { ...rest };
|
||||
if (disabled.value !== undefined) bind.disabled = disabled.value;
|
||||
return h(
|
||||
Primitive,
|
||||
{
|
||||
as: "button",
|
||||
asChild: props.asChild,
|
||||
type: props.asChild ? undefined : props.type,
|
||||
...bind,
|
||||
class: [context?.slots.value.link(), cls],
|
||||
// Explicit caller attributes win over isActive defaults.
|
||||
"aria-current":
|
||||
explicitCurrent !== undefined
|
||||
? explicitCurrent
|
||||
: props.isActive
|
||||
? "page"
|
||||
: undefined,
|
||||
"data-active":
|
||||
explicitActive !== undefined
|
||||
? explicitActive
|
||||
: props.isActive
|
||||
? "true"
|
||||
: undefined,
|
||||
"data-slot": "pagination-link",
|
||||
},
|
||||
slots,
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,60 @@
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, h, inject, useAttrs } from "vue";
|
||||
import { Primitive } from "reka-ui";
|
||||
import type { ButtonHTMLAttributes, PropType } from "vue";
|
||||
import { paginationContextKey } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "PaginationNext",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
isDisabled: {
|
||||
type: Boolean,
|
||||
default: undefined,
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: undefined,
|
||||
},
|
||||
type: {
|
||||
type: String as PropType<ButtonHTMLAttributes["type"]>,
|
||||
default: "button",
|
||||
},
|
||||
asChild: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const context = inject(paginationContextKey, null);
|
||||
const disabled = computed(
|
||||
() => props.isDisabled ?? props.disabled ?? undefined,
|
||||
);
|
||||
const linkClass = computed(() =>
|
||||
[context?.slots.value.link(), "hv-pagination__link--nav"]
|
||||
.filter(Boolean)
|
||||
.join(" "),
|
||||
);
|
||||
|
||||
function render() {
|
||||
const bind: Record<string, unknown> = { ...attrs };
|
||||
if (disabled.value !== undefined) bind.disabled = disabled.value;
|
||||
return h(
|
||||
Primitive,
|
||||
{
|
||||
as: "button",
|
||||
asChild: props.asChild,
|
||||
type: props.asChild ? undefined : props.type,
|
||||
...bind,
|
||||
class: [linkClass.value, attrs.class],
|
||||
"data-slot": "pagination-next",
|
||||
},
|
||||
slots,
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, useAttrs, type VNodeChild } from "vue";
|
||||
import PaginationChevronRightIcon from "./PaginationChevronRightIcon.vue";
|
||||
|
||||
function hasContent(nodes: VNodeChild[] | undefined): boolean {
|
||||
if (!nodes || nodes.length === 0) return false;
|
||||
return nodes.some((node) => {
|
||||
if (node == null || node === false || node === true) return false;
|
||||
if (typeof node === "string") return node.trim() !== "";
|
||||
if (typeof node === "number") return true;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "PaginationNextIcon",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
/** Render the icon wrapper as a custom element instead of `span`. */
|
||||
as: {
|
||||
type: String,
|
||||
default: "span",
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
|
||||
function render() {
|
||||
const content = slots.default?.() as VNodeChild[] | undefined;
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
class: attrs.class,
|
||||
"aria-hidden": "true",
|
||||
"data-slot": "pagination-next-icon",
|
||||
},
|
||||
hasContent(content) ? content : [h(PaginationChevronRightIcon)],
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,60 @@
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent, h, inject, useAttrs } from "vue";
|
||||
import { Primitive } from "reka-ui";
|
||||
import type { ButtonHTMLAttributes, PropType } from "vue";
|
||||
import { paginationContextKey } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "PaginationPrevious",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
isDisabled: {
|
||||
type: Boolean,
|
||||
default: undefined,
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: undefined,
|
||||
},
|
||||
type: {
|
||||
type: String as PropType<ButtonHTMLAttributes["type"]>,
|
||||
default: "button",
|
||||
},
|
||||
asChild: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const context = inject(paginationContextKey, null);
|
||||
const disabled = computed(
|
||||
() => props.isDisabled ?? props.disabled ?? undefined,
|
||||
);
|
||||
const linkClass = computed(() =>
|
||||
[context?.slots.value.link(), "hv-pagination__link--nav"]
|
||||
.filter(Boolean)
|
||||
.join(" "),
|
||||
);
|
||||
|
||||
function render() {
|
||||
const bind: Record<string, unknown> = { ...attrs };
|
||||
if (disabled.value !== undefined) bind.disabled = disabled.value;
|
||||
return h(
|
||||
Primitive,
|
||||
{
|
||||
as: "button",
|
||||
asChild: props.asChild,
|
||||
type: props.asChild ? undefined : props.type,
|
||||
...bind,
|
||||
class: [linkClass.value, attrs.class],
|
||||
"data-slot": "pagination-previous",
|
||||
},
|
||||
slots,
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, useAttrs, type VNodeChild } from "vue";
|
||||
import PaginationChevronLeftIcon from "./PaginationChevronLeftIcon.vue";
|
||||
|
||||
function hasContent(nodes: VNodeChild[] | undefined): boolean {
|
||||
if (!nodes || nodes.length === 0) return false;
|
||||
return nodes.some((node) => {
|
||||
if (node == null || node === false || node === true) return false;
|
||||
if (typeof node === "string") return node.trim() !== "";
|
||||
if (typeof node === "number") return true;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "PaginationPreviousIcon",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
/** Render the icon wrapper as a custom element instead of `span`. */
|
||||
as: {
|
||||
type: String,
|
||||
default: "span",
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
|
||||
function render() {
|
||||
const content = slots.default?.() as VNodeChild[] | undefined;
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
class: attrs.class,
|
||||
"aria-hidden": "true",
|
||||
"data-slot": "pagination-previous-icon",
|
||||
},
|
||||
hasContent(content) ? content : [h(PaginationChevronLeftIcon)],
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
h,
|
||||
provide,
|
||||
useAttrs,
|
||||
type PropType,
|
||||
} from "vue";
|
||||
import {
|
||||
paginationVariants,
|
||||
type PaginationVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
import { paginationContextKey } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "PaginationRoot",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
/** Pagination size. */
|
||||
size: {
|
||||
type: String as PropType<PaginationVariants["size"]>,
|
||||
default: "md",
|
||||
},
|
||||
/** Render the root as a custom element instead of `nav`. */
|
||||
as: {
|
||||
type: String,
|
||||
default: "nav",
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const variantSlots = computed(() =>
|
||||
paginationVariants({ size: props.size }),
|
||||
);
|
||||
provide(paginationContextKey, { slots: variantSlots });
|
||||
|
||||
function render() {
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...attrs,
|
||||
class: [variantSlots.value.base(), attrs.class],
|
||||
"aria-label": attrs["aria-label"] ?? "pagination",
|
||||
role: attrs.role ?? "navigation",
|
||||
"data-slot": "pagination",
|
||||
},
|
||||
slots.default?.(),
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { defineComponent, h, inject, useAttrs } from "vue";
|
||||
import { paginationContextKey } from "./context";
|
||||
|
||||
export default defineComponent({
|
||||
name: "PaginationSummary",
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
/** Render the summary as a custom element instead of `div`. */
|
||||
as: {
|
||||
type: String,
|
||||
default: "div",
|
||||
},
|
||||
},
|
||||
setup(props, { slots }) {
|
||||
const attrs = useAttrs();
|
||||
const context = inject(paginationContextKey, null);
|
||||
|
||||
function render() {
|
||||
const { class: cls, dir, ...rest } = attrs as Record<string, unknown>;
|
||||
return h(
|
||||
props.as,
|
||||
{
|
||||
...rest,
|
||||
// Auto-detect base direction from the summary's own text so mixed
|
||||
// number/word content is not bidi-reordered by an RTL ancestor.
|
||||
// Explicit `dir` still overrides.
|
||||
dir: dir === undefined ? "auto" : dir,
|
||||
class: [context?.slots.value.summary(), cls],
|
||||
"data-slot": "pagination-summary",
|
||||
},
|
||||
slots.default?.(),
|
||||
);
|
||||
}
|
||||
|
||||
return render;
|
||||
},
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { InjectionKey, ComputedRef } from "vue";
|
||||
import type { paginationVariants } from "@heroui-vue/styles";
|
||||
|
||||
export type PaginationSlots = ReturnType<typeof paginationVariants>;
|
||||
|
||||
export type PaginationContextValue = {
|
||||
slots: ComputedRef<PaginationSlots>;
|
||||
};
|
||||
|
||||
export const paginationContextKey: InjectionKey<PaginationContextValue> =
|
||||
Symbol("heroui-vue.pagination");
|
||||
@@ -536,3 +536,56 @@ export type {
|
||||
} from "./components/toolbar/context";
|
||||
export { toolbarVariants, type ToolbarVariants } from "@heroui-vue/styles";
|
||||
export type { ToolbarProps } from "./types";
|
||||
|
||||
export { default as PaginationRoot } from "./components/pagination/PaginationRoot.vue";
|
||||
export { default as Pagination } from "./components/pagination/PaginationRoot.vue";
|
||||
export { default as PaginationSummary } from "./components/pagination/PaginationSummary.vue";
|
||||
export { default as PaginationContent } from "./components/pagination/PaginationContent.vue";
|
||||
export { default as PaginationItem } from "./components/pagination/PaginationItem.vue";
|
||||
export { default as PaginationLink } from "./components/pagination/PaginationLink.vue";
|
||||
export { default as PaginationPrevious } from "./components/pagination/PaginationPrevious.vue";
|
||||
export { default as PaginationPreviousIcon } from "./components/pagination/PaginationPreviousIcon.vue";
|
||||
export { default as PaginationNext } from "./components/pagination/PaginationNext.vue";
|
||||
export { default as PaginationNextIcon } from "./components/pagination/PaginationNextIcon.vue";
|
||||
export { default as PaginationEllipsis } from "./components/pagination/PaginationEllipsis.vue";
|
||||
export {
|
||||
paginationVariants,
|
||||
type PaginationVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type {
|
||||
PaginationRootProps,
|
||||
PaginationProps,
|
||||
PaginationSummaryProps,
|
||||
PaginationContentProps,
|
||||
PaginationItemProps,
|
||||
PaginationLinkProps,
|
||||
PaginationPreviousProps,
|
||||
PaginationPreviousIconProps,
|
||||
PaginationNextProps,
|
||||
PaginationNextIconProps,
|
||||
PaginationEllipsisProps,
|
||||
} from "./types";
|
||||
|
||||
export { default as HeaderRoot } from "./components/header/HeaderRoot.vue";
|
||||
export { default as Header } from "./components/header/HeaderRoot.vue";
|
||||
export { headerVariants, type HeaderVariants } from "@heroui-vue/styles";
|
||||
export type { HeaderRootProps, HeaderProps } from "./types";
|
||||
|
||||
export { default as InputOTPRoot } from "./components/input-otp/InputOTPRoot.vue";
|
||||
export { default as InputOTP } from "./components/input-otp/InputOTPRoot.vue";
|
||||
export { default as InputOTPGroup } from "./components/input-otp/InputOTPGroup.vue";
|
||||
export { default as InputOTPSlot } from "./components/input-otp/InputOTPSlot.vue";
|
||||
export { default as InputOTPSeparator } from "./components/input-otp/InputOTPSeparator.vue";
|
||||
export { inputOTPVariants, type InputOTPVariants } from "@heroui-vue/styles";
|
||||
export type {
|
||||
InputOTPRootProps,
|
||||
InputOTPProps,
|
||||
InputOTPGroupProps,
|
||||
InputOTPSlotProps,
|
||||
InputOTPSeparatorProps,
|
||||
} from "./types";
|
||||
|
||||
/** Regular expressions matching upstream input-otp constants. */
|
||||
export const REGEXP_ONLY_DIGITS = "^\\d+$";
|
||||
export const REGEXP_ONLY_CHARS = "^[a-zA-Z]+$";
|
||||
export const REGEXP_ONLY_DIGITS_AND_CHARS = "^[a-zA-Z0-9]+$";
|
||||
|
||||
@@ -395,3 +395,55 @@ export type ToggleButtonGroupSeparatorProps = InstanceType<
|
||||
|
||||
import type Toolbar from "./components/toolbar/Toolbar.vue";
|
||||
export type ToolbarProps = InstanceType<typeof Toolbar>["$props"];
|
||||
|
||||
import type PaginationRoot from "./components/pagination/PaginationRoot.vue";
|
||||
import type PaginationSummary from "./components/pagination/PaginationSummary.vue";
|
||||
import type PaginationContent from "./components/pagination/PaginationContent.vue";
|
||||
import type PaginationItem from "./components/pagination/PaginationItem.vue";
|
||||
import type PaginationLink from "./components/pagination/PaginationLink.vue";
|
||||
import type PaginationPrevious from "./components/pagination/PaginationPrevious.vue";
|
||||
import type PaginationPreviousIcon from "./components/pagination/PaginationPreviousIcon.vue";
|
||||
import type PaginationNext from "./components/pagination/PaginationNext.vue";
|
||||
import type PaginationNextIcon from "./components/pagination/PaginationNextIcon.vue";
|
||||
import type PaginationEllipsis from "./components/pagination/PaginationEllipsis.vue";
|
||||
|
||||
export type PaginationRootProps = InstanceType<typeof PaginationRoot>["$props"];
|
||||
export type PaginationProps = PaginationRootProps;
|
||||
export type PaginationSummaryProps = InstanceType<
|
||||
typeof PaginationSummary
|
||||
>["$props"];
|
||||
export type PaginationContentProps = InstanceType<
|
||||
typeof PaginationContent
|
||||
>["$props"];
|
||||
export type PaginationItemProps = InstanceType<typeof PaginationItem>["$props"];
|
||||
export type PaginationLinkProps = InstanceType<typeof PaginationLink>["$props"];
|
||||
export type PaginationPreviousProps = InstanceType<
|
||||
typeof PaginationPrevious
|
||||
>["$props"];
|
||||
export type PaginationPreviousIconProps = InstanceType<
|
||||
typeof PaginationPreviousIcon
|
||||
>["$props"];
|
||||
export type PaginationNextProps = InstanceType<typeof PaginationNext>["$props"];
|
||||
export type PaginationNextIconProps = InstanceType<
|
||||
typeof PaginationNextIcon
|
||||
>["$props"];
|
||||
export type PaginationEllipsisProps = InstanceType<
|
||||
typeof PaginationEllipsis
|
||||
>["$props"];
|
||||
|
||||
import type HeaderRoot from "./components/header/HeaderRoot.vue";
|
||||
export type HeaderRootProps = InstanceType<typeof HeaderRoot>["$props"];
|
||||
export type HeaderProps = HeaderRootProps;
|
||||
|
||||
import type InputOTPRoot from "./components/input-otp/InputOTPRoot.vue";
|
||||
import type InputOTPGroup from "./components/input-otp/InputOTPGroup.vue";
|
||||
import type InputOTPSlot from "./components/input-otp/InputOTPSlot.vue";
|
||||
import type InputOTPSeparator from "./components/input-otp/InputOTPSeparator.vue";
|
||||
|
||||
export type InputOTPRootProps = InstanceType<typeof InputOTPRoot>["$props"];
|
||||
export type InputOTPProps = InputOTPRootProps;
|
||||
export type InputOTPGroupProps = InstanceType<typeof InputOTPGroup>["$props"];
|
||||
export type InputOTPSlotProps = InstanceType<typeof InputOTPSlot>["$props"];
|
||||
export type InputOTPSeparatorProps = InstanceType<
|
||||
typeof InputOTPSeparator
|
||||
>["$props"];
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { createSSRApp, defineComponent, h, nextTick, ref } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import { Header, HeaderRoot } from "../packages/vue/src";
|
||||
|
||||
import HeaderBasicDemo from "../apps/docs/demos/header-basic.vue";
|
||||
import HeaderCustomClassDemo from "../apps/docs/demos/header-custom-class.vue";
|
||||
import HeaderSemanticDemo from "../apps/docs/demos/header-semantic.vue";
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
describe("Header basics", () => {
|
||||
it("renders a native header with baseline class and data-slot", () => {
|
||||
const w = mount(Header, {
|
||||
props: {},
|
||||
slots: { default: "操作" },
|
||||
attachTo: document.body,
|
||||
});
|
||||
const root = w.get('[data-slot="header"]');
|
||||
expect(root.element.tagName).toBe("HEADER");
|
||||
expect(root.classes().join(" ")).toContain("hv-header");
|
||||
expect(root.text()).toBe("操作");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("exports Header as HeaderRoot alias", () => {
|
||||
expect(Header).toBe(HeaderRoot);
|
||||
});
|
||||
|
||||
it("supports as override without inventing heading levels", () => {
|
||||
const w = mount(Header, {
|
||||
props: { as: "div" },
|
||||
slots: { default: "分组" },
|
||||
attachTo: document.body,
|
||||
});
|
||||
const root = w.get('[data-slot="header"]');
|
||||
expect(root.element.tagName).toBe("DIV");
|
||||
expect(root.attributes("role")).toBeUndefined();
|
||||
expect(root.attributes("aria-level")).toBeUndefined();
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("merges class and attrs, including dynamic add/update/delete/re-add", async () => {
|
||||
const extra = ref<Record<string, unknown>>({});
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Header },
|
||||
setup: () => ({ extra }),
|
||||
template: `<Header v-bind="extra" class="base-header">分组</Header>`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
let root = w.get('[data-slot="header"]');
|
||||
expect(root.classes()).toContain("hv-header");
|
||||
expect(root.classes()).toContain("base-header");
|
||||
|
||||
extra.value = {
|
||||
"data-testid": "h1",
|
||||
"aria-label": "分组标题",
|
||||
id: "group-title",
|
||||
};
|
||||
await nextTick();
|
||||
root = w.get('[data-slot="header"]');
|
||||
expect(root.attributes("data-testid")).toBe("h1");
|
||||
expect(root.attributes("aria-label")).toBe("分组标题");
|
||||
expect(root.attributes("id")).toBe("group-title");
|
||||
|
||||
extra.value = { "data-testid": "h2", title: "updated" };
|
||||
await nextTick();
|
||||
root = w.get('[data-slot="header"]');
|
||||
expect(root.attributes("data-testid")).toBe("h2");
|
||||
expect(root.attributes("title")).toBe("updated");
|
||||
expect(root.attributes("aria-label")).toBeUndefined();
|
||||
expect(root.attributes("id")).toBeUndefined();
|
||||
|
||||
extra.value = {};
|
||||
await nextTick();
|
||||
root = w.get("[data-slot=header]");
|
||||
expect(root.attributes("data-testid")).toBeUndefined();
|
||||
expect(root.attributes("title")).toBeUndefined();
|
||||
|
||||
extra.value = { style: { color: "red" } };
|
||||
await nextTick();
|
||||
root = w.get("[data-slot=header]");
|
||||
expect(root.attributes("style")).toContain("color: red");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("updates default slot content and keeps multiple instances independent", async () => {
|
||||
const label = ref("A 组");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { Header },
|
||||
setup: () => ({ label }),
|
||||
template: `
|
||||
<div>
|
||||
<Header data-testid="one">{{ label }}</Header>
|
||||
<Header data-testid="two">B 组</Header>
|
||||
</div>
|
||||
`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
expect(w.get('[data-testid="one"]').text()).toBe("A 组");
|
||||
expect(w.get('[data-testid="two"]').text()).toBe("B 组");
|
||||
|
||||
label.value = "A 组已更新";
|
||||
await nextTick();
|
||||
expect(w.get('[data-testid="one"]').text()).toBe("A 组已更新");
|
||||
expect(w.get('[data-testid="two"]').text()).toBe("B 组");
|
||||
w.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Header demos", () => {
|
||||
it("mounts all self-authored demos without Vue warnings", async () => {
|
||||
const warnings: string[] = [];
|
||||
const spy = vi.spyOn(console, "warn").mockImplementation((...args) => {
|
||||
warnings.push(args.map(String).join(" "));
|
||||
});
|
||||
for (const demo of [
|
||||
HeaderBasicDemo,
|
||||
HeaderCustomClassDemo,
|
||||
HeaderSemanticDemo,
|
||||
]) {
|
||||
const w = mount(demo, { attachTo: document.body });
|
||||
await nextTick();
|
||||
expect(w.html().length).toBeGreaterThan(0);
|
||||
expect(w.find('[data-slot="header"]').exists()).toBe(true);
|
||||
w.unmount();
|
||||
}
|
||||
spy.mockRestore();
|
||||
expect(warnings).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Header types", () => {
|
||||
it("exposes HeaderProps alias", () => {
|
||||
const ok: InstanceType<typeof HeaderRoot>["$props"] = { as: "header" };
|
||||
expect(ok.as).toBe("header");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Header SSR", () => {
|
||||
it("renders without touching browser globals", async () => {
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () => h(Header, () => "操作"),
|
||||
}),
|
||||
);
|
||||
expect(html).toContain("<header");
|
||||
expect(html).toContain('data-slot="header"');
|
||||
expect(html).toContain("hv-header");
|
||||
expect(html).toContain("操作");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
// @vitest-environment node
|
||||
import { expect, it } from "vitest";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
} from "../packages/vue/src";
|
||||
it("renders composed OTP names on the real native inputs without browser globals", async () => {
|
||||
expect(typeof window).toBe("undefined");
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(InputOTP, { maxLength: 2, defaultValue: "12" }, () => [
|
||||
h(Label, { id: "otp-server-label" }, () => "Security code"),
|
||||
h(InputOTPGroup, {}, () => [
|
||||
h(InputOTPSlot, { index: 0 }),
|
||||
h(InputOTPSlot, { index: 1 }),
|
||||
]),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
expect(html.match(/aria-labelledby="otp-server-label"/g)).toHaveLength(2);
|
||||
expect(html).toContain('value="1"');
|
||||
expect(html).toContain('value="2"');
|
||||
expect(html).not.toMatch(/aria-label="pin input/);
|
||||
});
|
||||
@@ -0,0 +1,563 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { createSSRApp, defineComponent, h, nextTick, ref } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPRoot,
|
||||
InputOTPSeparator,
|
||||
InputOTPSlot,
|
||||
REGEXP_ONLY_CHARS,
|
||||
REGEXP_ONLY_DIGITS,
|
||||
REGEXP_ONLY_DIGITS_AND_CHARS,
|
||||
} from "../packages/vue/src";
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
function mountOtp(
|
||||
opts: {
|
||||
maxLength?: number;
|
||||
modelValue?: string;
|
||||
defaultValue?: string;
|
||||
pattern?: string | RegExp;
|
||||
isDisabled?: boolean;
|
||||
isInvalid?: boolean;
|
||||
validationErrors?: string[];
|
||||
name?: string;
|
||||
required?: boolean;
|
||||
variant?: "primary" | "secondary";
|
||||
inputClassName?: string;
|
||||
otp?: boolean;
|
||||
onComplete?: (v: string) => void;
|
||||
} = {},
|
||||
) {
|
||||
const value = ref(opts.modelValue ?? opts.defaultValue ?? "");
|
||||
const controlled = opts.modelValue !== undefined;
|
||||
const updates: string[] = [];
|
||||
const completes: string[] = [];
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => ({ value }),
|
||||
render: () =>
|
||||
h(
|
||||
InputOTP,
|
||||
{
|
||||
maxLength: opts.maxLength ?? 6,
|
||||
modelValue: controlled ? value.value : undefined,
|
||||
defaultValue: opts.defaultValue,
|
||||
pattern: opts.pattern,
|
||||
isDisabled: opts.isDisabled,
|
||||
isInvalid: opts.isInvalid,
|
||||
validationErrors: opts.validationErrors,
|
||||
name: opts.name,
|
||||
required: opts.required,
|
||||
variant: opts.variant,
|
||||
inputClassName: opts.inputClassName,
|
||||
otp: opts.otp,
|
||||
"onUpdate:modelValue": (v: string) => {
|
||||
value.value = v;
|
||||
updates.push(v);
|
||||
},
|
||||
onComplete: (v: string) => {
|
||||
completes.push(v);
|
||||
opts.onComplete?.(v);
|
||||
},
|
||||
},
|
||||
() => [
|
||||
h(InputOTPGroup, () =>
|
||||
Array.from({ length: opts.maxLength ?? 6 }, (_, i) =>
|
||||
h(InputOTPSlot, { index: i }),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
return { w, value, updates, completes, controlled };
|
||||
}
|
||||
|
||||
function slotInputs(w: ReturnType<typeof mount>) {
|
||||
return w.findAll("input[data-slot=input-otp-input]");
|
||||
}
|
||||
|
||||
describe("InputOTP structure", () => {
|
||||
it("exports InputOTP as Root alias and renders slots/groups", () => {
|
||||
expect(InputOTP).toBe(InputOTPRoot);
|
||||
const { w } = mountOtp({ maxLength: 4, variant: "secondary" });
|
||||
const root = w.get('[data-slot="input-otp"]');
|
||||
expect(root.classes().join(" ")).toContain("hv-input-otp");
|
||||
expect(root.classes().join(" ")).toContain("hv-input-otp--secondary");
|
||||
expect(w.findAll('[data-slot="input-otp-slot"]')).toHaveLength(4);
|
||||
expect(slotInputs(w)).toHaveLength(4);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("renders separator and applies inputClassName to real inputs only", () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(InputOTP, { maxLength: 2, inputClassName: "custom-input" }, () => [
|
||||
h(InputOTPGroup, () => h(InputOTPSlot, { index: 0 })),
|
||||
h(InputOTPSeparator, { class: "custom-sep" }),
|
||||
h(InputOTPGroup, () => h(InputOTPSlot, { index: 1 })),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
expect(w.get('[data-slot="input-otp-separator"]').classes()).toContain(
|
||||
"custom-sep",
|
||||
);
|
||||
for (const input of slotInputs(w)) {
|
||||
expect(input.classes()).toContain("custom-input");
|
||||
}
|
||||
expect(w.get('[data-slot="input-otp"]').classes()).not.toContain(
|
||||
"custom-input",
|
||||
);
|
||||
w.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe("InputOTP value model", () => {
|
||||
it("supports uncontrolled defaultValue and typed updates as strings", async () => {
|
||||
const { w, value, updates } = mountOtp({ defaultValue: "12" });
|
||||
await nextTick();
|
||||
const slots = w.findAll('[data-slot="input-otp-slot"]');
|
||||
expect(slots[0].text()).toContain("1");
|
||||
expect(slots[1].text()).toContain("2");
|
||||
expect(slots[2].text()).not.toContain("3");
|
||||
|
||||
await slotInputs(w)[2].setValue("3");
|
||||
await nextTick();
|
||||
expect(value.value).toBe("123");
|
||||
expect(updates.at(-1)).toBe("123");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("controlled parent rejects update and restores actual input", async () => {
|
||||
const value = ref("12");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => ({ value }),
|
||||
render: () =>
|
||||
h(
|
||||
InputOTP,
|
||||
{
|
||||
maxLength: 4,
|
||||
modelValue: value.value,
|
||||
// Parent always keeps "12"
|
||||
"onUpdate:modelValue": () => {},
|
||||
},
|
||||
() =>
|
||||
h(InputOTPGroup, () =>
|
||||
[0, 1, 2, 3].map((i) => h(InputOTPSlot, { index: i })),
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
await nextTick();
|
||||
const list = slotInputs(w);
|
||||
await list[2].setValue("9");
|
||||
await nextTick();
|
||||
// Parent rejected; display should still be 12
|
||||
expect(value.value).toBe("12");
|
||||
const slots = w.findAll('[data-slot="input-otp-slot"]');
|
||||
expect(slots[0].text()).toContain("1");
|
||||
expect(slots[2].text()).not.toContain("9");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("keeps middle empty slot without left-shifting later characters", async () => {
|
||||
const { w } = mountOtp({ defaultValue: "123456" });
|
||||
await nextTick();
|
||||
await slotInputs(w)[1].setValue("");
|
||||
await nextTick();
|
||||
const slots = w.findAll('[data-slot="input-otp-slot"]');
|
||||
expect(slots[1].text()).not.toContain("2");
|
||||
expect(slots[2].text()).toContain("3");
|
||||
expect(slots[3].text()).toContain("4");
|
||||
expect(slots[5].text()).toContain("6");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("clears value and restores on retype", async () => {
|
||||
const { w, value } = mountOtp({ defaultValue: "12" });
|
||||
await nextTick();
|
||||
await slotInputs(w)[0].setValue("");
|
||||
await slotInputs(w)[1].setValue("");
|
||||
await nextTick();
|
||||
expect(value.value).toBe("");
|
||||
await slotInputs(w)[0].setValue("9");
|
||||
await nextTick();
|
||||
expect(value.value).toBe("9");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("emits complete on first fill and not on same-value rewrite", async () => {
|
||||
const completes: string[] = [];
|
||||
const { w, value } = mountOtp({
|
||||
maxLength: 3,
|
||||
onComplete: (v: string) => completes.push(v),
|
||||
});
|
||||
const list = slotInputs(w);
|
||||
await list[0].setValue("1");
|
||||
await list[1].setValue("2");
|
||||
await list[2].setValue("3");
|
||||
await nextTick();
|
||||
expect(completes.at(-1)).toBe("123");
|
||||
const count = completes.length;
|
||||
// Re-set same value should not grow complete
|
||||
await list[2].setValue("3");
|
||||
await nextTick();
|
||||
expect(completes.length).toBe(count);
|
||||
expect(value.value).toBe("123");
|
||||
w.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe("InputOTP pattern and states", () => {
|
||||
it("filters characters 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]+$");
|
||||
|
||||
const { w, value } = mountOtp({
|
||||
maxLength: 4,
|
||||
pattern: REGEXP_ONLY_DIGITS,
|
||||
});
|
||||
await slotInputs(w)[0].setValue("a");
|
||||
await nextTick();
|
||||
expect(value.value).toBe("");
|
||||
await slotInputs(w)[0].setValue("7");
|
||||
await nextTick();
|
||||
expect(value.value).toBe("7");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("marks disabled, invalid and filled data attributes", async () => {
|
||||
const { w } = mountOtp({
|
||||
defaultValue: "1",
|
||||
isDisabled: true,
|
||||
isInvalid: true,
|
||||
});
|
||||
await nextTick();
|
||||
expect(
|
||||
w.get('[data-slot="input-otp"]').attributes("data-disabled"),
|
||||
).toBeDefined();
|
||||
expect(
|
||||
w.get('[data-slot="input-otp"]').attributes("data-invalid"),
|
||||
).toBeDefined();
|
||||
const slots = w.findAll('[data-slot="input-otp-slot"]');
|
||||
expect(slots[0].attributes("data-filled")).toBeDefined();
|
||||
expect(slots[0].attributes("data-disabled")).toBeDefined();
|
||||
expect(slots[0].attributes("data-invalid")).toBeDefined();
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("shows validation errors via field context", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h("div", () => [
|
||||
h(
|
||||
InputOTP,
|
||||
{
|
||||
maxLength: 4,
|
||||
isInvalid: true,
|
||||
validationErrors: ["验证码无效"],
|
||||
name: "code",
|
||||
},
|
||||
() =>
|
||||
h(InputOTPGroup, () =>
|
||||
[0, 1, 2, 3].map((i) => h(InputOTPSlot, { index: i })),
|
||||
),
|
||||
),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
// FieldError is optional; invalid state on root is enough for this check
|
||||
expect(
|
||||
w.get('[data-slot="input-otp"]').attributes("data-invalid"),
|
||||
).toBeDefined();
|
||||
w.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe("InputOTP form and label", () => {
|
||||
it("submits a single form value and omits when disabled", async () => {
|
||||
const { w } = mountOtp({
|
||||
name: "code",
|
||||
defaultValue: "123456",
|
||||
});
|
||||
await nextTick();
|
||||
const form = document.createElement("form");
|
||||
form.appendChild(w.element);
|
||||
document.body.appendChild(form);
|
||||
const data = new FormData(form);
|
||||
expect(data.get("code")).toBe("123456");
|
||||
form.remove();
|
||||
|
||||
const d = mountOtp({
|
||||
name: "code",
|
||||
defaultValue: "12",
|
||||
isDisabled: true,
|
||||
});
|
||||
await nextTick();
|
||||
const form2 = document.createElement("form");
|
||||
form2.appendChild(d.w.element);
|
||||
document.body.appendChild(form2);
|
||||
const data2 = new FormData(form2);
|
||||
expect(data2.get("code")).toBeNull();
|
||||
form2.remove();
|
||||
d.w.unmount();
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("resets uncontrolled value to defaultValue and keeps controlled parent value", async () => {
|
||||
const uncontrolled = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h("form", null, [
|
||||
h(
|
||||
InputOTP,
|
||||
{ maxLength: 4, defaultValue: "12", name: "code" },
|
||||
() =>
|
||||
h(InputOTPGroup, () =>
|
||||
[0, 1, 2, 3].map((i) => h(InputOTPSlot, { index: i })),
|
||||
),
|
||||
),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const uInputs = slotInputs(uncontrolled);
|
||||
await uInputs[0].setValue("9");
|
||||
await nextTick();
|
||||
expect(new FormData(uncontrolled.get("form").element).get("code")).toBe(
|
||||
"92",
|
||||
);
|
||||
uncontrolled.get("form").element.reset();
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
expect(
|
||||
slotInputs(uncontrolled)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("12");
|
||||
expect(new FormData(uncontrolled.get("form").element).get("code")).toBe(
|
||||
"12",
|
||||
);
|
||||
|
||||
// Cancelable reset keeps the edited value.
|
||||
await slotInputs(uncontrolled)[0].setValue("9");
|
||||
await nextTick();
|
||||
const form = uncontrolled.get("form").element as HTMLFormElement;
|
||||
form.addEventListener(
|
||||
"reset",
|
||||
(event) => {
|
||||
event.preventDefault();
|
||||
},
|
||||
true,
|
||||
);
|
||||
form.reset();
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
expect(
|
||||
slotInputs(uncontrolled)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("92");
|
||||
uncontrolled.unmount();
|
||||
|
||||
const value = ref("34");
|
||||
const controlled = mount(
|
||||
defineComponent({
|
||||
setup: () => ({ value }),
|
||||
render: () =>
|
||||
h("form", null, [
|
||||
h(
|
||||
InputOTP,
|
||||
{
|
||||
maxLength: 4,
|
||||
modelValue: value.value,
|
||||
"onUpdate:modelValue": () => {
|
||||
/* parent rejects */
|
||||
},
|
||||
},
|
||||
() =>
|
||||
h(InputOTPGroup, () =>
|
||||
[0, 1, 2, 3].map((i) => h(InputOTPSlot, { index: i })),
|
||||
),
|
||||
),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
await nextTick();
|
||||
await slotInputs(controlled)[0].setValue("9");
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
expect(
|
||||
slotInputs(controlled)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("34");
|
||||
controlled.get("form").element.reset();
|
||||
await nextTick();
|
||||
expect(
|
||||
slotInputs(controlled)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("34");
|
||||
controlled.unmount();
|
||||
});
|
||||
|
||||
it("restores real inputs after a rejected controlled update and allows retry", async () => {
|
||||
const updates: string[] = [];
|
||||
const value = ref("12");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => ({ value }),
|
||||
render: () =>
|
||||
h(
|
||||
InputOTP,
|
||||
{
|
||||
maxLength: 4,
|
||||
modelValue: value.value,
|
||||
"onUpdate:modelValue": (v: string) => {
|
||||
updates.push(v);
|
||||
},
|
||||
},
|
||||
() =>
|
||||
h(InputOTPGroup, () =>
|
||||
[0, 1, 2, 3].map((i) => h(InputOTPSlot, { index: i })),
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
await nextTick();
|
||||
await slotInputs(w)[2].setValue("9");
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
expect(
|
||||
slotInputs(w)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("12");
|
||||
await slotInputs(w)[2].setValue("9");
|
||||
await nextTick();
|
||||
expect(updates.filter((u) => u === "129").length).toBe(2);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("middle deletion keeps slot values aligned without left-shift", async () => {
|
||||
const value = ref("1234");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => ({ value }),
|
||||
render: () =>
|
||||
h(
|
||||
InputOTP,
|
||||
{
|
||||
maxLength: 4,
|
||||
modelValue: value.value,
|
||||
"onUpdate:modelValue": (v: string) => {
|
||||
value.value = v;
|
||||
},
|
||||
},
|
||||
() =>
|
||||
h(InputOTPGroup, () =>
|
||||
[0, 1, 2, 3].map((i) => h(InputOTPSlot, { index: i })),
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
await nextTick();
|
||||
await slotInputs(w)[1].trigger("keydown", { key: "Delete" });
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
expect(
|
||||
slotInputs(w).map((i) => (i.element as HTMLInputElement).value),
|
||||
).toEqual(["1", "", "3", "4"]);
|
||||
expect(
|
||||
w.findAll('[data-slot="input-otp-slot-value"]').map((i) => i.text()),
|
||||
).toEqual(["1", "3", "4"]);
|
||||
w.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe("InputOTP demos", () => {
|
||||
it("mounts all 11 demos without Vue warnings", async () => {
|
||||
const names = [
|
||||
"basic",
|
||||
"variants",
|
||||
"on-surface",
|
||||
"disabled",
|
||||
"four-digits",
|
||||
"controlled",
|
||||
"on-complete",
|
||||
"form-example",
|
||||
"with-pattern",
|
||||
"with-validation",
|
||||
"custom-styles",
|
||||
];
|
||||
expect(names).toHaveLength(11);
|
||||
const warnings: string[] = [];
|
||||
const spy = vi.spyOn(console, "warn").mockImplementation((...args) => {
|
||||
warnings.push(args.map(String).join(" "));
|
||||
});
|
||||
for (const name of names) {
|
||||
const mod = await import(`../apps/docs/demos/input-otp-${name}.vue`);
|
||||
const w = mount(mod.default, { attachTo: document.body });
|
||||
await nextTick();
|
||||
expect(w.html().length).toBeGreaterThan(0);
|
||||
w.unmount();
|
||||
}
|
||||
spy.mockRestore();
|
||||
expect(warnings).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("InputOTP types", () => {
|
||||
it("accepts legal string model and rejects illegal variant", () => {
|
||||
const ok: InstanceType<typeof InputOTPRoot>["$props"] = {
|
||||
modelValue: "123",
|
||||
maxLength: 6,
|
||||
variant: "secondary",
|
||||
};
|
||||
expect(ok.modelValue).toBe("123");
|
||||
const bad: InstanceType<typeof InputOTPRoot>["$props"] = {
|
||||
maxLength: 4,
|
||||
// @ts-expect-error variant must be primary | secondary
|
||||
variant: "ghost",
|
||||
};
|
||||
expect((bad as { variant?: string }).variant).toBe("ghost");
|
||||
});
|
||||
});
|
||||
|
||||
describe("InputOTP SSR", () => {
|
||||
it("renders without touching browser globals", async () => {
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(InputOTP, { maxLength: 4, name: "code", defaultValue: "12" }, () =>
|
||||
h(InputOTPGroup, () =>
|
||||
[0, 1, 2, 3].map((i) => h(InputOTPSlot, { index: i })),
|
||||
),
|
||||
),
|
||||
}),
|
||||
);
|
||||
expect(html).toContain('data-slot="input-otp"');
|
||||
expect(html).toContain("hv-input-otp");
|
||||
expect(html).toContain('data-slot="input-otp-slot"');
|
||||
expect(html).toContain("1");
|
||||
expect(html).toContain('name="code"');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,297 @@
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { defineComponent, h, ref } from "vue";
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
Fieldset,
|
||||
Form,
|
||||
Pagination,
|
||||
PaginationLink,
|
||||
} from "../packages/vue/src";
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(async () => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
await flushPromises();
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
function fixture(template: string, setup = () => ({})) {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
Description,
|
||||
FieldError,
|
||||
Fieldset,
|
||||
Form,
|
||||
Pagination,
|
||||
PaginationLink,
|
||||
},
|
||||
template,
|
||||
setup,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
const slots =
|
||||
'<InputOTPGroup><InputOTPSlot v-for="i in 4" :key="i" :index="i-1"/></InputOTPGroup>';
|
||||
const inputs = (w: ReturnType<typeof mount>) =>
|
||||
w.findAll('input[data-slot="input-otp-input"]');
|
||||
|
||||
it("noncontrolled OTP restores its initial visible and submitted value on native reset", async () => {
|
||||
const w = fixture(
|
||||
`<form><InputOTP :max-length="4" default-value="12" name="code">${slots}</InputOTP></form>`,
|
||||
);
|
||||
await inputs(w)[0].setValue("9");
|
||||
await flushPromises();
|
||||
expect(new FormData(w.get("form").element).get("code")).toBe("92");
|
||||
w.get("form").element.reset();
|
||||
await flushPromises();
|
||||
expect(
|
||||
inputs(w)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("12");
|
||||
expect(new FormData(w.get("form").element).get("code")).toBe("12");
|
||||
});
|
||||
it("controlled OTP middle deletion keeps visual slots aligned with real inputs", async () => {
|
||||
const value = ref("1234");
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4" v-model="value">${slots}</InputOTP>`,
|
||||
() => ({ value }),
|
||||
);
|
||||
await inputs(w)[1].trigger("keydown", { key: "Delete" });
|
||||
await flushPromises();
|
||||
expect(inputs(w).map((i) => (i.element as HTMLInputElement).value)).toEqual([
|
||||
"1",
|
||||
"",
|
||||
"3",
|
||||
"4",
|
||||
]);
|
||||
expect(
|
||||
w.findAll('[data-slot="input-otp-slot-value"]').map((i) => i.text()),
|
||||
).toEqual(["1", "3", "4"]);
|
||||
expect(
|
||||
w.findAll('[data-slot="input-otp-slot"]')[1].attributes("data-filled"),
|
||||
).toBeUndefined();
|
||||
});
|
||||
it("rejecting a controlled update still allows a later identical request", async () => {
|
||||
const update = vi.fn();
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4" model-value="12" @update:model-value="update">${slots}</InputOTP>`,
|
||||
() => ({ update }),
|
||||
);
|
||||
await inputs(w)[2].setValue("9");
|
||||
await flushPromises();
|
||||
expect(
|
||||
inputs(w)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("12");
|
||||
await inputs(w)[2].setValue("9");
|
||||
await flushPromises();
|
||||
expect(update).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
it("OTP readonly blocks editing and deletion", async () => {
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4" default-value="1234" readonly>${slots}</InputOTP>`,
|
||||
);
|
||||
expect((inputs(w)[0].element as HTMLInputElement).readOnly).toBe(true);
|
||||
await inputs(w)[0].trigger("keydown", { key: "Delete" });
|
||||
await flushPromises();
|
||||
expect(
|
||||
inputs(w)
|
||||
.map((i) => (i.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("1234");
|
||||
});
|
||||
it("OTP consumes Fieldset disabled for real input state and visual slots", async () => {
|
||||
const w = fixture(
|
||||
`<Fieldset disabled><InputOTP :max-length="4">${slots}</InputOTP></Fieldset>`,
|
||||
);
|
||||
expect((inputs(w)[0].element as HTMLInputElement).disabled).toBe(true);
|
||||
expect(
|
||||
w.get('[data-slot="input-otp-slot"]').attributes("data-disabled"),
|
||||
).toBeDefined();
|
||||
});
|
||||
it("OTP real inputs reference descriptions and errors from their field context", async () => {
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4" is-invalid :validation-errors="['Invalid']"><Label>Code</Label>${slots}<Description id="otp-help">Help</Description><FieldError id="otp-error"/></InputOTP>`,
|
||||
);
|
||||
await flushPromises();
|
||||
for (const input of inputs(w)) {
|
||||
expect(input.attributes("aria-describedby")?.split(/\s+/)).toContain(
|
||||
"otp-help",
|
||||
);
|
||||
expect(input.attributes("aria-describedby")?.split(/\s+/)).toContain(
|
||||
"otp-error",
|
||||
);
|
||||
expect(input.attributes("aria-invalid")).toBe("true");
|
||||
}
|
||||
});
|
||||
it("OTP consumes named server errors from the public Form", async () => {
|
||||
const w = fixture(
|
||||
`<Form :validation-errors="{code: 'Invalid code'}"><InputOTP :max-length="4" name="code">${slots}<FieldError/></InputOTP></Form>`,
|
||||
);
|
||||
await flushPromises();
|
||||
expect(w.get('[data-slot="input-otp"]').attributes("data-invalid")).toBe(
|
||||
"true",
|
||||
);
|
||||
expect(w.text()).toContain("Invalid code");
|
||||
});
|
||||
it("OTP inputClassName augments the structural input class", () => {
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4" input-class-name="custom-input">${slots}</InputOTP>`,
|
||||
);
|
||||
expect(inputs(w)[0].classes()).toContain("custom-input");
|
||||
expect(inputs(w)[0].classes()).toContain("hv-input-otp__input");
|
||||
});
|
||||
it("OTP mask does not reveal plaintext through its visual value layer", () => {
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4" default-value="1234" mask>${slots}</InputOTP>`,
|
||||
);
|
||||
expect(
|
||||
inputs(w).every((input) => input.attributes("type") === "password"),
|
||||
).toBe(true);
|
||||
expect(w.get('[data-slot="input-otp-slot-value"]').text()).not.toBe("1");
|
||||
});
|
||||
it("PaginationLink preserves an explicit aria-current override when not isActive", () => {
|
||||
const w = fixture(
|
||||
'<Pagination><PaginationLink aria-current="step">Next step</PaginationLink></Pagination>',
|
||||
);
|
||||
expect(w.get("button").attributes("aria-current")).toBe("step");
|
||||
});
|
||||
|
||||
it("OTP composed Label names the actual focusable input", async () => {
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4"><Label id="otp-label">Verification code</Label>${slots}</InputOTP>`,
|
||||
);
|
||||
await flushPromises();
|
||||
const actual = inputs(w)[0];
|
||||
const hasReference = actual
|
||||
.attributes("aria-labelledby")
|
||||
?.split(/\s+/)
|
||||
.includes("otp-label");
|
||||
const hasNativeLabel =
|
||||
Boolean(actual.attributes("id")) &&
|
||||
w.get("label").attributes("for") === actual.attributes("id");
|
||||
const hasExplicitName = actual
|
||||
.attributes("aria-label")
|
||||
?.includes("Verification code");
|
||||
expect(Boolean(hasReference || hasNativeLabel || hasExplicitName)).toBe(true);
|
||||
});
|
||||
it("OTP dynamically added readonly reaches the real input", async () => {
|
||||
const extra = ref<Record<string, unknown>>({});
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4" default-value="12" v-bind="extra">${slots}</InputOTP>`,
|
||||
() => ({ extra }),
|
||||
);
|
||||
expect((inputs(w)[0].element as HTMLInputElement).readOnly).toBe(false);
|
||||
extra.value = { readonly: true };
|
||||
await flushPromises();
|
||||
expect((inputs(w)[0].element as HTMLInputElement).readOnly).toBe(true);
|
||||
});
|
||||
it("OTP edit dismisses the current server error response", async () => {
|
||||
const w = fixture(
|
||||
`<Form :validation-errors="{code:'Invalid code'}"><InputOTP :max-length="4" name="code" default-value="12">${slots}<FieldError/></InputOTP></Form>`,
|
||||
);
|
||||
await inputs(w)[0].setValue("9");
|
||||
await flushPromises();
|
||||
expect(
|
||||
w.get('[data-slot="input-otp"]').attributes("data-invalid"),
|
||||
).toBeUndefined();
|
||||
expect(w.text()).not.toContain("Invalid code");
|
||||
});
|
||||
it("OTP does not lose valid characters with a global RegExp filter", async () => {
|
||||
const filter = /\d/g;
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4" :pattern="filter">${slots}</InputOTP>`,
|
||||
() => ({ filter }),
|
||||
);
|
||||
for (let i = 0; i < 4; i++) await inputs(w)[i].setValue(String(i + 1));
|
||||
await flushPromises();
|
||||
expect(
|
||||
inputs(w)
|
||||
.map((input) => (input.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("1234");
|
||||
});
|
||||
it("OTP Slot keydown.prevent cancels editing before the bottom-layer handler", async () => {
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4" default-value="1234"><InputOTPGroup><InputOTPSlot v-for="i in 4" :key="i" :index="i-1" @keydown.prevent/></InputOTPGroup></InputOTP>`,
|
||||
);
|
||||
await inputs(w)[1].trigger("keydown", { key: "Delete" });
|
||||
await flushPromises();
|
||||
expect(
|
||||
inputs(w)
|
||||
.map((input) => (input.element as HTMLInputElement).value)
|
||||
.join(""),
|
||||
).toBe("1234");
|
||||
});
|
||||
it("OTP capture handler arrays honor stopImmediatePropagation", async () => {
|
||||
const stop = (event: Event) => event.stopImmediatePropagation();
|
||||
const after = vi.fn();
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4" default-value="1234"><InputOTPGroup><InputOTPSlot v-for="i in 4" :key="i" :index="i-1" :onKeydownCapture="[stop,after]"/></InputOTPGroup></InputOTP>`,
|
||||
() => ({ stop, after }),
|
||||
);
|
||||
await inputs(w)[1].trigger("keydown", { key: "Delete" });
|
||||
await flushPromises();
|
||||
expect(after).not.toHaveBeenCalled();
|
||||
});
|
||||
it("OTP resizing retains existing empty slot indices", async () => {
|
||||
const length = ref(4);
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="length" default-value="1234"><InputOTPGroup><InputOTPSlot v-for="i in length" :key="i" :index="i-1"/></InputOTPGroup></InputOTP>`,
|
||||
() => ({ length }),
|
||||
);
|
||||
await inputs(w)[1].trigger("keydown", { key: "Delete" });
|
||||
await flushPromises();
|
||||
length.value = 5;
|
||||
await flushPromises();
|
||||
expect(
|
||||
inputs(w).map((input) => (input.element as HTMLInputElement).value),
|
||||
).toEqual(["1", "", "3", "4", ""]);
|
||||
});
|
||||
it("OTP form and validation examples have unique field IDs on the same page", async () => {
|
||||
const formDemo =
|
||||
await import("../apps/docs/demos/input-otp-form-example.vue");
|
||||
const validationDemo =
|
||||
await import("../apps/docs/demos/input-otp-with-validation.vue");
|
||||
const wrapper = mount(
|
||||
defineComponent({
|
||||
render: () => h("div", [h(formDemo.default), h(validationDemo.default)]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(wrapper);
|
||||
await flushPromises();
|
||||
const ids = wrapper
|
||||
.findAll("[id]")
|
||||
.map((element) => element.attributes("id"));
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
});
|
||||
it("OTP primitive fallback name cannot override a composed Label or explicit name", async () => {
|
||||
const w = fixture(
|
||||
`<InputOTP :max-length="4"><Label id="otp-composed">Verification code</Label>${slots}</InputOTP>`,
|
||||
);
|
||||
await flushPromises();
|
||||
for (const input of inputs(w))
|
||||
expect(input.attributes("aria-labelledby")?.split(/\s+/)).toContain(
|
||||
"otp-composed",
|
||||
);
|
||||
const explicit = fixture(
|
||||
`<InputOTP :max-length="4" aria-label="Security code">${slots}</InputOTP>`,
|
||||
);
|
||||
await flushPromises();
|
||||
expect(inputs(explicit)[0].attributes("aria-label")).toBe("Security code");
|
||||
});
|
||||
@@ -0,0 +1,623 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount } from "@vue/test-utils";
|
||||
import { createSSRApp, defineComponent, h, nextTick, ref } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationEllipsis,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
PaginationNext,
|
||||
PaginationNextIcon,
|
||||
PaginationPrevious,
|
||||
PaginationPreviousIcon,
|
||||
PaginationRoot,
|
||||
PaginationSummary,
|
||||
} from "../packages/vue/src";
|
||||
|
||||
import PaginationBasicDemo from "../apps/docs/demos/pagination-basic.vue";
|
||||
import PaginationSizesDemo from "../apps/docs/demos/pagination-sizes.vue";
|
||||
import PaginationDisabledDemo from "../apps/docs/demos/pagination-disabled.vue";
|
||||
import PaginationSimplePrevNextDemo from "../apps/docs/demos/pagination-simple-prev-next.vue";
|
||||
import PaginationControlledDemo from "../apps/docs/demos/pagination-controlled.vue";
|
||||
import PaginationWithEllipsisDemo from "../apps/docs/demos/pagination-with-ellipsis.vue";
|
||||
import PaginationWithSummaryDemo from "../apps/docs/demos/pagination-with-summary.vue";
|
||||
import PaginationCustomIconsDemo from "../apps/docs/demos/pagination-custom-icons.vue";
|
||||
import PaginationCustomStylesDemo from "../apps/docs/demos/pagination-custom-styles.vue";
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
function mountFull(props: Record<string, unknown> = {}, rootProps = {}) {
|
||||
return mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Pagination, { ...rootProps }, () =>
|
||||
h(PaginationContent, () => [
|
||||
h(PaginationItem, () =>
|
||||
h(PaginationPrevious, props.previous ?? {}, () => [
|
||||
h(PaginationPreviousIcon),
|
||||
h("span", "上一页"),
|
||||
]),
|
||||
),
|
||||
h(PaginationItem, () =>
|
||||
h(PaginationLink, props.link ?? {}, () => "1"),
|
||||
),
|
||||
h(PaginationItem, () => h(PaginationEllipsis)),
|
||||
h(PaginationItem, () =>
|
||||
h(PaginationNext, props.next ?? {}, () => [
|
||||
h("span", "下一页"),
|
||||
h(PaginationNextIcon),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
}
|
||||
|
||||
describe("Pagination structure and ARIA", () => {
|
||||
it("renders nav/list/listitem with baseline slots and classes", () => {
|
||||
const w = mountFull({}, { size: "md" });
|
||||
const root = w.get('[data-slot="pagination"]');
|
||||
expect(root.element.tagName).toBe("NAV");
|
||||
expect(root.attributes("role")).toBe("navigation");
|
||||
expect(root.attributes("aria-label")).toBe("pagination");
|
||||
expect(root.classes().join(" ")).toContain("hv-pagination");
|
||||
expect(root.classes().join(" ")).toContain("hv-pagination--md");
|
||||
|
||||
const content = w.get('[data-slot="pagination-content"]');
|
||||
expect(content.element.tagName).toBe("UL");
|
||||
expect(content.classes().join(" ")).toContain("hv-pagination__content");
|
||||
|
||||
const items = w.findAll('[data-slot="pagination-item"]');
|
||||
expect(items).toHaveLength(4);
|
||||
for (const item of items) {
|
||||
expect(item.element.tagName).toBe("LI");
|
||||
expect(item.classes().join(" ")).toContain("hv-pagination__item");
|
||||
}
|
||||
|
||||
const link = w.get('[data-slot="pagination-link"]');
|
||||
expect(link.element.tagName).toBe("BUTTON");
|
||||
expect(link.attributes("type")).toBe("button");
|
||||
expect(link.classes().join(" ")).toContain("hv-pagination__link");
|
||||
expect(link.classes().join(" ")).not.toContain("hv-button");
|
||||
|
||||
const previous = w.get('[data-slot="pagination-previous"]');
|
||||
expect(previous.element.tagName).toBe("BUTTON");
|
||||
expect(previous.attributes("type")).toBe("button");
|
||||
expect(previous.classes().join(" ")).toContain("hv-pagination__link");
|
||||
expect(previous.classes().join(" ")).toContain("hv-pagination__link--nav");
|
||||
expect(previous.classes().join(" ")).not.toContain("hv-button");
|
||||
|
||||
const next = w.get('[data-slot="pagination-next"]');
|
||||
expect(next.classes().join(" ")).toContain("hv-pagination__link--nav");
|
||||
|
||||
const ellipsis = w.get('[data-slot="pagination-ellipsis"]');
|
||||
expect(ellipsis.element.tagName).toBe("SPAN");
|
||||
expect(ellipsis.attributes("aria-hidden")).toBe("true");
|
||||
expect(ellipsis.text()).toBe("…");
|
||||
|
||||
const prevIcon = w.get('[data-slot="pagination-previous-icon"]');
|
||||
expect(prevIcon.attributes("aria-hidden")).toBe("true");
|
||||
expect(prevIcon.find("svg").exists()).toBe(true);
|
||||
|
||||
const nextIcon = w.get('[data-slot="pagination-next-icon"]');
|
||||
expect(nextIcon.attributes("aria-hidden")).toBe("true");
|
||||
expect(nextIcon.find("svg").exists()).toBe(true);
|
||||
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("exposes Pagination as Root alias and isolated instances", () => {
|
||||
expect(Pagination).toBe(PaginationRoot);
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h("div", () => [
|
||||
h(Pagination, { "data-testid": "a" }, () =>
|
||||
h(PaginationContent, () =>
|
||||
h(PaginationItem, () =>
|
||||
h(PaginationLink, { isActive: true }, () => "1"),
|
||||
),
|
||||
),
|
||||
),
|
||||
h(Pagination, { "data-testid": "b", size: "lg" }, () =>
|
||||
h(PaginationContent, () =>
|
||||
h(PaginationItem, () =>
|
||||
h(PaginationLink, { isActive: true }, () => "1"),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const roots = w.findAll('[data-slot="pagination"]');
|
||||
expect(roots).toHaveLength(2);
|
||||
expect(roots[0].classes().join(" ")).toContain("hv-pagination--md");
|
||||
expect(roots[1].classes().join(" ")).toContain("hv-pagination--lg");
|
||||
expect(roots[0].attributes("aria-label")).toBe("pagination");
|
||||
expect(roots[0].attributes("data-testid")).toBe("a");
|
||||
expect(roots[1].attributes("data-testid")).toBe("b");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("updates size context dynamically and keeps custom classes", async () => {
|
||||
const size = ref<"sm" | "md" | "lg">("sm");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => ({ size }),
|
||||
render: () =>
|
||||
h(Pagination, { size: size.value, class: "custom-root" }, () =>
|
||||
h(PaginationContent, { class: "custom-content" }, () =>
|
||||
h(PaginationItem, { class: "custom-item" }, () =>
|
||||
h(PaginationLink, { class: "custom-link" }, () => "1"),
|
||||
),
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
let root = w.get('[data-slot="pagination"]');
|
||||
expect(root.classes().join(" ")).toContain("hv-pagination--sm");
|
||||
expect(root.classes().join(" ")).toContain("custom-root");
|
||||
expect(w.get('[data-slot="pagination-content"]').classes()).toContain(
|
||||
"custom-content",
|
||||
);
|
||||
expect(w.get('[data-slot="pagination-item"]').classes()).toContain(
|
||||
"custom-item",
|
||||
);
|
||||
expect(w.get('[data-slot="pagination-link"]').classes()).toContain(
|
||||
"custom-link",
|
||||
);
|
||||
|
||||
size.value = "lg";
|
||||
await nextTick();
|
||||
root = w.get('[data-slot="pagination"]');
|
||||
expect(root.classes().join(" ")).toContain("hv-pagination--lg");
|
||||
expect(root.classes().join(" ")).not.toContain("hv-pagination--sm");
|
||||
expect(root.classes().join(" ")).toContain("custom-root");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("keeps nested pagination size contexts independent", () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Pagination, { size: "sm", "data-testid": "outer" }, () =>
|
||||
h(PaginationContent, () => [
|
||||
h(PaginationItem, () => h(PaginationLink, () => "1")),
|
||||
h(PaginationItem, () =>
|
||||
h(Pagination, { size: "lg", "data-testid": "inner" }, () =>
|
||||
h(PaginationContent, () =>
|
||||
h(PaginationItem, () => h(PaginationLink, () => "2")),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const outer = w.get('[data-testid="outer"]');
|
||||
const inner = w.get('[data-testid="inner"]');
|
||||
expect(outer.classes().join(" ")).toContain("hv-pagination--sm");
|
||||
expect(inner.classes().join(" ")).toContain("hv-pagination--lg");
|
||||
w.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Pagination active and summary states", () => {
|
||||
it("toggles aria-current and data-active with isActive", async () => {
|
||||
const isActive = ref(true);
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => ({ isActive }),
|
||||
render: () =>
|
||||
h(Pagination, () =>
|
||||
h(PaginationContent, () =>
|
||||
h(PaginationItem, () =>
|
||||
h(PaginationLink, { isActive: isActive.value }, () => "3"),
|
||||
),
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
let link = w.get('[data-slot="pagination-link"]');
|
||||
expect(link.attributes("aria-current")).toBe("page");
|
||||
expect(link.attributes("data-active")).toBe("true");
|
||||
|
||||
isActive.value = false;
|
||||
await nextTick();
|
||||
link = w.get('[data-slot="pagination-link"]');
|
||||
expect(link.attributes("aria-current")).toBeUndefined();
|
||||
expect(link.attributes("data-active")).toBeUndefined();
|
||||
|
||||
isActive.value = true;
|
||||
await nextTick();
|
||||
link = w.get('[data-slot="pagination-link"]');
|
||||
expect(link.attributes("aria-current")).toBe("page");
|
||||
expect(link.attributes("data-active")).toBe("true");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("summary defaults to dir=auto and allows explicit dir override", async () => {
|
||||
const dir = ref<string | undefined>(undefined);
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
setup: () => ({ dir }),
|
||||
render: () =>
|
||||
h(Pagination, () =>
|
||||
h(PaginationSummary, { dir: dir.value }, () => "1–5 of 10"),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
let summary = w.get('[data-slot="pagination-summary"]');
|
||||
expect(summary.element.tagName).toBe("DIV");
|
||||
expect(summary.attributes("dir")).toBe("auto");
|
||||
expect(summary.classes().join(" ")).toContain("hv-pagination__summary");
|
||||
|
||||
dir.value = "rtl";
|
||||
await nextTick();
|
||||
summary = w.get('[data-slot="pagination-summary"]');
|
||||
expect(summary.attributes("dir")).toBe("rtl");
|
||||
|
||||
dir.value = undefined;
|
||||
await nextTick();
|
||||
summary = w.get('[data-slot="pagination-summary"]');
|
||||
expect(summary.attributes("dir")).toBe("auto");
|
||||
w.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Pagination button behavior", () => {
|
||||
it("activates once on click and does not when disabled", async () => {
|
||||
const clicks = vi.fn();
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Pagination, () =>
|
||||
h(PaginationContent, () =>
|
||||
h(PaginationItem, () =>
|
||||
h(
|
||||
PaginationLink,
|
||||
{ isDisabled: false, onClick: clicks },
|
||||
() => "1",
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
await w.get('[data-slot="pagination-link"]').trigger("click");
|
||||
expect(clicks).toHaveBeenCalledTimes(1);
|
||||
|
||||
await w.unmount();
|
||||
|
||||
const disabledClicks = vi.fn();
|
||||
const w2 = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Pagination, () =>
|
||||
h(PaginationContent, () =>
|
||||
h(PaginationItem, () =>
|
||||
h(
|
||||
PaginationLink,
|
||||
{ isDisabled: true, onClick: disabledClicks },
|
||||
() => "1",
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const disabledLink = w2.get('[data-slot="pagination-link"]');
|
||||
expect(disabledLink.attributes("disabled")).toBeDefined();
|
||||
expect((disabledLink.element as HTMLButtonElement).disabled).toBe(true);
|
||||
await disabledLink.trigger("click");
|
||||
expect(disabledClicks).not.toHaveBeenCalled();
|
||||
w2.unmount();
|
||||
});
|
||||
|
||||
it("supports handler arrays, capture and stopImmediatePropagation", async () => {
|
||||
const order: string[] = [];
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Pagination, () =>
|
||||
h(PaginationContent, () =>
|
||||
h(PaginationItem, () =>
|
||||
h(
|
||||
PaginationLink,
|
||||
{
|
||||
onClick: [
|
||||
() => order.push("a"),
|
||||
(e: Event) => {
|
||||
order.push("b");
|
||||
e.stopImmediatePropagation();
|
||||
},
|
||||
],
|
||||
},
|
||||
() => "1",
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
await w.get('[data-slot="pagination-link"]').trigger("click");
|
||||
expect(order).toEqual(["a", "b"]);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("keeps Previous/Next disabled state on native buttons", async () => {
|
||||
const w = mountFull({
|
||||
previous: { isDisabled: true },
|
||||
next: { disabled: true },
|
||||
});
|
||||
const previous = w.get('[data-slot="pagination-previous"]');
|
||||
const next = w.get('[data-slot="pagination-next"]');
|
||||
expect((previous.element as HTMLButtonElement).disabled).toBe(true);
|
||||
expect((next.element as HTMLButtonElement).disabled).toBe(true);
|
||||
w.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Pagination attrs merge", () => {
|
||||
it("adds, updates, deletes and re-adds root and leaf attrs", async () => {
|
||||
const extra = ref<Record<string, unknown>>({});
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: {
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
},
|
||||
setup: () => ({ extra }),
|
||||
template: `
|
||||
<Pagination v-bind="extra" class="base-root">
|
||||
<PaginationContent v-bind="extra">
|
||||
<PaginationItem v-bind="extra">
|
||||
<PaginationLink v-bind="extra">1</PaginationLink>
|
||||
</PaginationItem>
|
||||
</PaginationContent>
|
||||
</Pagination>
|
||||
`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
|
||||
let root = w.get('[data-slot="pagination"]');
|
||||
expect(root.classes()).toContain("base-root");
|
||||
expect(root.attributes("data-testid")).toBeUndefined();
|
||||
|
||||
extra.value = {
|
||||
"data-testid": "p1",
|
||||
"aria-label": "页码",
|
||||
tabindex: 0,
|
||||
onClick: () => {},
|
||||
};
|
||||
await nextTick();
|
||||
root = w.get('[data-slot="pagination"]');
|
||||
expect(root.attributes("data-testid")).toBe("p1");
|
||||
expect(root.attributes("aria-label")).toBe("页码");
|
||||
expect(root.attributes("tabindex")).toBe("0");
|
||||
const link = w.get('[data-slot="pagination-link"]');
|
||||
expect(link.attributes("data-testid")).toBe("p1");
|
||||
expect(link.attributes("aria-label")).toBe("页码");
|
||||
expect(link.attributes("tabindex")).toBe("0");
|
||||
|
||||
extra.value = { "data-testid": "p2", title: "updated" };
|
||||
await nextTick();
|
||||
root = w.get('[data-slot="pagination"]');
|
||||
expect(root.attributes("data-testid")).toBe("p2");
|
||||
expect(root.attributes("title")).toBe("updated");
|
||||
expect(root.attributes("aria-label")).toBe("pagination");
|
||||
expect(root.attributes("tabindex")).toBeUndefined();
|
||||
|
||||
extra.value = {};
|
||||
await nextTick();
|
||||
root = w.get('[data-slot="pagination"]');
|
||||
expect(root.attributes("data-testid")).toBeUndefined();
|
||||
expect(root.attributes("title")).toBeUndefined();
|
||||
|
||||
extra.value = { style: { color: "red" }, "aria-current": "true" };
|
||||
await nextTick();
|
||||
root = w.get("[data-slot=pagination]");
|
||||
expect(root.attributes("style")).toContain("color: red");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("preserves asChild native child attributes", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Pagination, () =>
|
||||
h(PaginationContent, () =>
|
||||
h(PaginationItem, () =>
|
||||
h(
|
||||
PaginationLink,
|
||||
{
|
||||
asChild: true,
|
||||
isActive: true,
|
||||
"data-custom": "keep",
|
||||
tabindex: 0,
|
||||
},
|
||||
{
|
||||
default: () =>
|
||||
h("a", { href: "#page-1", id: "native-link" }, "1"),
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const link = w.get("#native-link");
|
||||
expect(link.element.tagName).toBe("A");
|
||||
expect(link.attributes("href")).toBe("#page-1");
|
||||
expect(link.attributes("data-custom")).toBe("keep");
|
||||
expect(link.attributes("tabindex")).toBe("0");
|
||||
expect(link.attributes("aria-current")).toBe("page");
|
||||
expect(link.attributes("data-active")).toBe("true");
|
||||
expect(link.attributes("data-slot")).toBe("pagination-link");
|
||||
w.unmount();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Pagination demos", () => {
|
||||
it("controlled demo pages, disables at bounds and keeps summary in sync", async () => {
|
||||
const w = mount(PaginationControlledDemo, { attachTo: document.body });
|
||||
const previous = w.get('[data-slot="pagination-previous"]');
|
||||
const next = w.get('[data-slot="pagination-next"]');
|
||||
expect((previous.element as HTMLButtonElement).disabled).toBe(true);
|
||||
expect((next.element as HTMLButtonElement).disabled).toBe(false);
|
||||
expect(w.get('[data-slot="pagination-summary"]').text()).toContain(
|
||||
"第 1–10 条",
|
||||
);
|
||||
expect(
|
||||
w.get('[data-slot="pagination-link"][data-active="true"]').text(),
|
||||
).toBe("1");
|
||||
|
||||
await next.trigger("click");
|
||||
await nextTick();
|
||||
expect(w.get('[data-slot="pagination-summary"]').text()).toContain(
|
||||
"第 11–20 条",
|
||||
);
|
||||
expect(
|
||||
w.get('[data-slot="pagination-link"][data-active="true"]').text(),
|
||||
).toBe("2");
|
||||
expect(
|
||||
(w.get('[data-slot="pagination-previous"]').element as HTMLButtonElement)
|
||||
.disabled,
|
||||
).toBe(false);
|
||||
|
||||
for (let i = 0; i < 20; i++) {
|
||||
const nextBtn = w.get('[data-slot="pagination-next"]');
|
||||
if ((nextBtn.element as HTMLButtonElement).disabled) break;
|
||||
await nextBtn.trigger("click");
|
||||
}
|
||||
await nextTick();
|
||||
expect(
|
||||
(w.get('[data-slot="pagination-next"]').element as HTMLButtonElement)
|
||||
.disabled,
|
||||
).toBe(true);
|
||||
expect(w.get('[data-slot="pagination-summary"]').text()).toContain(
|
||||
"第 111–120 条",
|
||||
);
|
||||
expect(
|
||||
w.get('[data-slot="pagination-link"][data-active="true"]').text(),
|
||||
).toBe("12");
|
||||
expect(
|
||||
w.findAll('[data-slot="pagination-ellipsis"]').length,
|
||||
).toBeGreaterThan(0);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("basic demo updates the active page", async () => {
|
||||
const w = mount(PaginationBasicDemo, { attachTo: document.body });
|
||||
const links = w.findAll('[data-slot="pagination-link"]');
|
||||
expect(links[0].attributes("data-active")).toBe("true");
|
||||
await links[2].trigger("click");
|
||||
await nextTick();
|
||||
expect(links[2].attributes("data-active")).toBe("true");
|
||||
expect(links[0].attributes("data-active")).toBeUndefined();
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("mounts all 9 pagination demos without Vue warnings", async () => {
|
||||
const warnings: string[] = [];
|
||||
const spy = vi.spyOn(console, "warn").mockImplementation((...args) => {
|
||||
warnings.push(args.map(String).join(" "));
|
||||
});
|
||||
const demos = [
|
||||
PaginationBasicDemo,
|
||||
PaginationSizesDemo,
|
||||
PaginationDisabledDemo,
|
||||
PaginationSimplePrevNextDemo,
|
||||
PaginationControlledDemo,
|
||||
PaginationWithEllipsisDemo,
|
||||
PaginationWithSummaryDemo,
|
||||
PaginationCustomIconsDemo,
|
||||
PaginationCustomStylesDemo,
|
||||
];
|
||||
expect(demos).toHaveLength(9);
|
||||
for (const demo of demos) {
|
||||
const w = mount(demo, { attachTo: document.body });
|
||||
await nextTick();
|
||||
expect(w.html().length).toBeGreaterThan(0);
|
||||
w.unmount();
|
||||
}
|
||||
spy.mockRestore();
|
||||
expect(warnings).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Pagination types", () => {
|
||||
it("accepts legal props and rejects illegal size values", () => {
|
||||
const bad: InstanceType<typeof PaginationRoot>["$props"] = {
|
||||
// @ts-expect-error size must be sm | md | lg
|
||||
size: "xl",
|
||||
};
|
||||
expect((bad as { size?: string }).size).toBe("xl");
|
||||
const ok: InstanceType<typeof PaginationRoot>["$props"] = {
|
||||
size: "lg",
|
||||
};
|
||||
expect(ok.size).toBe("lg");
|
||||
|
||||
const okLink: InstanceType<typeof PaginationLink>["$props"] = {
|
||||
isActive: true,
|
||||
isDisabled: false,
|
||||
};
|
||||
expect(okLink.isActive).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Pagination SSR", () => {
|
||||
it("renders without touching browser globals", async () => {
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(Pagination, { size: "sm" }, () => [
|
||||
h(PaginationSummary, () => "显示第 1–10 条,共 120 条结果"),
|
||||
h(PaginationContent, () => [
|
||||
h(PaginationItem, () =>
|
||||
h(PaginationPrevious, { isDisabled: true }, () => [
|
||||
h(PaginationPreviousIcon),
|
||||
h("span", "上一页"),
|
||||
]),
|
||||
),
|
||||
h(PaginationItem, () =>
|
||||
h(PaginationLink, { isActive: true }, () => "1"),
|
||||
),
|
||||
h(PaginationItem, () => h(PaginationEllipsis)),
|
||||
h(PaginationItem, () =>
|
||||
h(PaginationNext, () => [
|
||||
h("span", "下一页"),
|
||||
h(PaginationNextIcon),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
expect(html).toContain('data-slot="pagination"');
|
||||
expect(html).toContain("hv-pagination--sm");
|
||||
expect(html).toContain('dir="auto"');
|
||||
expect(html).toContain('aria-current="page"');
|
||||
expect(html).toContain('data-active="true"');
|
||||
expect(html).toContain("…");
|
||||
expect(html).toContain("disabled");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user