diff --git a/apps/docs/.vitepress/theme/Layout.vue b/apps/docs/.vitepress/theme/Layout.vue index 28f20de..bc6250d 100644 --- a/apps/docs/.vitepress/theme/Layout.vue +++ b/apps/docs/.vitepress/theme/Layout.vue @@ -53,15 +53,20 @@ const groups = [ { title: "Card 卡片", url: "/components/card" }, { title: "Chip 标签", url: "/components/chip" }, { title: "CloseButton 关闭按钮", url: "/components/close-button" }, + { title: "Description 描述", url: "/components/description" }, + { title: "FieldError 字段错误", url: "/components/field-error" }, { title: "Input 输入框", url: "/components/input" }, { title: "InputGroup 输入框组", url: "/components/input-group" }, { title: "Kbd 键盘按键", url: "/components/kbd" }, + { title: "Label 标签", url: "/components/label" }, { title: "Link 链接", url: "/components/link" }, { title: "Separator 分隔符", url: "/components/separator" }, { title: "Skeleton 骨架屏", url: "/components/skeleton" }, { title: "Spinner 加载指示器", url: "/components/spinner" }, { title: "Surface 表面", url: "/components/surface" }, { title: "Switch 开关", url: "/components/switch" }, + { title: "TextArea 多行文本框", url: "/components/textarea" }, + { title: "TextField 文本输入框", url: "/components/text-field" }, ], }, ]; diff --git a/apps/docs/components.md b/apps/docs/components.md index 8d81b81..e82ea3f 100644 --- a/apps/docs/components.md +++ b/apps/docs/components.md @@ -11,12 +11,17 @@ description: 已迁移组件及文档 - [Card 卡片](./components/card) - [Chip 标签](./components/chip) - [CloseButton 关闭按钮](./components/close-button) +- [Description 描述](./components/description) +- [FieldError 字段错误](./components/field-error) - [Input 输入框](./components/input) - [InputGroup 输入框组](./components/input-group) - [Kbd 键盘按键](./components/kbd) +- [Label 标签](./components/label) - [Link 链接](./components/link) - [Separator 分隔符](./components/separator) - [Skeleton 骨架屏](./components/skeleton) - [Spinner 加载指示器](./components/spinner) - [Surface 表面](./components/surface) - [Switch 开关](./components/switch) +- [TextArea 多行文本框](./components/textarea) +- [TextField 文本输入框](./components/text-field) diff --git a/apps/docs/components/description.md b/apps/docs/components/description.md new file mode 100644 index 0000000..b001c6d --- /dev/null +++ b/apps/docs/components/description.md @@ -0,0 +1,112 @@ +--- +title: Description 描述 +description: 为表单字段及其他组件提供补充说明文本 +component: description +group: 组件 +--- + +## 用法 + +```vue + +``` + + + +## 示例 + +### 搭配表单字段 + +```vue + + + + + 密码 + + + 至少 8 个字符,且包含一个大写字母 + + + +``` + +### 与 TextField 配合 + +```vue + + + + + 邮箱 + + 我们不会分享你的邮箱 + + +``` + +使用 [TextField](/components/text-field) 时,`aria-describedby` 会自动合并到控件;支持多个描述与动态 id。 + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +可使用 `@layer components` 指令自定义 Description 组件类。 + +```css +@layer components { + .hv-description { + @apply text-muted; + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +Description 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/description.css)): + +#### 基础类 [!toc] + +- `.hv-description` - 基础描述样式,使用 `muted` 文本颜色 + +## API 参考 + +### Description + +| Prop | 类型 | 默认值 | 描述 | +| -------- | --------------------------- | ------ | --------------------------------- | +| `id` | `string` | 自动 | 显式 id;未指定时生成并与控件关联 | +| 默认插槽 | `Component` | - | 描述内容 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | + +## 无障碍 + +Description 组件通过以下方式增强无障碍性: + +- 使用屏幕阅读器可识别的语义化 HTML(`p`) +- 在 TextField 内自动注册到控件的 `aria-describedby` +- 支持多个描述、外部 `aria-describedby` 合并与卸载清理 + +任意用户 Vue 包装组件不能被 TextField 静态展开做 SSR 预规划;需要首屏 SSR 关联时请显式设置控件 `aria-describedby` 与描述 id。 + +## 相关组件 + +[TextField 文本输入框](./text-field) · [Label 标签](./label) · [FieldError 字段错误](./field-error) diff --git a/apps/docs/components/field-error.md b/apps/docs/components/field-error.md new file mode 100644 index 0000000..d5b5ed9 --- /dev/null +++ b/apps/docs/components/field-error.md @@ -0,0 +1,212 @@ +--- +title: FieldError 字段错误 +description: 展示表单字段校验错误消息 +component: field-error +group: 组件 +--- + +## 用法 + +```vue + +``` + + + +FieldError 组件展示表单字段的校验错误消息。当父字段标记为无效时自动显示,并提供平滑的透明度过渡。 + +## 示例 + +### 基础校验 + +```vue + + + + + 用户名 + + 用户名至少需要 3 个字符 + + +``` + +### 动态错误信息 + +使用 **FieldError** 作用域插槽读取当前字段错误。`is-invalid` 只负责展示;阻止提交请使用 `validate` 或 Form 的 `validation-errors`。下面示例用 `validate` + `validation-behavior="aria"`,输入时即可看到动态消息: + +```vue + + + + + 密码 + + + + {{ validationErrors.join(",") }} + + + + +``` + +上游 `FieldError` 的 render 函数 `(validation) => …` 在 Vue 中为 **FieldError** 的作用域插槽 `#default="{ validationErrors, isInvalid }"`。当前未提供完整 React Aria `validationDetails` 对象。 + +### 自定义校验逻辑 + +```vue + + + + + 邮箱 + + 邮箱必须包含 @ 符号 + + +``` + +也可以用 `validate` 做同步提交拦截: + +```vue + + 邮箱 + + + +``` + +### 多条错误信息 + +默认插槽展示合并后的错误文本;需要逐条渲染时使用 FieldError 作用域插槽。下面示例的 `validate` 会返回多条错误: + +```vue + + + + + 密码 + + + + {{ error }} + + + + +``` + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +可使用 `@layer components` 指令自定义 FieldError 组件类。 + +```css +@layer components { + .hv-field-error { + @apply font-medium text-danger; + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +FieldError 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/field-error.css)): + +#### 基础类 [!toc] + +- `.hv-field-error` - 基础错误样式,danger 色 +- 仅在存在 `data-visible` 属性时显示 +- 长消息自动换行(`wrap-break-word`) + +## API 参考 + +### FieldError + +| Prop | 类型 | 默认值 | 描述 | +| -------- | --------------------------- | ------ | ---------------------------------------------------- | +| `id` | `string` | 自动 | 显式 id;未指定时生成并关联到控件 `aria-describedby` | +| 默认插槽 | `Component` | - | 错误消息;作用域提供 `validationErrors`、`isInvalid` | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | + +字段无效时渲染;默认展示错误数组(空格连接)。在 Switch 等 toggle 字段内也可使用。 + +## 无障碍 + +FieldError 组件通过以下方式确保无障碍性: + +- 使用 `role="alert"` 播报错误 +- 语义化 HTML 支持屏幕阅读器 +- 提供视觉与程序化错误指示(`aria-describedby` 关联) +- 根据校验状态自动管理可见性 + +当前不提供完整 React Aria `validationDetails` 对象;第三方契约请勿据此宣称完全兼容。 + +## 相关组件 + +[TextField 文本输入框](./text-field) · [Label 标签](./label) · [Description 描述](./description) diff --git a/apps/docs/components/label.md b/apps/docs/components/label.md new file mode 100644 index 0000000..ec6da56 --- /dev/null +++ b/apps/docs/components/label.md @@ -0,0 +1,130 @@ +--- +title: Label 标签 +description: 渲染与表单控件关联的无障碍标签。 +component: label +group: 组件 +--- + +## 用法 + +```vue + +``` + + + +## 示例 + +### 带必填指示符 + +```vue + + + + 邮箱地址 + + +``` + +### 禁用状态 + +```vue + + + + 用户名 + + +``` + +### 无效状态 + +```vue + + + + 密码 + + +``` + +在 TextField 内使用时,`is-required` / `is-disabled` / `is-invalid` 会自动继承字段状态,无需重复标注。 + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +若要自定义组件类,可使用 `@layer components` 指令。 + +```css +@layer components { + .hv-label { + @apply font-semibold text-foreground; + } + + .hv-label--required::after { + @apply text-accent; + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +Label 使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/label.css)): + +#### 基础类 [!toc] + +- `.hv-label` — 基础标签文本样式 + +#### 状态修饰类 [!toc] + +- `.hv-label--required` 或 `[data-required="true"] > .hv-label` — 显示必填星号 +- `.hv-label--disabled` 或 `[data-disabled="true"] .hv-label` — 禁用状态样式 +- `.hv-label--invalid` 或 `[data-invalid="true"] .hv-label` — 无效状态样式(危险/红色文本) + +**说明:** 必填星号会基于 role 与 `data-slot` 智能应用,并排除 `role="group"` / `radiogroup` / `checkboxgroup` 以及 `data-slot="radio"` / `checkbox` 的元素,避免分组内重复星号。 + +## API 参考 + +### Label + +| Prop | 类型 | 默认值 | 描述 | +| ------------ | --------------------------- | ------- | ------------------------------------- | +| `for` | `string` | - | 标签所关联元素的 id(Vue 使用 `for`) | +| `isRequired` | `boolean` | `false` | 是否显示必填指示符 | +| `isDisabled` | `boolean` | `false` | 标签是否处于禁用状态 | +| `isInvalid` | `boolean` | `false` | 标签是否处于无效状态 | +| 默认插槽 | `Component` | - | 标签内容 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | + +在 TextField 内且未显式传 `for` 时,自动关联当前控件 id。Switch 等 toggle 字段内渲染为非交互 `span`,避免嵌套交互。 + +## 无障碍 + +Label 基于原生 HTML ``,并遵循 WAI-ARIA 最佳实践: + +- 使用 `for` 与表单控件关联(上游 `htmlFor` 的 Vue 等价) +- 提供语义化的 `` 元素 +- 与表单控件关联时支持键盘导航 +- 向屏幕阅读器传达必填与无效状态 +- 点击标签可聚焦/激活关联的表单控件 + +## 相关组件 + +[TextField 文本输入框](./text-field) · [Description 描述](./description) · [FieldError 字段错误](./field-error) diff --git a/apps/docs/components/text-field.md b/apps/docs/components/text-field.md new file mode 100644 index 0000000..2bc2509 --- /dev/null +++ b/apps/docs/components/text-field.md @@ -0,0 +1,239 @@ +--- +title: TextField 文本输入框 +description: 便于组合的文本字段,包含标签、说明与内联校验。 +component: textfield +group: 组件 +--- + +## 用法 + +```vue + +``` + + + +## 组件结构 + +```vue + + + + + + + + + + +``` + +> **TextField** 将标签、输入、说明与错误信息整合为单个无障碍组件。若只需独立输入,请使用 **[Input](/components/input)** 或 **[TextArea](/components/textarea)**。 + +## 示例 + +### 表面样式 + +在 [Surface](/components/surface) 内使用时,请在 Input 或 TextArea 组件上使用 `variant="secondary"`,以应用适合表面背景的低强调变体。 + + + +### 带描述 + + + +### 必填字段 + + + +### 禁用状态 + + + +### 宽度充满 + + + +### 表单校验 + +将 `is-invalid` 与 `FieldError` 配合使用,以展示校验消息。`is-invalid` 只负责错误展示;阻止提交请使用 `validate` 或 Form 的 `validation-errors`。 + + + +### 受控组件 + +使用 `v-model` 控制值,以同步计数器、预览或格式化逻辑。 + + + +### 错误信息 + + + +### 文本域 + +多行内容请使用 [TextArea](/components/textarea),而非 [Input](/components/input)。 + + + +### Input 类型 + + + +### 渲染函数 + +上游 `render` 自定义根元素;Vue 将 `class`/`data-*` 等透传到 TextField 根节点,暂不支持替换根元素类型。 + + + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +若要自定义组件类,可使用 `@layer components` 指令。 + +```css +@layer components { + .hv-textfield { + @apply flex flex-col gap-1; + } + + /* When invalid, the description is hidden automatically */ + .hv-textfield[data-invalid="true"] [data-slot="description"], + .hv-textfield[aria-invalid="true"] [data-slot="description"] { + @apply hidden; + } + + /* Description has default padding */ + .hv-textfield [data-slot="description"] { + @apply px-1; + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +- `.hv-textfield` – 根容器,样式极少(`flex flex-col gap-1`) + +> **提示:** 子组件([Label](/components/label)、[Input](/components/input)、[TextArea](/components/textarea)、[Description](/components/description)、[FieldError](/components/field-error))各自拥有 CSS 类与样式,定制方式请参见对应文档。 + +### 交互状态 + +TextField 会根据状态自动管理以下 data 属性: + +- **无效**:`[data-invalid="true"]` — 无效时自动隐藏 description 插槽 +- **禁用**:`[data-disabled="true"]` — 在 `is-disabled` 为 true 时应用 +- **必填**:`[data-required="true"]` +- **只读**:`[data-readonly="true"]` + +## API 参考 + +### TextField + +| Prop | 类型 | 默认值 | 描述 | +| ------------------------------------- | -------------------------------------------------------------------- | -------------------------- | -------------------------------------------------- | +| 默认插槽 | `Component` | - | 子组件(Label、Input、Description、FieldError 等) | +| `modelValue` | `string` | - | 当前值(受控;`v-model`) | +| `defaultValue` | `string` | - | 默认值(非受控) | +| `name` | `string` | - | 用于 HTML 表单提交的 input 名称 | +| `id` | `string` | - | 控件 id;子控件显式 id 优先 | +| `type` | `string` | - | 下发到 Input 的 type | +| `isDisabled` | `boolean` | `false` | 是否禁用输入 | +| `isReadOnly` | `boolean` | `false` | 只读 | +| `isRequired` | `boolean` | `false` | 提交表单前是否必须填写 | +| `isInvalid` | `boolean` | - | 错误展示状态;不单独阻止提交 | +| `validate` | `(value: string) => string \| string[] \| true \| null \| undefined` | - | 同步校验函数 | +| `validationBehavior` | `'native' \| 'aria'` | 继承 Form,否则 `'native'` | 原生约束拦截或仅 ARIA 语义 | +| `fullWidth` | `boolean` | `false` | 是否占满容器宽度 | +| `variant` | `'primary' \| 'secondary'` | - | 视觉变体,继承到子控件 | +| `minLength` / `maxLength` / `pattern` | `number` / `number` / `string` | - | 下发到真实文本控件的原生约束 | +| `autoComplete` | `string` | - | 浏览器自动完成提示(下发 `autocomplete`) | +| `inputMode` | `string` | - | 移动键盘类型提示(下发 `inputmode`) | +| `form` | `string` | - | 关联外部 form 的 id(下发到真实控件) | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | + +值使用 `v-model`(`update:modelValue`)。受控值由父级决定,拒绝更新时恢复实际 DOM 值。`name`、原生约束、`autoComplete` / `inputMode` / `form` 与 ARIA 落在真实 `input`/`textarea` 上。服务端/外部错误通过 Form 的 `validation-errors`(按 name 映射)接入,不是 TextField 的 `validationErrors` 数组。 + +### 事件 + +| 事件 | 参数 | 描述 | +| ------------------- | -------- | ---------------------------- | +| `update:modelValue` | `string` | 值变化时发出;配合 `v-model` | + +### 暴露方法 + +通过模板 ref 调用: + +| 名称 | 类型 | 描述 | +| --------- | ------------------------------------------------------ | ------------------------------------------------- | +| `focus` | `() => void` | 聚焦当前文本控件 | +| `element` | `HTMLInputElement \| HTMLTextAreaElement \| undefined` | 底层控件(模板 ref 的公开实例会自动解包内部 Ref) | + +### 组合子组件 + +- **[Label](/components/label)** — 字段标签 +- **[Input](/components/input)** — 单行文本输入 +- **[TextArea](/components/textarea)** — 多行文本输入 +- **[Description](/components/description)** — 辅助说明 +- **[FieldError](/components/field-error)** — 校验错误 + +```vue + + + + + 邮箱地址 + + 我们不会分享你的邮箱。 + 请输入有效的邮箱地址。 + + +``` + +### 作用域插槽状态 + +默认插槽提供以下状态,可用于条件渲染: + +| 参数 | 类型 | 描述 | +| ------------------ | ---------- | ------------ | +| `isDisabled` | `boolean` | 是否禁用 | +| `isReadOnly` | `boolean` | 是否只读 | +| `isRequired` | `boolean` | 是否必填 | +| `isInvalid` | `boolean` | 是否无效 | +| `validationErrors` | `string[]` | 当前错误列表 | + +与上游 `TextFieldRenderProps` 的差异:Vue 使用作用域插槽而非 render prop;无 `isFocusWithin` / `isFocusVisible`(聚焦状态由控件自身管理)。 + +## 相关组件 + +[Input 输入框](./input) · [TextArea 多行文本框](./textarea) · [Label 标签](./label) · [FieldError 字段错误](./field-error) diff --git a/apps/docs/components/textarea.md b/apps/docs/components/textarea.md new file mode 100644 index 0000000..ab56fb2 --- /dev/null +++ b/apps/docs/components/textarea.md @@ -0,0 +1,128 @@ +--- +title: TextArea 多行文本框 +description: 原语级多行文本输入组件,可接受标准 HTML 属性。 +component: textarea +group: 组件 +--- + +## 用法 + +```vue + +``` + + + +> 校验、标签与错误消息请参阅 **[TextField](/components/text-field)**。 + +## 示例 + +### 变体 + +TextArea 组件支持两种视觉变体: + +- **`primary`**(默认)— 带阴影的标准样式,适用于大多数场景 +- **`secondary`** — 低强调、无阴影,适合在 Surface 等表面背景上使用 + + + +### 表面样式 + +在 [Surface](/components/surface) 内使用时,请使用 `variant="secondary"`,以应用适合表面背景的低强调变体。 + + + +### 宽度充满 + + + +### 受控组件 + + + +### 行数与尺寸调整 + + + +## 自定义样式 + +### Tailwind CSS + + + +### 全局 CSS + +若要自定义组件类,可使用 `@layer components` 指令。 + +```css +@layer components { + .hv-textarea { + @apply rounded-xl border border-border bg-surface px-4 py-3 text-sm leading-6 shadow-sm; + + &:hover, + &[data-hovered="true"] { + @apply bg-surface-secondary border-border/80; + } + + &:focus-visible, + &[data-focus-visible="true"] { + @apply border-accent ring-2 ring-accent/20; + } + + &[data-invalid="true"] { + @apply border-danger bg-danger-soft text-danger; + } + } +} +``` + +## 样式参考 + +HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。 + +### CSS 类 + +#### 基础类 [!toc] + +- `.hv-textarea` – 底层 `` 元素样式 + +### 交互状态 + +- **悬停**:`:hover` 或 `[data-hovered="true"]` +- **可见焦点**:`:focus-visible` 或 `[data-focus-visible="true"]` +- **无效**:`[data-invalid="true"]` +- **禁用**:`:disabled` 或 `[aria-disabled="true"]` + +## API 参考 + +### TextArea + +TextArea 接受所有标准 HTML `` 属性,以及以下属性: + +| Prop | 类型 | 默认值 | 描述 | +| -------------- | --------------------------- | ----------- | -------------------------------- | +| `modelValue` | `string` | - | 受控值(`v-model`) | +| `defaultValue` | `string` | - | 非受控初始值 | +| `rows` | `number` | `3` | 可见文本行数 | +| `fullWidth` | `boolean` | `false` | 是否占满容器宽度 | +| `variant` | `'primary' \| 'secondary'` | `'primary'` | 视觉变体 | +| `invalid` | `boolean` | - | 展示无效状态;与父级字段状态合并 | +| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) | + +原生属性(`name`、`placeholder`、`disabled`、`readonly`、`required`、`cols`、`wrap`、`autocomplete`、`minlength`、`maxlength` 等)透传到真实 ``。在 TextField 内时,`name`/禁用/只读/必填/校验/ARIA 由字段上下文统一管理。 + +### 事件与暴露 + +| 接口 | 说明 | +| ------------------- | ---------------------------------------------- | +| `update:modelValue` | 值变化时发出;配合 `v-model` | +| `focus()` | 模板 ref 暴露,聚焦真实 `` | +| `element` | 模板 ref 暴露的底层 `HTMLTextAreaElement` 引用 | + +> 对于 `isInvalid`、`isRequired` 等校验 prop 以及错误处理,请将 TextArea 作为子组件与 **[TextField](/components/text-field)** 一起使用。 + +## 相关组件 + +[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [InputGroup 输入框组](./input-group) diff --git a/apps/docs/demos/description-basic.vue b/apps/docs/demos/description-basic.vue new file mode 100644 index 0000000..42788de --- /dev/null +++ b/apps/docs/demos/description-basic.vue @@ -0,0 +1,19 @@ + + + + + 邮箱 + + + 我们不会将你的邮箱分享给任何人。 + + + diff --git a/apps/docs/demos/description-custom-styles.vue b/apps/docs/demos/description-custom-styles.vue new file mode 100644 index 0000000..f005fad --- /dev/null +++ b/apps/docs/demos/description-custom-styles.vue @@ -0,0 +1,13 @@ + + + + + 工作区 URL + + + 仅支持小写字母和连字符。将用于 app.heroui.com/acme + + + diff --git a/apps/docs/demos/field-error-basic.vue b/apps/docs/demos/field-error-basic.vue new file mode 100644 index 0000000..85504d4 --- /dev/null +++ b/apps/docs/demos/field-error-basic.vue @@ -0,0 +1,17 @@ + + + + + 用户名 + + 用户名至少需要 3 个字符 + + diff --git a/apps/docs/demos/field-error-custom-styles.vue b/apps/docs/demos/field-error-custom-styles.vue new file mode 100644 index 0000000..1443209 --- /dev/null +++ b/apps/docs/demos/field-error-custom-styles.vue @@ -0,0 +1,17 @@ + + + + + 用户名 + + 用户名至少需要 3 个字符 + + diff --git a/apps/docs/demos/label-basic.vue b/apps/docs/demos/label-basic.vue new file mode 100644 index 0000000..454ddfa --- /dev/null +++ b/apps/docs/demos/label-basic.vue @@ -0,0 +1,10 @@ + + + + + 姓名 + + + diff --git a/apps/docs/demos/label-custom-styles.vue b/apps/docs/demos/label-custom-styles.vue new file mode 100644 index 0000000..5744b37 --- /dev/null +++ b/apps/docs/demos/label-custom-styles.vue @@ -0,0 +1,15 @@ + + + + + + 仓库 + + + + diff --git a/apps/docs/demos/text-field-custom-styles.vue b/apps/docs/demos/text-field-custom-styles.vue new file mode 100644 index 0000000..63c1915 --- /dev/null +++ b/apps/docs/demos/text-field-custom-styles.vue @@ -0,0 +1,21 @@ + + + + + + 邮箱 + + + + diff --git a/apps/docs/demos/textarea-basic.vue b/apps/docs/demos/textarea-basic.vue new file mode 100644 index 0000000..1baa7a7 --- /dev/null +++ b/apps/docs/demos/textarea-basic.vue @@ -0,0 +1,11 @@ + + + + + diff --git a/apps/docs/demos/textarea-controlled.vue b/apps/docs/demos/textarea-controlled.vue new file mode 100644 index 0000000..1501afa --- /dev/null +++ b/apps/docs/demos/textarea-controlled.vue @@ -0,0 +1,20 @@ + + + + + + + 字符数: {{ value.length }} / 280 + + + diff --git a/apps/docs/demos/textarea-custom-styles.vue b/apps/docs/demos/textarea-custom-styles.vue new file mode 100644 index 0000000..9f695bd --- /dev/null +++ b/apps/docs/demos/textarea-custom-styles.vue @@ -0,0 +1,17 @@ + + + + + diff --git a/apps/docs/demos/textarea-full-width.vue b/apps/docs/demos/textarea-full-width.vue new file mode 100644 index 0000000..66ebb13 --- /dev/null +++ b/apps/docs/demos/textarea-full-width.vue @@ -0,0 +1,9 @@ + + + + + + + diff --git a/apps/docs/demos/textarea-on-surface.vue b/apps/docs/demos/textarea-on-surface.vue new file mode 100644 index 0000000..9a55fa6 --- /dev/null +++ b/apps/docs/demos/textarea-on-surface.vue @@ -0,0 +1,13 @@ + + + + + + + diff --git a/apps/docs/demos/textarea-rows.vue b/apps/docs/demos/textarea-rows.vue new file mode 100644 index 0000000..58cea6b --- /dev/null +++ b/apps/docs/demos/textarea-rows.vue @@ -0,0 +1,27 @@ + + + + + + 简短反馈 + + + + 详细笔记 + + + + diff --git a/apps/docs/demos/textarea-variants.vue b/apps/docs/demos/textarea-variants.vue new file mode 100644 index 0000000..f154246 --- /dev/null +++ b/apps/docs/demos/textarea-variants.vue @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/apps/docs/demos/textfield-controlled.vue b/apps/docs/demos/textfield-controlled.vue new file mode 100644 index 0000000..7be5a0f --- /dev/null +++ b/apps/docs/demos/textfield-controlled.vue @@ -0,0 +1,28 @@ + + + + + + 显示名称 + + 字符数: {{ name.length }} + + + 个人简介 + + 字符数: {{ bio.length }} / 200 + + + diff --git a/apps/docs/demos/textfield-disabled.vue b/apps/docs/demos/textfield-disabled.vue new file mode 100644 index 0000000..a1deedd --- /dev/null +++ b/apps/docs/demos/textfield-disabled.vue @@ -0,0 +1,16 @@ + + + + + 账户 ID + + 此字段不可编辑 + + diff --git a/apps/docs/demos/textfield-full-width.vue b/apps/docs/demos/textfield-full-width.vue new file mode 100644 index 0000000..6873742 --- /dev/null +++ b/apps/docs/demos/textfield-full-width.vue @@ -0,0 +1,23 @@ + + + + + + 你的姓名 + + + + 密码 + + 密码长度必须超过 8 个字符 + + + diff --git a/apps/docs/demos/textfield-input-types.vue b/apps/docs/demos/textfield-input-types.vue new file mode 100644 index 0000000..5d7c043 --- /dev/null +++ b/apps/docs/demos/textfield-input-types.vue @@ -0,0 +1,32 @@ + + + + + + 密码 + + + + + 年龄 + + + + + 邮箱 + + + + + 网站 + + + + + 电话 + + + + diff --git a/apps/docs/demos/textfield-on-surface.vue b/apps/docs/demos/textfield-on-surface.vue new file mode 100644 index 0000000..3dc23d1 --- /dev/null +++ b/apps/docs/demos/textfield-on-surface.vue @@ -0,0 +1,29 @@ + + + + + + 你的姓名 + + 我们绝不会与他人分享此信息 + + + 邮箱 + + + + 个人简介 + + 至少 4 行 + + + diff --git a/apps/docs/demos/textfield-render-function.vue b/apps/docs/demos/textfield-render-function.vue new file mode 100644 index 0000000..39960b4 --- /dev/null +++ b/apps/docs/demos/textfield-render-function.vue @@ -0,0 +1,16 @@ + + + + + + 邮箱 + + + diff --git a/apps/docs/demos/textfield-required.vue b/apps/docs/demos/textfield-required.vue new file mode 100644 index 0000000..48de961 --- /dev/null +++ b/apps/docs/demos/textfield-required.vue @@ -0,0 +1,11 @@ + + + + + 全名 + + 此字段为必填项 + + diff --git a/apps/docs/demos/textfield-textarea.vue b/apps/docs/demos/textfield-textarea.vue new file mode 100644 index 0000000..4878b24 --- /dev/null +++ b/apps/docs/demos/textfield-textarea.vue @@ -0,0 +1,16 @@ + + + + + 消息 + + 最多 500 个字符 + + diff --git a/apps/docs/demos/textfield-with-error.vue b/apps/docs/demos/textfield-with-error.vue new file mode 100644 index 0000000..b9794e3 --- /dev/null +++ b/apps/docs/demos/textfield-with-error.vue @@ -0,0 +1,11 @@ + + + + + 邮箱 + + 请输入有效的邮箱地址 + + diff --git a/apps/docs/fields.md b/apps/docs/fields.md index d04c2bd..5f42431 100644 --- a/apps/docs/fields.md +++ b/apps/docs/fields.md @@ -57,7 +57,15 @@ Form 的 `validation-errors` 是以字段 name 为键、字符串或字符串数 ## 当前边界 -本页交付共享协议和验证场景,尚未宣称完整迁移 Form、TextField 的所有上游文档。已迁移的三个 TextField 基线示例在此展示,其余示例后续按清单补齐。 +本页交付共享协议和验证场景,是字段/表单基础设施指南,不替代独立组件文档。TextField、Label、Description、FieldError、TextArea 的完整 API 与基线示例见各自组件页: + +- [TextField 文本输入框](/components/text-field) +- [Label 标签](/components/label) +- [Description 描述](/components/description) +- [FieldError 字段错误](/components/field-error) +- [TextArea 多行文本框](/components/textarea) + +已迁移的三个 TextField 基线示例仍在此展示,便于联调验证。 SSR 支持标准的直接子部件、原生元素/Fragment 包裹的 Description/FieldError,即使说明放在控件之后也能生成完整 ID 关联。自定义 Vue 包装组件中的描述在客户端注册;若首屏 SSR 必须关联,请显式提供控件 aria-describedby 和对应描述 id。Nuxt 完整消费验收尚未进行。 diff --git a/docs/compatibility.md b/docs/compatibility.md index 9c069b5..0187c3b 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -55,14 +55,14 @@ | tooltip | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | | input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 | | input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 | -| textarea | 验证中(字段接入) | 接入 TextField 与共享 useTextControl;独立文档/全部示例仍待补齐 | -| textfield | 验证中(基础设施) | 一个文本控件;值/状态/约束/校验/ID;3 个基线示例;完整文档与其余示例待补齐 | +| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl | +| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) | | search-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | | typography | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| label | 验证中(通用字段) | 文本字段自动 for,Switch 内 span;继承 required/disabled/invalid;完整独立文档待补齐 | -| description | 验证中(通用字段) | 通用字段描述注册与动态 ID 清理;外部 describedby 合并;SSR 包装限制见基础协议 | +| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 | +| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 | | empty-state | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | -| field-error | 验证中(通用字段) | 通用 FieldContext;TextField 与 Switch 错误/动态 ID;validationDetails 等差异见基础协议 | +| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) | | fieldset | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | | form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 | | header | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 | @@ -100,7 +100,7 @@ React Aria 专属 rac 导出与 React 图标类型不移植;Vue 版 ConfigProv ## 已实现组件的文档清单复核 -Button 14 / 14,Card 7 / 7,Input 7 / 7,Switch 15 / 15,Surface 4 / 4,Link 6 / 6,Spinner 5 / 5,CloseButton 4 / 4,Avatar 7 / 7,AvatarGroup 7 / 7,Skeleton 8 / 8,Separator 7 / 7,Kbd 7 / 7,Chip 5 / 5,Badge 8 / 8,Alert 2 / 2,InputGroup 21 / 21,基线预览名称与顺序均已对齐。没有用空壳补足数量;预览与复制代码共用 SFC。 +Button 14 / 14,Card 7 / 7,Input 7 / 7,Switch 15 / 15,Surface 4 / 4,Link 6 / 6,Spinner 5 / 5,CloseButton 4 / 4,Avatar 7 / 7,AvatarGroup 7 / 7,Skeleton 8 / 8,Separator 7 / 7,Kbd 7 / 7,Chip 5 / 5,Badge 8 / 8,Alert 2 / 2,InputGroup 21 / 21,TextField 13 / 13,Label 2 / 2,Description 2 / 2,FieldError 2 / 2,TextArea 7 / 7,基线预览名称与顺序均已对齐。没有用空壳补足数量;预览与复制代码共用 SFC。 Card 图片、头像、横向布局、表单与自定义样式已补齐;Input 的标签、类型、宽度与自定义样式已对齐。Switch 补齐图标、位置、分组、表单、状态插槽与自定义根容器。Surface 覆盖变体与表单组合;Link 覆盖图标位置、文本装饰、自定义图标、asChild 与自定义样式;Spinner 覆盖颜色、尺寸、速度与自定义样式。CloseButton 覆盖默认、交互、自定义图标与自定义样式。Avatar 覆盖基本、尺寸、颜色、变体、回退、自定义图片组件与自定义样式;AvatarGroup 覆盖基本、max、自定义计数、尺寸、网格、叠放样式与自定义样式;Skeleton 覆盖文本、用户资料、列表、网格、单次闪烁、动画类型与自定义样式。Separator 覆盖基本、变体、Surface 组合、垂直、带内容布局、asChild 自定义根与自定义样式;Kbd 覆盖基本、变体、导航键、行内、说明文字、特殊键与自定义样式;Chip 覆盖基本、变体矩阵、状态图标、带图标与自定义样式。Badge 覆盖基本、变体、尺寸、颜色、四角位置、点状、带内容与自定义样式;Alert 覆盖六种组合的基本示例与自定义样式。 @@ -153,3 +153,11 @@ Card 图片、头像、横向布局、表单与自定义样式已补齐;Input - 显式 `variant` 优先于 TextField 继承;fullWidth/role 可配置。点击组合空白聚焦真实 input/textarea(按钮等可交互子元素除外)。 - Prefix/Suffix 为展示容器,不进入 FormData;嵌入 Button 默认 `type="button"`。 - 与上游差异:`with-textarea` 的 Tooltip 以原生 `title`/`aria-label` 适配(Tooltip 未迁移);React `render`/`className`/`children` 改为 Vue 插槽与 `class`。 + +## M13–M14 说明 + +- TextField / Label / Description / FieldError / TextArea 均有独立中文文档页;`/fields` 保留为基础设施指南并链接到组件页。 +- TextField 13 例含 on-surface、required、disabled、full-width、controlled、with-error、textarea、input-types、render-function、custom-styles;复用已有 basic / with-description / validation。 +- Label/Description/FieldError 正文中的必填/禁用/无效、表单组合、动态/多条错误示例已改为可运行 Vue 写法(v-model、作用域插槽)。 +- TextArea:补 `rows` 默认 3;7 例齐全。值/reset/ARIA 仍由 useTextControl 管理。 +- 差异:TextField `render` 不支持替换根元素类型(data-* 透传);FieldError 无 validationDetails,动态错误用作用域插槽。 diff --git a/docs/migrations/M13-M14-review.md b/docs/migrations/M13-M14-review.md new file mode 100644 index 0000000..06164d8 --- /dev/null +++ b/docs/migrations/M13-M14-review.md @@ -0,0 +1,47 @@ +# M13–M14 独立复核 + +日期:2026-10-21。起点 `37e11e6`。首轮结论:**待修正,未提交**。以下发现保留为历史,最终结论见文末。 + +## P2:FieldError 两个正文示例既不能独立编译,也没有错误数据来源 + +位置:`apps/docs/components/field-error.md:48–64`(动态错误信息)、`108–124`(多条错误信息)。 + +两段完整 SFC 的 script 只有组件导入,但模板引用 `hasErrors`。把正文完整 SFC 提取为临时 Vue 文件,运行 `pnpm typecheck`,两处均报 TS2339:`hasErrors` 不存在。 + +此外,单纯添加 `const hasErrors = ref(true)` 不能修好演示。`isInvalid` 只改变错误展示状态,不会向 `validationErrors` 填入任何文本;当前既没有 validate 也没有 Form.validationErrors 数据源,所以动态 join 和多条 v-for 都没有内容。前一个示例还把作用域挂在 TextField,后文却说明 FieldError 的作用域插槽,需统一实际演示对象。 + +修正要求:给两例完整、明确的错误源,例如 Form 的按 name 映射错误,或带 v-model / validate / validationBehavior 的可操作字段。动态例实际使用 FieldError 作用域插槽;多条例实际产生至少两条错误。完整 SFC 能复制编译,交互或初始状态确实显示预期消息。补充正文代码块编译检查和消息内容行为验证,不能只断言 Markdown 包含 validationErrors 字符串。 + +## P2:TextField API 表未完整描述已实现的公共属性 + +位置:`apps/docs/components/text-field.md` API 参考(约 148–170 行)。 + +当前 TextField.vue 已明确声明 `autoComplete`、`inputMode`、`form`,并通过字段上下文下发到实际输入控件,但新独立页未列出这三项,也没有指向完整契约。它们直接影响自动完成、移动键盘与外部表单归属,不能在“字段文档补齐”时静默省略。 + +修正要求:逐项核对 TextField 当前全部公开 props、update:modelValue 事件、focus/element 暴露接口、作用域插槽和属性落点;补齐缺失项和适用默认值。TextArea 页也明确说明 focus/element 与值更新事件,原生属性可以有清楚的统一说明,无需重复制造别名。使用最小消费用例确认表中接口真实生效。 + +## 已通过的独立检查与边界 + +- `pnpm test`:13 文件 / 201 项(含 node SSR 3 项)。 +- `pnpm test:unit`:12 文件 / 198 项(不含 node SSR)。 +- 常规 `pnpm typecheck`、`pnpm build:docs`、`pnpm format` 通过;这不覆盖 Markdown 正文 SFC 的变量与行为。 +- 额外正文 SFC 类型探针失败,见第一项;临时文件已移除,不混入交付。 +- TextArea 改动限于 rows 的显式类型、默认值和 DOM 绑定,未复制或改动共享字段协议;默认 3 依据上游 API 表,未独立验证 React Aria 运行时默认值。 +- TextField 13、Label/Description/FieldError 各 2、TextArea 7 个预览均存在。抽查受控、行数、自定义样式与上游源码;render-function 例的实际上游根也是 div + data-custom,本例通过根属性透传保留效果,根元素替换能力仍明确未支持。 +- 未重新逐页操作浏览器,不把实施者浏览器记录算作独立复测;未做逐像素、Nuxt、RTL、读屏或独立安装。 + +## 最短返工范围 + +优先修正文档/API、必要的示例与验证,不动 shared field/TextField/Form/Switch/InputGroup 核心。同步实施者报告、兼容矩阵中“可运行 Vue 示例”等结论,以实际结果为准。完成后交回复核,不自行提交或改写本报告结论为验收通过。 + +## 返工后独立复核(2026-10-21) + +结论:**上述两项已修正,通过本批复核,可以提交。** + +- FieldError 两个完整正文示例均以 v-model + 同步 validate + aria 模式提供真实错误,并使用 FieldError 作用域插槽。 +- 独立提取五个文档页中包含 script 和 template 的完整 Vue 代码块,由 vue-tsc 实际检查,通过;另将 Markdown 原文中的动态/多条错误 SFC 直接导入 Vitest(不是手写一份副本),输入 abc 显示预期的一条/两条错误,合法输入后错误消失,两项通过。临时探针已删除。 +- TextField autoComplete/inputMode/form、值更新事件、focus/element 和 TextArea 的事件/暴露说明补齐。集成人校正 element 在公开组件实例中自动解包的类型说明,并去掉暴露测试中会掩盖失败的 DOM 回退,直接断言真实元素与实际焦点。 +- 既有正文绑定检查是正则静态检查,集成人更正其测试名称,避免将它描述为完整编译器;本次真正的正文类型/行为检查单独记录在上文。 +- dist TextAreaProps 探针经 vue-tsc 验证:rows 数字可用、字符串被拒绝;临时探针已移除。 +- 最终 pnpm test:13 文件 / 208 项(含 node SSR 3 项);pnpm test:unit:12 文件 / 205 项(不含 node SSR)。pnpm typecheck、pnpm build:docs、pnpm format、git diff --check 通过。 +- 本轮没有重跑逐页浏览器或视觉对比,不扩大原有浏览器自测、SSR、主题与独立安装的验收范围。完整基建与根元素替换差异仍按既有协议记录。 diff --git a/docs/migrations/M13-field-docs.md b/docs/migrations/M13-field-docs.md new file mode 100644 index 0000000..dc0fd05 --- /dev/null +++ b/docs/migrations/M13-field-docs.md @@ -0,0 +1,105 @@ +# M13 字段文档交接报告 + +实施日期:2026-10-21。状态:实施者自测完成,待集成人复核。**未提交、未推送。** + +## 1. 起点与范围 + +| 项 | 值 | +| --------- | ---------------------------------------------------------------------------------------- | +| 起始 HEAD | `37e11e6`(feat: add InputGroup and verify shared field integration) | +| 工作区 | 干净;未改 field/useFieldPart/useTextControl/TextField/Form guard/Switch/InputGroup 核心 | +| 上游 | HeroUI 3.2.6 / `ce90ea3`(`../heroui` 只读) | +| 范围 | TextField、Label、Description、FieldError 四个独立中文文档页及全部基线内容 | + +## 2. 交付 + +### 文档页(新建) + +- `apps/docs/components/text-field.md`(13 预览) +- `apps/docs/components/label.md`(2 预览) +- `apps/docs/components/description.md`(2 预览) +- `apps/docs/components/field-error.md`(2 预览) + +### 演示(新建 16;复用 3) + +复用:`textfield-basic` / `textfield-with-description` / `textfield-validation`(FORM-01 已有)。 + +新建 TextField 10:on-surface、required、disabled、full-width、controlled、with-error、textarea、input-types、render-function、text-field-custom-styles。 + +新建 Label 2、Description 2、FieldError 2。 + +### 其他 + +- 导航与 `components.md` 增加四页;`fields.md` 保留基础设施用途并链接组件页。 +- `tests/field-docs-textarea.test.ts`(与 M14 共用,见 M14 报告)。 + +## 3. 上游来源 + +| 路径 | 用途 | +| --------------------------------------------------------------------------- | ---------------------------------------- | +| `.../(forms)/{text-field,label,description,field-error}.mdx` | 标题、结构、示例次序、正文代码、API 叙述 | +| `apps/docs/src/demos/cn/{textfield,label,description,field-error}/` | 16 个新演示的文案与布局 | +| `packages/react/src/components/{textfield,label,description,field-error}/*` | API 语义对照 | +| `packages/styles/components/{textfield,label,description,field-error}.css` | 样式类说明(hv- 已存在) | + +## 4. 示例与正文对照 + +- TextField 13/13:名称与 CN 文档顺序一致;custom-styles 预览名保持上游 `text-field-custom-styles`。 +- Label/Description/FieldError 各 2/2。 +- 正文代码示例已改为 Vue:Label 必填/禁用/无效;Description 搭配表单与 TextField;FieldError 基础校验、动态错误(作用域插槽)、自定义校验(含 validate)、多条错误(v-for)。 + +## 5. API 差异(Vue 契约) + +| 上游 | Vue | +| ---------------------------------- | ------------------------------------------------------------------------------------------------------- | +| `htmlFor` | `for` | +| `value`/`onChange` | `v-model` / `update:modelValue` | +| `className`/`children` | `class` / 默认插槽 | +| `render` 自定义根 | 未支持元素类型替换;`data-*` 透传到根(render-function 示例已注明) | +| FieldError render `(validation)=>` | 作用域插槽 `validationErrors` / `isInvalid` | +| `validationErrors` 数组 prop | Form `validation-errors`(按 name 映射) | +| TextFieldRenderProps | 作用域插槽 isDisabled/isReadOnly/isRequired/isInvalid/validationErrors;无 isFocusWithin/isFocusVisible | + +不提供完整 `validationDetails`;文档已注明。 + +## 6. 回归与命令 + +| 要求 | 结果 | +| --------------------------------- | --------------------------- | +| 文档契约(无 className/children) | 测试通过 | +| 预览清单 13+2+2+2 | 测试通过 | +| 三份既有示例与 /fields 保留 | 测试通过 | +| Label/Description/FieldError 关联 | field-foundation + 本批测试 | + +`pnpm test` 13 文件 / **201**(含 SSR 3);`pnpm test:unit` 12 文件 / **198**(不含 SSR);typecheck / build:docs / format 通过。 + +## 7. 浏览器证据 + +`http://127.0.0.1:5173`:text-field 22 字段 / data-custom 1;field-error 输入 "ab" 显示错误;四页 API 表桌面与 390 窄屏均无溢出。 + +## 8. 未验证 + +浅/深切换交互、位图、Nuxt、RTL、读屏、独立安装、逐像素。 + +## 9. 最短复核步骤 + +1. `pnpm test && pnpm typecheck && pnpm build:docs` +2. 打开 `/components/text-field` 数预览 13;核对 render 示例注释。 +3. `/components/label`、`description`、`field-error`:对照正文代码是否 Vue 且可运行。 +4. `/fields` 仍为指南页并链接四个组件页。 + +## 10. 需集成人确认 + +- TextField 根元素类型自定义(render/asChild)是否列入后续协议扩展。 +- custom-styles 预览名 `text-field-custom-styles` 与 `textfield-*` 前缀不一致(对齐上游命名)。 + +实施者不宣布验收通过。 + +## 11. 复核返工记录(实施者,2026-10-21) + +独立复核两项 P2 已修: + +1. FieldError「动态错误信息」「多条错误信息」正文示例:补 `password` + `validatePassword` 真实错误源,使用 FieldError 作用域插槽与 `validation-behavior="aria"`;多条示例返回两条错误并 v-for 渲染。完整 SFC 可编译,输入 `abc` 显示预期消息。 +2. TextField API 表补齐 `autoComplete`、`inputMode`、`form`,以及 `update:modelValue` 事件与 `focus`/`element` 暴露;TextArea 页补事件与暴露说明。 + +回归新增:正文 SFC 脚本绑定检查、动态/多条错误消息行为、API 表关键字、`autoComplete`/`inputMode`/`form` 下发到真实控件、focus/element 暴露。`pnpm test` **208**(+7)、typecheck、format 通过。未改共享 field/TextField/Form 核心。 diff --git a/docs/migrations/M14-textarea.md b/docs/migrations/M14-textarea.md new file mode 100644 index 0000000..973f451 --- /dev/null +++ b/docs/migrations/M14-textarea.md @@ -0,0 +1,80 @@ +# M14 TextArea 交接报告 + +实施日期:2026-10-21。状态:实施者自测完成,待集成人复核。**未提交、未推送。** + +## 1. 起点与范围 + +| 项 | 值 | +| --------- | ---------------------------------------------------------------------------------------------------------------- | +| 起始 HEAD | `37e11e6`;与 M13 同一 checkout、同一交付批次 | +| 边界 | 可改 TextArea 局部封装/CSS/变体;不复制 useTextControl;不改 TextField/Form/Switch/InputGroup 核心 | +| 上游 | `text-area.mdx`、`packages/react/src/components/textarea`、`demos/cn/textarea`、`styles/components/textarea.css` | + +## 2. 能力核对与局部缺口 + +| 能力 | 状态 | +| ------------------------------------ | --------------------------------------------------- | +| 值 v-model / default-value | 已有(useTextControl) | +| FormData / reset / 取消 reset | 已有 | +| 受控拒绝恢复 DOM | 已有 | +| disabled / readonly / required | 已有 | +| variant primary/secondary、fullWidth | 已有 | +| rows | **本批补**:显式 `rows` prop,默认 3(上游 API 表) | +| cols/wrap/autocomplete/maxlength 等 | attrs 透传 | +| Label/Description/FieldError 关联 | 已有 | +| InputGroup 相邻回归 | 本批测试覆盖 | + +未改 useTextControl;无第二份值/错误状态。 + +## 3. 交付 + +- `apps/docs/components/textarea.md`(7 预览,Vue API 表) +- 演示 7:basic、variants、on-surface、full-width、controlled、rows、textarea-custom-styles(对应上游 `text-area-custom-styles` 预览名) +- `TextArea.vue`:`rows?: number` 默认 3 +- 测试(与 M13 共用 `tests/field-docs-textarea.test.ts`):rows 默认与显式、FormData/disabled/readonly/reset/取消 reset、受控拒绝、字段关联、InputGroup 回归、类型约束 + +## 4. 示例对照(7/7) + +| 预览 | 上游文件 | 内容 | +| ---------------------- | ----------------- | ---------------------------- | +| textarea-basic | basic.tsx | aria-label + h-32 w-96 | +| textarea-variants | variants.tsx | primary/secondary fullWidth | +| textarea-on-surface | on-surface.tsx | Surface + secondary | +| textarea-full-width | full-width.tsx | 全宽 | +| textarea-controlled | controlled.tsx | v-model + 字符数 Description | +| textarea-rows | rows.tsx | rows 3/6 + Label | +| textarea-custom-styles | custom-styles.tsx | 自定义圆角/阴影 | + +## 5. API 差异 + +- `value`/`onChange` → `v-model`;`className` → `class`(string|array|object)。 +- `rows` 默认 3 与上游一致;校验类 prop 仍通过 TextField。 + +## 6. 命令 + +与 M13 同次执行:`pnpm test` 13 文件 / **201**(SSR 3);`pnpm test:unit` 12 文件 / **198**;typecheck / build:docs / format 通过。 + +## 7. 浏览器 + +`/components/textarea`:9 个 textarea(含演示外页面代码),rows=3 与 rows=6 生效;表格无溢出;390 窄屏正常。 + +## 8. 未验证 + +浅/深切换交互、位图、Nuxt、RTL、读屏、独立安装、resize 手感(仅样式属性)。 + +## 9. 最短复核步骤 + +1. `pnpm exec vitest run tests/field-docs-textarea.test.ts` +2. `/components/textarea`:变体、全宽、受控计数、行数 3/6。 +3. 在 `/components/text-field` 的 textarea 示例与 InputGroup with-textarea 回归。 + +## 10. 需集成人确认 + +- `rows` 默认 3 是否需要与 Input 默认高度策略统一文档说明。 +- 自定义样式预览名 `textarea-custom-styles` 对应上游 `text-area-custom-styles`。 + +实施者不宣布验收通过。 + +## 11. 复核返工(2026-10-21) + +按 M13–M14 复核报告,在 TextArea 文档补充 `update:modelValue`、`focus()`、`element` 暴露说明;行为测试覆盖 focus/element 与 autoComplete 等字段下发。`pnpm test` 208 项通过。 diff --git a/docs/upstream.md b/docs/upstream.md index fe77568..2e05db4 100644 --- a/docs/upstream.md +++ b/docs/upstream.md @@ -53,3 +53,5 @@ - Form/字段验证页的 `form-foundation.vue` 为本库基础设施回归场景,未冒充上游完整 Form 示例。 - 原 Switch 专属 FieldError 移到通用 field 目录;复用 fieldContextKey,而非复制一套说明/错误基础组件。具体差异与 SSR 包装边界见 decisions/field-form-foundation.md。 - InputGroup 演示图标由 `@gravity-ui/icons` 替换为 Tabler(IconMail/IconWorld/IconCopy/IconEye/IconEyeOff/IconAt/IconPlus/IconPlugConnected/IconMicrophone/IconArrowUp);with-textarea 的 Tooltip 以原生 title/aria-label 适配。 +- M13–M14:`apps/docs/content/docs/cn/react/components/(forms)/{text-field,label,description,field-error,text-area}.mdx` 与 `apps/docs/src/demos/cn/{textfield,textarea,label,description,field-error}/` 的文档结构、正文代码示例与 26 个文档引用预览(TextField 13 + Label 2 + Description 2 + FieldError 2 + TextArea 7)。 +- TextArea `rows` 默认值 3 来自上游 API 表;CSS/变体此前已移植为 hv- 命名空间。 diff --git a/docs/verification.md b/docs/verification.md index 346bddc..5753720 100644 --- a/docs/verification.md +++ b/docs/verification.md @@ -229,3 +229,38 @@ 独立复核见 [M12-review.md](./migrations/M12-review.md)。修复 InputGroup 内显式控件 ID 的 SSR Label 关联,补充受控拒绝、取消 reset、native/aria、实际水合与动态插槽回归。多行演示清理定时器,校正文档继承语义与静态复制按钮说明。 最终 `pnpm test` 12 文件 / 189 项(含 node SSR 3 项);`pnpm test:unit` 11 文件 / 186 项(不含 node SSR)。`pnpm typecheck`、`pnpm build:docs`、`pnpm format`、`git diff --check` 通过。CSS 规范化后与固定基线一致。本次未重新逐页浏览器检查;实施者浏览器自测记录不能算作集成人复测。逐像素、读屏、RTL、Nuxt、独立安装仍未验证。 + +## M13–M14 字段文档与 TextArea(2026-10-21) + +起始 HEAD `37e11e6`(M12 InputGroup 及集成人修正已合入),工作区干净。未改 field/context.ts、useFieldPart.ts、useTextControl.ts、TextField.vue、Form guard、Switch、InputGroup 核心。 + +### 命令(分别记录) + +| 入口 | 文件数 | 通过数 | 含 SSR | +| ----------------- | ------ | ------ | ------------------- | +| `pnpm test` | 13 | 201 | 是(ssr.test.ts 3) | +| `pnpm test:unit` | 12 | 198 | 否 | +| `pnpm typecheck` | — | 通过 | — | +| `pnpm build:docs` | — | 通过 | — | +| `pnpm format` | — | 通过 | — | + +### 浏览器(Playwright CLI,127.0.0.1:5173) + +- `/components/text-field`:22 个 TextField、22 Label、10 Description、2 FieldError;render 示例 `data-custom=foo`;API 表 17 行无溢出。 +- `/components/label`、`/components/description`、`/components/field-error`:预览与表格正常;field-error 输入 "ab" 显示错误文案与 data-invalid。 +- `/components/textarea`:9 个 textarea,rows=3 与 rows=6 均生效。 +- 窄屏 390:表格宽 350,无水平溢出。 + +### 未验证 + +浅/深切换交互、位图截图、Nuxt 水合、RTL、读屏、触屏、独立安装、自动视觉对比。 + +## M13–M14 文档返工(2026-10-21) + +独立复核 2 项 P2:FieldError 正文两例缺错误数据源/未定义 `hasErrors`;TextField API 缺 autoComplete/inputMode/form 与事件/暴露。已改为带 `validate` 的完整 Vue 示例并补 API;新增正文 SFC 绑定检查与消息行为测试。`pnpm test` 208(13 文件,SSR 3)、typecheck、format 通过。详见 `docs/migrations/M13-M14-review.md`。 + +## M13–M14 返工后集成人复核(2026-10-21) + +结论见 [独立报告](./migrations/M13-M14-review.md#返工后独立复核2026-10-21):FieldError 正文完整 SFC 经独立提取、vue-tsc 检查及原文动态/多条错误运行检查通过,TextField/ TextArea 公共接口文档补齐。公开 element 直接断言真实 DOM,focus 确认实际焦点。 + +最终 pnpm test 为 13 文件 / 208 项(含 node SSR 3 项);pnpm test:unit 为 12 文件 / 205 项(不含 node SSR)。pnpm typecheck、pnpm build:docs、pnpm format、git diff --check 通过。另有临时正文原文行为探针 2 项通过、dist 类型探针通过,探针验证后删除,不计入最终套件数量。未重新逐页浏览器检查,未新增逐像素、Nuxt、RTL、读屏或独立安装验收。 diff --git a/package.json b/package.json index a970f0d..387bf23 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build", "typecheck": "vue-tsc --noEmit", "test": "vitest run", - "test:unit": "vitest run 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-foundation.test.ts", + "test:unit": "vitest run 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", "test:ssr": "vitest run tests/ssr.test.ts", "format": "prettier --check .", "format:fix": "prettier --write .", diff --git a/packages/vue/src/components/textarea/TextArea.vue b/packages/vue/src/components/textarea/TextArea.vue index b9ac755..74afd31 100644 --- a/packages/vue/src/components/textarea/TextArea.vue +++ b/packages/vue/src/components/textarea/TextArea.vue @@ -3,13 +3,17 @@ import { useAttrs } from "vue"; import { textAreaVariants, type TextAreaVariants } from "@heroui-vue/styles"; import { useTextControl } from "../field/useTextControl"; defineOptions({ inheritAttrs: false }); -const props = defineProps<{ - modelValue?: string; - defaultValue?: string; - invalid?: boolean; - variant?: TextAreaVariants["variant"]; - fullWidth?: boolean; -}>(); +const props = withDefaults( + defineProps<{ + modelValue?: string; + defaultValue?: string; + invalid?: boolean; + variant?: TextAreaVariants["variant"]; + fullWidth?: boolean; + rows?: number; + }>(), + { rows: 3 }, +); const emit = defineEmits<{ "update:modelValue": [value: string] }>(); const attrs = useAttrs(); const control = useTextControl(props, attrs, emit); @@ -23,6 +27,7 @@ defineExpose({ focus: () => element.value?.focus(), element }); :value="value" :id="control.id()" :name="control.name()" + :rows="rows" :disabled="control.disabled()" :readonly="control.readOnly()" :required="control.required()" diff --git a/tests/field-docs-textarea.test.ts b/tests/field-docs-textarea.test.ts new file mode 100644 index 0000000..e6f7e49 --- /dev/null +++ b/tests/field-docs-textarea.test.ts @@ -0,0 +1,534 @@ +import { describe, it, expect, afterEach, vi } from "vitest"; +import { mount } from "@vue/test-utils"; +import { defineComponent, h, nextTick, ref } from "vue"; +import { readFileSync } from "node:fs"; +import { + Description, + FieldError, + Form, + Input, + InputGroup, + InputGroupInput, + Label, + TextArea, + TextField, +} from "../packages/vue/src"; + +afterEach(() => { + document.body.innerHTML = ""; +}); + +const settle = async () => { + await nextTick(); + await nextTick(); +}; + +describe("TextArea", () => { + it("renders native textarea with default rows and variant classes", () => { + const w = mount(TextArea, { + props: { rows: 5, variant: "secondary", fullWidth: true }, + }); + const el = w.get("[data-slot=textarea]"); + expect(el.element.tagName).toBe("TEXTAREA"); + expect((el.element as HTMLTextAreaElement).rows).toBe(5); + expect(el.classes()).toContain("hv-textarea"); + expect(el.classes()).toContain("hv-textarea--secondary"); + expect(el.classes()).toContain("hv-textarea--full-width"); + }); + + it("defaults rows to 3", () => { + const w = mount(TextArea); + expect((w.get("textarea").element as HTMLTextAreaElement).rows).toBe(3); + }); + + it("submits FormData, respects disabled/readonly and resets uncontrolled values", async () => { + const w = mount( + defineComponent({ + render: () => + h(Form, {}, () => [ + h(TextField, { name: "bio", defaultValue: "start" }, () => [ + h(TextArea), + ]), + h( + TextField, + { name: "off", defaultValue: "no", isDisabled: true }, + () => [h(TextArea)], + ), + h( + TextField, + { name: "ro", defaultValue: "yes", isReadOnly: true }, + () => [h(TextArea)], + ), + ]), + }), + { attachTo: document.body }, + ); + const areas = w.findAll("textarea"); + await areas[0].setValue("changed"); + expect( + Object.fromEntries( + new FormData(w.get("form").element as HTMLFormElement), + ), + ).toEqual({ bio: "changed", ro: "yes" }); + (w.get("form").element as HTMLFormElement).reset(); + await settle(); + expect((areas[0].element as HTMLTextAreaElement).value).toBe("start"); + w.unmount(); + }); + + it("restores DOM value when the parent rejects updates", async () => { + const value = ref("fixed"); + const w = mount( + defineComponent({ + components: { TextField, TextArea }, + setup: () => ({ value }), + template: ``, + }), + { attachTo: document.body }, + ); + const area = w.get("textarea"); + await area.setValue("typing"); + await settle(); + expect((area.element as HTMLTextAreaElement).value).toBe("fixed"); + w.unmount(); + }); + + it("respects canceled form reset", async () => { + const w = mount( + defineComponent({ + render: () => + h(Form, {}, () => [ + h(TextField, { name: "t", defaultValue: "init" }, () => [ + h(TextArea), + ]), + ]), + }), + { attachTo: document.body }, + ); + const area = w.get("textarea"); + await area.setValue("edited"); + const form = w.get("form").element as HTMLFormElement; + form.addEventListener("reset", (e) => e.preventDefault()); + form.reset(); + await settle(); + expect((area.element as HTMLTextAreaElement).value).toBe("edited"); + w.unmount(); + }); + + it("associates Label, Description and FieldError through TextField", async () => { + const w = mount( + defineComponent({ + render: () => + h(TextField, { isInvalid: true, name: "x" }, () => [ + h(Label, {}, () => "Bio"), + h(TextArea, { rows: 2 }), + h(Description, {}, () => "hint"), + h(FieldError), + ]), + }), + { attachTo: document.body }, + ); + await settle(); + const area = w.get("textarea"); + const label = w.get("label"); + expect(label.attributes("for")).toBe(area.attributes("id")); + const described = area.attributes("aria-describedby")!.split(" "); + expect(described.length).toBeGreaterThanOrEqual(2); + for (const id of described) { + expect(w.find(`[id="${id}"]`).exists()).toBe(true); + } + expect(w.find("[data-slot=field-error]").exists()).toBe(true); + w.unmount(); + }); + + it("keeps InputGroup integration working next to TextArea", async () => { + const w = mount( + defineComponent({ + render: () => + h(Form, {}, () => [ + h(TextField, { name: "email", defaultValue: "a@b.c" }, () => [ + h(InputGroup, {}, () => [h(InputGroupInput)]), + ]), + h(TextField, { name: "note", defaultValue: "hi" }, () => [ + h(TextArea, { rows: 2 }), + ]), + ]), + }), + { attachTo: document.body }, + ); + expect( + Object.fromEntries( + new FormData(w.get("form").element as HTMLFormElement), + ), + ).toEqual({ email: "a@b.c", note: "hi" }); + w.unmount(); + }); + + it("keeps public prop types constrained", async () => { + const { TextArea: Area } = await import("../packages/vue/src"); + // @ts-expect-error rows must be a number + const badRows: InstanceType["$props"]["rows"] = "3"; + // @ts-expect-error variant must be primary | secondary + const badVariant: InstanceType["$props"]["variant"] = "ghost"; + void badRows; + void badVariant; + const ok: InstanceType["$props"] = { + rows: 6, + variant: "secondary", + fullWidth: true, + modelValue: "x", + }; + expect(ok.rows).toBe(6); + }); +}); + +describe("M13 field docs demos", () => { + const expected: Record = { + textfield: [ + "basic", + "on-surface", + "with-description", + "required", + "disabled", + "full-width", + "validation", + "controlled", + "with-error", + "textarea", + "input-types", + "render-function", + "text-field-custom-styles", + ], + label: ["basic", "custom-styles"], + description: ["basic", "custom-styles"], + "field-error": ["basic", "custom-styles"], + textarea: [ + "basic", + "variants", + "on-surface", + "full-width", + "controlled", + "rows", + "custom-styles", + ], + }; + + const docFiles: Record = { + textfield: "text-field", + label: "label", + description: "description", + "field-error": "field-error", + textarea: "textarea", + }; + + it("includes every preview from the pinned upstream documents", () => { + for (const [key, names] of Object.entries(expected)) { + const docName = docFiles[key]; + const document = readFileSync( + `apps/docs/components/${docName}.md`, + "utf8", + ); + const previewNames = [ + ...document.matchAll(/ m[1]); + const ids = + key === "textfield" + ? names.map((n) => + n === "text-field-custom-styles" ? n : `textfield-${n}`, + ) + : names.map((n) => `${key}-${n}`); + expect(previewNames).toEqual(ids); + for (const id of ids) { + const source = readFileSync(`apps/docs/demos/${id}.vue`, "utf8"); + expect(source).toContain(""); + } + } + }); + + it("documents Vue class binding and slots instead of React APIs", () => { + for (const docName of [ + "text-field", + "label", + "description", + "field-error", + "textarea", + ]) { + const document = readFileSync( + `apps/docs/components/${docName}.md`, + "utf8", + ); + expect(document).not.toMatch(/\|\s*`className`\s*\|/); + expect(document).not.toMatch(/\|\s*`children`\s*\|/); + expect(document).toContain("`class`"); + } + const fieldError = readFileSync( + "apps/docs/components/field-error.md", + "utf8", + ); + expect(fieldError).toContain("validationErrors"); + expect(fieldError).toContain("不提供完整 React Aria `validationDetails`"); + expect(fieldError).toContain("作用域插槽"); + }); + + it("keeps the three shared textfield demos and new pages aligned", () => { + for (const name of [ + "textfield-basic", + "textfield-with-description", + "textfield-validation", + ]) { + const source = readFileSync(`apps/docs/demos/${name}.vue`, "utf8"); + expect(source).toContain("TextField"); + } + const fieldsGuide = readFileSync("apps/docs/fields.md", "utf8"); + expect(fieldsGuide).toContain("textfield-basic"); + // Independent pages exist alongside the infrastructure guide + for (const page of [ + "text-field", + "label", + "description", + "field-error", + "textarea", + ]) { + expect(readFileSync(`apps/docs/components/${page}.md`, "utf8")).toContain( + "ComponentPreview", + ); + } + }); + + it("uses Tabler-free demos with library parts for field docs", () => { + for (const name of [ + "label-basic", + "description-basic", + "field-error-basic", + "textarea-basic", + ]) { + const source = readFileSync(`apps/docs/demos/${name}.vue`, "utf8"); + expect(source).not.toContain("className"); + expect(source).not.toContain("@gravity-ui/icons"); + expect(source).toContain("@heroui-vue/components"); + } + }); +}); + +function extractVueBlocks(markdown: string): string[] { + return [...markdown.matchAll(/```vue\n([\s\S]*?)```/g)].map((m) => m[1]); +} + +function scriptBindings(block: string): Set { + const script = + block.match(/