Files
heroui-vue/docs/migrations/M32-input-otp.md
T

76 lines
5.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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 复核](../history.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、读屏、水合、独立安装。
## 集成人第二轮复核
上面的返修记录不能视为最终验收。新增十八项复核用例中十一项通过、七项失败,详情见 [第二轮复核](../history.md)。本批尚未提交;需继续补真实命名、事件语义、过滤/长度状态与同页示例关联。
## 第二轮复核返修(2026-10-23)
按 [M30–M32 第二轮复核](../history.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 展示错误。
未验证范围不变。