Files
heroui-vue/docs/audit-groups/06-forms-fields.md
T

16 KiB
Raw Blame History

组 06(forms 表单字段族)差异报告

范围:description、error-message、field-error、fieldset、form、input-group、input-otp、label、number-field。 基线:上游 ce90ea3(heroui/)对 heroui-vue/。已剔除 use client、模板循环、hv- 前缀、图标库约定(上游 @gravity-ui/icons/内联 SVG → Tabler,见文末备注)等非硬差异。

组级发现(@heroui-vue/styles 导出契约)

  • [API] heroui-vue/packages/styles/src/index.ts(@heroui-vue/styles 唯一入口)缺 5 个 tv 导出:descriptionVariants、fieldErrorVariants、labelVariants(本组),以及 textFieldVariants、switchGroupVariants(他组,一并核实)。上游经 heroui/packages/styles/src/components/index.ts export * 导出全部(含 heroui/packages/styles/src/components/{description,label,field-error}/*.styles.ts)。
    • Vue 侧取类方式:组件直接硬编码类名——Description.vue 写死 hv-description、Label.vue 写死 hv-label/hv-label--required|--disabled|--invalid、FieldError.vue 写死 hv-field-error(均在 heroui-vue/packages/vue/src/components/);CSS 文件本身存在且与上游一致,视觉不受影响。
    • 但按名从 @heroui-vue/styles 导入 descriptionVariants/fieldErrorVariants/labelVariants 会失败,属对外 API 契约缺失(对照:errorMessageVariants、inputOTPVariants、numberFieldVariants、inputGroupVariants、fieldsetVariants 在 Vue index.ts 均存在且与上游逐字一致)。

description

  • [示例] 文档内联示例文案:上游 cn 文档保留英文 Password、Enter your email、We'll never share your email(heroui/apps/docs/content/docs/cn/react/components/(forms)/description.mdx),Vue 译为"密码/输入你的邮箱/我们不会分享你的邮箱"(heroui-vue/apps/docs/components/description.md)。实际演示 description-basic、description-custom-styles 内容逐项一致。
  • [API] descriptionVariants 未导出(见组级发现)。
  • [API] 文档 API 表:上游仅 className/children;Vue 表增列 id(默认"自动",组件确实自动生成并注册到控件 aria-describedby)。children→插槽、className→class 为框架映射。
  • [样式] description.css 双方一致(仅许可头/hv- 前缀)。

error-message

  • [示例] error-message-basic、error-message-custom-styles 内容一致(TagGroup 多选、4/3 个 Tag、文案相同)。
  • [API] errorMessageVariants 双方均有(Vue heroui-vue/packages/styles/src/index.ts:1743)。
  • [样式] 文档 CSS 类描述:上游写"danger 色与文本截断",但上游 heroui/packages/styles/components/error-message.css 实为 wrap-break-word 换行(上游文档与自身代码不一致);Vue 改为"danger 色与文本换行"(heroui-vue/apps/docs/components/error-message.md),与 CSS 一致。
  • [API] Vue 插槽类清单多 [data-slot="error-message"](组件确实渲染 data-slot="error-message" 与 slot="errorMessage",heroui-vue/packages/vue/src/components/error-message/ErrorMessage.vue);API 表多 id 行。均为增列,非缺失。

field-error

  • [API] fieldErrorVariants 未导出(见组级发现)。
  • [API] 能力差异:上游 FieldError children 支持 render 函数 (validation: ValidationResult) => …,含完整 validationDetails(heroui/packages/react/src/components/field-error/field-error.tsx 用 RAC FieldErrorPrimitive + renderProps);Vue 作用域插槽仅提供 validationErrors、isInvalid,无 validationDetails,Vue 文档自述"当前未提供完整 React Aria validationDetails 对象"(heroui-vue/apps/docs/components/field-error.md)。
  • [实现] 渲染条件:Vue v-if="!field || field.invalid.value"——无字段上下文时始终渲染、字段有效时隐藏,并额外输出 role="alert"(heroui-vue/packages/vue/src/components/field/FieldError.vue);上游由 RAC 校验上下文驱动。两者在"字段无效才显示"的常见场景等价,脱离字段使用时行为不同(待核实可见影响)。
  • [样式] 文档描述"长消息以省略号截断"(上游)vs"长消息自动换行(wrap-break-word)"(Vue);上游 field-error.css 实为换行,无省略号——又是上游文档与自身 CSS 不一致,Vue 纠正。CSS 文件双方一致。
  • [示例] 文档内联示例文案本地化(Username→用户名 等);Vue 增加 validate 同步拦截示例文本(新增说明性内容,非缺失)。

label

  • [API] labelVariants 未导出(见组级发现)。上游 labelVariants 含 isDisabled/isInvalid/isRequired → label--disabled|--invalid|--required(heroui/packages/styles/src/components/label/label.styles.ts);Vue Label 组件硬编码同类名,行为等价。
  • [示例] 文档"验证状态"示例:上游 <Label htmlFor="password" isInvalid>…<Input id="password" isInvalid />;Vue <Label for="password" is-invalid>密码</Label><Input id="password" type="password" />——Input 未标 invalid 且改了 type(heroui-vue/apps/docs/components/label.md)。示例 props/内容差异(轻微)。
  • [样式] label.css 双方一致(含必填星号 role/data-slot 排除规则)。

fieldset

  • [示例] Vue 多 fieldset-disabled 示例(已知;文档明示"本库新增的协议验证例,不属于上游三项基线示例",heroui-vue/apps/docs/components/fieldset.md 禁用继承一节)。上游无。
  • [示例] fieldset-basic / on-surface / custom-styles 提交反馈:上游 alert("表单提交成功!");Vue 改为页内 <p role="status"> 显示"表单提交成功!+ FormData JSON",并在 reset 按钮加 @click="result = ''"(heroui/apps/docs/src/demos/cn/fieldset/basic.tsx vs heroui-vue/apps/docs/demos/fieldset-basic.vue 等三对)。交互反馈形态差异。
  • [示例] fieldset-on-surface:Vue 的 Surface 加 max-sm:min-w-0(heroui-vue/apps/docs/demos/fieldset-on-surface.vue),窄屏下不再强制 380px 最小宽度(轻微视觉差异)。
  • [API/实现] Vue 新增 disabled 下发语义:原生 disabled 同步到本库文本输入、SearchField、Switch、Button、CloseButton、Link 的状态/事件/表单值,内层组不可解除、首个直接 Legend 保留原生例外(heroui-vue/packages/vue/src/components/fieldset/Fieldset.vue disabledContextKey 逻辑)。上游仅原生 fieldset disabled(heroui/packages/react/src/components/fieldset/)。加法行为,文档已列。
  • [文档] 缺整节 ## 相关案例 <RelatedShowcases component="Fieldset" />(heroui/apps/docs/content/docs/cn/react/components/(forms)/fieldset.mdx 末尾)。
  • [样式] fieldset.css 与 fieldsetVariants 双方一致。

form

  • [示例] form-basic / form-render-function:上游提交反馈 alert("表单提交数据:…JSON…");Vue 改为页内 <pre role="status" aria-label="提交结果"> 并 @reset="result = ''" 清除;容器 flex w-96 flex-col gap-4 → 加 max-w-full(heroui/apps/docs/src/demos/cn/form/basic.tsx vs heroui-vue/apps/docs/demos/form-basic.vue)。form-custom-styles 仅 max-w-full 差异。Vue 文档自述该替换。
  • [API] API 表类型差异:上游 encType 为 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain'、method 为 'get' | 'post'、target 为四值 union、action: string | FormHTMLAttributes['action']、validationErrors: ValidationErrors(默认 -);Vue 对应 enctype/method/target 退化为 string,validationErrors 默认 {}(heroui-vue/apps/docs/components/form.md API 表)。
  • [API] Vue 新增(文档标注为扩展):novalidate/noValidate prop、FormExpose(element/checkValidity/reportValidity/reset)、FormRoot 别名。上游独有的 render(DOMRenderFunction)未移植,以 attrs 透传替代(已文档化)。
  • [API/能力] Vue 文档明示不提供 React Form Context、函数 action、完整 RAC ValidationResult(form.md 进阶用法一节)。
  • [实现] Vue <form novalidate> 恒定挂载,@submit.capture 逐控件用 Constraint Validation API 检查,支持按控件 data-validation-behavior 混合 native/aria、formnovalidate 跳过(heroui-vue/packages/vue/src/components/form/Form.vue);上游为 react-aria-components Form 直接包装(heroui/packages/react/src/components/form/form.tsx)。实际提交拦截/焦点行为等价性未实测(待核实)。
  • [文档] 缺 ## 相关案例 <RelatedShowcases component="Form" />(上游 form.mdx 末尾;Vue 以 /fields 页面链接替代)。
  • [备注] heroui-vue/apps/docs/demos/form-foundation.vue 仅被新增的 fields.md(字段与表单基础)引用,不属本组件文档示例。

input-group

  • [示例] input-group-with-textarea:上游 4 处 Tooltip delay={0} + Tooltip.Content("添加文件等/连接应用/语音输入/发送",发送提示内含 Kbd > Kbd.Abbr keyValue="enter");Vue 全部改为原生 title 属性,Enter 快捷键 Kbd 提示被删除(heroui/apps/docs/src/demos/cn/input-group/with-textarea.tsx vs heroui-vue/apps/docs/demos/input-group-with-textarea.vue)。hover 提示形态与快捷键提示为可见差异(Vue 文档注明"Tooltip 组件尚未迁移")。
  • [API] variant 默认值描述差异:上游文档 default 'primary';Vue API 表写"继承 TextField,否则 'primary'"(heroui-vue/apps/docs/components/input-group.md)。其余 API 差异为子部件命名映射(InputGroup.Input→InputGroupInput 等)与 render props→作用域插槽。
  • [文档] 缺两个整段代码示例章节:### 用法示例(Iconify 图标 + 确认按钮例)与 ### 文本域用法示例(500 字符反馈例,含 Character count)(heroui/apps/docs/content/docs/cn/react/components/(forms)/input-group.mdx 约 156–215 行)。
  • [文档] 缺 ## 相关案例 <RelatedShowcases component="InputGroup" />。
  • [样式] input-group.css 与 inputGroupVariants 双方一致(含 textarea 时 items-start、[data-slot="input-group-textarea"] 说明保留)。
  • 其余 20 个示例(default/variants/disabled/full-width/invalid/on-surface/password-with-toggle/required/custom-styles/with-* 等)内容、文案、props 一致(password-with-toggle 的 显示密码/隐藏密码 动态 aria-label 等价)。

input-otp

  • [实现/样式] 底座不同:上游用 input-otp 包的单隐藏 input(heroui/packages/react/src/components/input-otp/input-otp.tsx OTPInput,inputClassName→slots.input,containerClassName→slots.base);Vue 用 Reka PinInput 多真实 input + 隐藏提交 input(heroui-vue/packages/vue/src/components/input-otp/InputOTPRoot.vue)。Vue CSS 因此新增 .hv-input-otp__input { absolute inset-0 z-10 … text-transparent caret-transparent } 透明覆盖层规则(heroui-vue/packages/styles/components/input-otp.css),上游 input-otp.css 无对应规则(隐藏 input 由 input-otp 包定位)。其余 CSS、slot-value-in keyframe 250ms、inputOTPVariants 完全一致。
  • [API] 缺失 props(上游 input-otp.mdx Input/Form Props 表):validationDetails(ValidityState)、textAlign、pasteTransformer、autoFocus、containerClassName、pushPasswordManagerStrategy。Vue "上游差异"表列了 pushPasswordManagerStrategy 与 render/OTPInputContext,但未列 validationDetails/textAlign/pasteTransformer/autoFocus(API 表中也无)。
  • [API] 行为差异(文档自述 + 源码):onComplete 上游为"值达到长度即触发",Vue 为"状态切换为填满时触发一次,替换已满值/重复同值不再触发"(InputOTPRoot.vue:298 prevFilled < length && nextFilled === length);pattern 上游整串校验、Vue 单字符过滤(同名常量 REGEXP_ONLY_* 双方均导出)。
  • [示例] input-otp-controlled:清空按钮文案上游为英文 Clear、Vue 为"清空"(cn/input-otp/controlled.tsx vs input-otp-controlled.vue)。
  • [示例] input-otp-form-example / input-otp-with-validation:上游 Label/Description 在 InputOTP 之外、错误用 <span className="field-error" data-visible id="code-error">(with-validation 另显式 aria-describedby);Vue 将 Label/Description 移入 InputOTP,改用 FieldError + validation-errors 数组,InputOTP 根加内联 style="flex-direction:column;align-items:stretch;gap:0.5rem"、槽位组外包 div.flex items-center gap-2(heroui-vue/apps/docs/demos/input-otp-form-example.vue、input-otp-with-validation.vue)。DOM 结构与布局类不同(视觉目标一致)。form-example 中上游 console.log("Code verified successfully!"),Vue 无对应输出。
  • [文档] ### 变体 一节标题改 ### 尺寸变体 且删去 primary/secondary 的说明文字("primary(默认)- 标准样式带阴影…secondary - 低强调…",上游 input-otp.mdx 44–50 行)。
  • [文档] 全局 CSS 示例缩减:上游展示 .input-otp/.input-otp__slot/[data-active]/.input-otp__separator 四组覆盖,Vue 仅 .hv-input-otp__slot 一组;CSS 类清单/交互状态清单被压缩(Vue 新列 data-complete,未列上游的 .input-otp__container)。

number-field

  • [API] 类型/契约差异(heroui-vue/apps/docs/components/number-field.md vs 上游 number-field.mdx):value: number+onChange(number|undefined) → modelValue: number|null(空值 null);validate 参数 number→number|null、返回 ValidationError|true|null|undefined→string|string[]|true|null|undefined;根 render(DOMRenderFunction)→ as(默认 div);不提供 RAC validationDetails(文档自述)。
  • [API] 上游 NumberField.Input 表列 variant(默认 primary),Vue Input 表无(样式由根 variant 生成)。Vue 文档脚注指出上游该行与其自身实现也不一致(上游文档与其代码不一致,双向已记录)。
  • [实现] Vue 增加(文档"Vue 适配说明"):isWheelDisabled(默认 true,可开滚轮步进)、增减按钮 asChild、指针按住重复步进与释放/移出清理、disabled/readonly/required 原生别名、FormData 提交未格式化数值、locale 继承 ConfigProvider(缺省 en-US)。均为加法或明示差异。
  • [示例] number-field-with-validation:上游校验 value < 0 || value > 100 与 maxValue=1 百分比模型自相矛盾(heroui/apps/docs/src/demos/cn/number-field/with-validation.tsx);Vue 改判 > 1 并注释 0–1 模型,但错误/提示文案仍为"0 到 100 之间"(heroui-vue/apps/docs/demos/number-field-with-validation.vue)。示例行为差异,Vue 文档自述"原演示将模型与 0–100 混用"。
  • [示例] number-field-form-example:上游成功仅 console.log("Order submitted:", …);Vue 显示页内 role="status""模拟提交成功"并加定时器清理;容器 flex w-[280px] flex-col gap-4 → 加 max-w-full(number-field-full-width 同样加 max-w-full)。
  • [示例] number-field-custom-icons / with-chevrons:上游为内联 SVG 路径(heroicons 风格),Vue 为 Tabler 图标(项目约定:示例用 Tabler 官方 Vue 图标)。
  • [文档] 缺 ## 相关案例 <RelatedShowcases component="NumberField" />(Vue 以"相关示例已包含在上方文档预览中"一句替代)。
  • [样式] number-field.css 与 numberFieldVariants 双方逐字一致(含 [data-invalid] 下 description 联动规则)。

本组小结(最严重 5 条)

  1. @heroui-vue/styles 缺 5 个 tv 导出(descriptionVariants/fieldErrorVariants/labelVariants/textFieldVariants/switchGroupVariants),Description/Label/FieldError 改为硬编码类名;视觉无损但对外导入契约缺失。
  2. input-otp 底座替换(input-otp 单隐藏 input → Reka PinInput 多 input)带来 DOM/样式差异(新增 __input 透明覆盖层)与 API 缺口:validationDetails、textAlign、pasteTransformer、autoFocus 未提供且未列入差异表;onComplete/pattern 语义改变。
  3. input-group-with-textarea 的 4 个 Tooltip(含 Enter 快捷键 Kbd 提示)被原生 title 替代、Kbd 提示删除——组内唯一可见交互降级。
  4. fieldset/form/number-field 三处提交反馈由上游 alert()/console 改为页内 role=status 文本(含 JSON 输出与 reset 清除),文档自述但与基线交互不同。
  5. fieldset/form/input-group/number-field 四页均缺上游 ## 相关案例 <RelatedShowcases> 区块;input-group 另缺"用法示例/文本域用法示例"两段代码章节。

备注:图标库差异(@gravity-ui/icons、内联 SVG → Tabler)按项目约定(示例使用 Tabler 官方 Vue 图标)不计为硬差异,仅在 number-field-custom-icons/with-chevrons 处记录事实。