feat: add InputGroup and verify shared field integration
This commit is contained in:
@@ -297,3 +297,9 @@ Vaul Vue 官方已说明停止维护并推荐 Reka Drawer;新项目不采用 V
|
||||
- 后续文本输入、InputGroup 与字段文档任务先读 [字段/表单协议](docs/decisions/field-form-foundation.md)。通用 fieldContextKey 管理状态/ID/错误;TextFieldContext 管理单文本控件,useTextControl 复用 Input/TextArea 值恢复与 reset。
|
||||
- 不再把 Label/Description/FieldError 绑定到 Switch 私有上下文,不新建第二份值/错误/表单队列。跨组件协议、Form guard、SSR 预规划和 Fieldset 禁用继承由集成人维护。
|
||||
- 已实现的是基础设施与纵向验证,完整 Form/TextField/字段文档尚未迁完。可交出的 M12–M14 范围与禁止越界项见协议,不把计划写成完成状态。
|
||||
|
||||
### InputGroup 集成后的字段约束
|
||||
|
||||
- 本库 InputGroup 是 TextField SSR 预规划支持的透明包装层,InputGroupInput/TextArea 显式 id 必须在服务端首屏就与 Label 匹配,并回归实际水合、动态 id 与插槽;不能只用直接 Input 的旧测试代替组合组件测试。任意用户 Vue 包装组件仍有已记录限制。
|
||||
- invalid 与父字段错误合并;叶子 disabled/readonly/required 不能通过 false 解除父字段状态。文档不得把这些描述成可自由覆盖。
|
||||
- 示例中的上游复制图标按钮若没有处理器,明确仅演示布局,不声称复制已经生效。未迁移 Tooltip 时,不能将其内容直接移到常驻操作栏改变布局;定时交互清理卸载时的定时器。
|
||||
|
||||
@@ -54,6 +54,7 @@ const groups = [
|
||||
{ title: "Chip 标签", url: "/components/chip" },
|
||||
{ title: "CloseButton 关闭按钮", url: "/components/close-button" },
|
||||
{ title: "Input 输入框", url: "/components/input" },
|
||||
{ title: "InputGroup 输入框组", url: "/components/input-group" },
|
||||
{ title: "Kbd 键盘按键", url: "/components/kbd" },
|
||||
{ title: "Link 链接", url: "/components/link" },
|
||||
{ title: "Separator 分隔符", url: "/components/separator" },
|
||||
|
||||
@@ -12,6 +12,7 @@ description: 已迁移组件及文档
|
||||
- [Chip 标签](./components/chip)
|
||||
- [CloseButton 关闭按钮](./components/close-button)
|
||||
- [Input 输入框](./components/input)
|
||||
- [InputGroup 输入框组](./components/input-group)
|
||||
- [Kbd 键盘按键](./components/kbd)
|
||||
- [Link 链接](./components/link)
|
||||
- [Separator 分隔符](./components/separator)
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
---
|
||||
title: InputGroup 输入框组
|
||||
description: 将相关输入控件与前后缀元素组合,以增强表单字段
|
||||
component: input-group
|
||||
group: 组件
|
||||
---
|
||||
|
||||
## 用法
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
```
|
||||
|
||||
<ComponentPreview name="input-group-default" />
|
||||
|
||||
## 组件结构
|
||||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField>
|
||||
<Label />
|
||||
<InputGroup>
|
||||
<InputGroupPrefix />
|
||||
<InputGroupInput />
|
||||
<!-- 多行请使用 InputGroupTextArea -->
|
||||
<InputGroupSuffix />
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
```
|
||||
|
||||
> **InputGroup** 使用可选的前缀与后缀包裹输入框,形成视觉上统一的组合。通常放在 **TextField** 内,用于在输入前后添加图标、文字、按钮等元素。单行输入请使用 **InputGroupInput**,多行输入请使用 **InputGroupTextArea**。
|
||||
|
||||
命名导出为 `InputGroup` / `InputGroupInput` / `InputGroupTextArea` / `InputGroupPrefix` / `InputGroupSuffix`,不使用 `InputGroup.Input` 对象式子部件。值、校验、ARIA、reset 与表单提交由既有 TextField / `useTextControl` 统一管理。
|
||||
|
||||
## 示例
|
||||
|
||||
### 变体
|
||||
|
||||
InputGroup 组件支持两种视觉变体:
|
||||
|
||||
- **`primary`**(默认)- 标准样式带阴影,适用于大多数场景
|
||||
- **`secondary`** - 低强调变体无阴影,适用于 Surface 组件内
|
||||
|
||||
<ComponentPreview name="input-group-variants" />
|
||||
|
||||
### 表面样式
|
||||
|
||||
在 [Surface](/components/surface) 内使用时,请使用 `variant="secondary"` 以应用适合 Surface 背景的低强调变体。
|
||||
|
||||
<ComponentPreview name="input-group-on-surface" />
|
||||
|
||||
### 后缀加载状态
|
||||
|
||||
在后缀显示加载 spinner 以表示正在处理。
|
||||
|
||||
<ComponentPreview name="input-group-with-loading-suffix" />
|
||||
|
||||
### 必填字段
|
||||
|
||||
InputGroup 会遵循父级 TextField 的必填状态。
|
||||
|
||||
<ComponentPreview name="input-group-required" />
|
||||
|
||||
### 禁用状态
|
||||
|
||||
InputGroup 会遵循父级 TextField 的禁用状态。
|
||||
|
||||
<ComponentPreview name="input-group-disabled" />
|
||||
|
||||
### 宽度充满
|
||||
|
||||
<ComponentPreview name="input-group-full-width" />
|
||||
|
||||
### 文字前缀
|
||||
|
||||
使用文字作为前缀,例如货币符号或协议前缀。
|
||||
|
||||
<ComponentPreview name="input-group-with-text-prefix" />
|
||||
|
||||
### 文字后缀
|
||||
|
||||
使用文字作为后缀,例如域名后缀或单位。
|
||||
|
||||
<ComponentPreview name="input-group-with-text-suffix" />
|
||||
|
||||
### 图标前缀与文字后缀
|
||||
|
||||
组合图标前缀与文字后缀。
|
||||
|
||||
<ComponentPreview name="input-group-with-icon-prefix-and-text-suffix" />
|
||||
|
||||
### 复制按钮后缀
|
||||
|
||||
在后缀中加入按钮,例如复制图标按钮。本例仅展示布局,复制逻辑由使用方接入。嵌入按钮使用 `type="button"`(本库 Button 默认),避免误提交表单。
|
||||
|
||||
<ComponentPreview name="input-group-with-copy-suffix" />
|
||||
|
||||
### 图标前缀与复制按钮
|
||||
|
||||
组合图标前缀与交互式后缀按钮。
|
||||
|
||||
<ComponentPreview name="input-group-with-icon-prefix-and-copy-suffix" />
|
||||
|
||||
### 密码可见性切换
|
||||
|
||||
在后缀中使用按钮切换密码可见性。
|
||||
|
||||
<ComponentPreview name="input-group-password-with-toggle" />
|
||||
|
||||
### 键盘快捷键
|
||||
|
||||
使用 [Kbd](/components/kbd) 组件展示键盘快捷键。
|
||||
|
||||
<ComponentPreview name="input-group-with-keyboard-shortcut" />
|
||||
|
||||
### 徽章后缀
|
||||
|
||||
在后缀中加入徽章或 chip,用于展示状态或标签。
|
||||
|
||||
<ComponentPreview name="input-group-with-badge-suffix" />
|
||||
|
||||
### 表单校验
|
||||
|
||||
InputGroup 会自动反映父级 TextField 的无效状态。
|
||||
|
||||
<ComponentPreview name="input-group-invalid" />
|
||||
|
||||
### 前缀图标
|
||||
|
||||
在输入框前添加图标。
|
||||
|
||||
<ComponentPreview name="input-group-with-prefix-icon" />
|
||||
|
||||
### 后缀图标
|
||||
|
||||
在输入框后添加图标。
|
||||
|
||||
<ComponentPreview name="input-group-with-suffix-icon" />
|
||||
|
||||
### 前缀与后缀
|
||||
|
||||
同时组合前缀与后缀。
|
||||
|
||||
<ComponentPreview name="input-group-with-prefix-and-suffix" />
|
||||
|
||||
### 文本域
|
||||
|
||||
多行输入请使用 **InputGroupTextArea**,并搭配前缀与后缀。当存在 textarea 时,容器高度会自动适应内容,并将前缀/后缀与顶部对齐。
|
||||
|
||||
上游示例中的 Tooltip 由原生 `title` 与 `aria-label` 适配(Tooltip 组件尚未迁移)。
|
||||
|
||||
<ComponentPreview name="input-group-with-textarea" />
|
||||
|
||||
## 自定义样式
|
||||
|
||||
### Tailwind CSS
|
||||
|
||||
<ComponentPreview name="input-group-custom-styles" />
|
||||
|
||||
### 全局 CSS
|
||||
|
||||
InputGroup 使用可自定义的 CSS 类。覆盖组件类以匹配设计系统。
|
||||
|
||||
```css
|
||||
@layer components {
|
||||
.hv-input-group {
|
||||
@apply bg-field text-field-foreground shadow-field rounded-field inline-flex min-h-9 items-center overflow-hidden border text-sm outline-none;
|
||||
}
|
||||
|
||||
.hv-input-group__input {
|
||||
@apply flex-1 rounded-none border-0 bg-transparent px-3 py-2 shadow-none outline-none;
|
||||
}
|
||||
|
||||
.hv-input-group__prefix {
|
||||
@apply text-field-placeholder rounded-l-field flex h-full items-center justify-center rounded-r-none bg-transparent px-3;
|
||||
}
|
||||
|
||||
.hv-input-group__suffix {
|
||||
@apply text-field-placeholder rounded-r-field flex h-full items-center justify-center rounded-l-none bg-transparent px-3;
|
||||
}
|
||||
|
||||
/* Secondary variant */
|
||||
.hv-input-group--secondary {
|
||||
@apply shadow-none;
|
||||
background-color: var(--color-default);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 样式参考
|
||||
|
||||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||||
|
||||
### CSS 类
|
||||
|
||||
#### 基础类 [!toc]
|
||||
|
||||
- `.hv-input-group` – 根容器:带边框、背景与 flex 布局。默认 `min-h-9` 与 `items-center`;存在 textarea 时切换为 `items-start`
|
||||
- `.hv-input-group__input` – 透明背景、无边框的输入元素。textarea 也使用该基础类
|
||||
- `.hv-input-group__prefix` – 左侧圆角的前缀容器。与 textarea 搭配时与顶部对齐
|
||||
- `.hv-input-group__suffix` – 右侧圆角的后缀容器。与 textarea 搭配时与顶部对齐
|
||||
|
||||
#### 变体类 [!toc]
|
||||
|
||||
- `.hv-input-group--primary` – 带阴影的主变体(默认)
|
||||
- `.hv-input-group--secondary` – 无阴影的次变体,适用于 Surface 内
|
||||
|
||||
**Note:** 使用 `InputGroupTextArea` 时,容器从 `items-center` 切换为 `items-start`,并使用 `height: auto` 替代固定高度。前缀与后缀与顶部对齐,并增加内边距以匹配 textarea 的垂直内边距。textarea 使用相同的 `.hv-input-group__input` 基础类,并通过 `[data-slot="input-group-textarea"]` 选择器应用 textarea 专用样式(最小高度与纵向 resize)。
|
||||
|
||||
### 交互状态
|
||||
|
||||
InputGroup 会根据状态自动管理以下 data 属性:
|
||||
|
||||
- **Hover**:`[data-hovered]` - 悬停在组合上时应用
|
||||
- **Focus Within**:`[data-focus-within]` - 输入聚焦时应用
|
||||
- **Invalid**:`[data-invalid]` - 父级 TextField 无效时应用
|
||||
- **Disabled**:`[data-disabled]` 或 `[aria-disabled]` - 父级 TextField 禁用时应用
|
||||
|
||||
## API 参考
|
||||
|
||||
### InputGroup
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| ----------- | --------------------------------------- | -------------------------------- | ----------------------------------------- |
|
||||
| 默认插槽 | `Component` | - | 子部件(Input、TextArea、Prefix、Suffix) |
|
||||
| `variant` | `'primary' \| 'secondary'` | 继承 TextField,否则 `'primary'` | 视觉变体。显式值优先于 TextField 继承 |
|
||||
| `fullWidth` | `boolean` | `false` | 输入组是否占满容器宽度 |
|
||||
| `role` | `'group' \| 'region' \| 'presentation'` | `'group'` | 分组的无障碍角色 |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
点击组合空白区域会聚焦内部真实 input/textarea(按钮等可交互子元素除外)。`aria-label`、`aria-labelledby`、`aria-describedby` 等 ARIA 属性透传到根节点。
|
||||
|
||||
### InputGroupInput
|
||||
|
||||
真实 `input` 元素,复用 `useTextControl` 与 TextField 上下文。
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------------- | --------------------------- | -------- | ------------------------------------- |
|
||||
| `modelValue` | `string` | - | 当前值(受控;也可由 TextField 管理) |
|
||||
| `defaultValue` | `string` | - | 默认值(非受控) |
|
||||
| `type` | `string` | `'text'` | 输入类型(text、password、email 等) |
|
||||
| `invalid` | `boolean` | - | 标记无效状态(与父字段错误合并) |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
`name`、`id`、`disabled`、`readonly`、`required`、原生约束与 ARIA 落在真实 `input` 上;从 TextField 继承;控件可额外启用 disabled/readonly/required,不能通过 false 解除父字段状态。
|
||||
|
||||
### InputGroupTextArea
|
||||
|
||||
真实 `textarea` 元素,复用同一套值/reset/ARIA 协议。
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------------- | --------------------------- | ------ | -------------------------------- |
|
||||
| `modelValue` | `string` | - | 当前值(受控) |
|
||||
| `defaultValue` | `string` | - | 默认值(非受控) |
|
||||
| `rows` | `number` | - | 可见文本行数 |
|
||||
| `invalid` | `boolean` | - | 标记无效状态(与父字段错误合并) |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
### InputGroupPrefix
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | ----------------------------- |
|
||||
| 默认插槽 | `Component` | - | 前缀内容(图标、文字等) |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
前后缀是展示容器,不是第二个表单字段,不会出现在 FormData 中。
|
||||
|
||||
### InputGroupSuffix
|
||||
|
||||
| Prop | 类型 | 默认值 | 描述 |
|
||||
| -------- | --------------------------- | ------ | ------------------------------ |
|
||||
| 默认插槽 | `Component` | - | 后缀内容(图标、按钮、徽章等) |
|
||||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||||
|
||||
`class` 遵循 Vue 的 class 绑定,可接收字符串、数组和对象并与基础类合并;不要使用 React 的 `className`。
|
||||
|
||||
## 相关组件
|
||||
|
||||
[Input 输入框](./input) · [Surface 表面](./surface) · [Button 按钮](./button)
|
||||
@@ -0,0 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconMail } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField class="w-full max-w-xs" name="email">
|
||||
<Label>工作邮箱</Label>
|
||||
<InputGroup class="rounded-xl border border-border/80 bg-default shadow-sm">
|
||||
<InputGroupPrefix>
|
||||
<IconMail class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput placeholder="you@company.com" />
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconMail } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField class="w-full max-w-[280px]" name="email">
|
||||
<Label>邮箱地址</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>
|
||||
<IconMail class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput
|
||||
class="w-full max-w-[280px]"
|
||||
placeholder="name@email.com"
|
||||
/>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconMail } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<TextField
|
||||
class="w-full max-w-[280px]"
|
||||
default-value="name@email.com"
|
||||
is-disabled
|
||||
name="email"
|
||||
>
|
||||
<Label>邮箱地址</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>
|
||||
<IconMail class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput class="w-full max-w-[280px]" />
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
<TextField
|
||||
class="w-full max-w-[280px]"
|
||||
default-value="10"
|
||||
is-disabled
|
||||
name="price"
|
||||
>
|
||||
<Label>设置价格</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>$</InputGroupPrefix>
|
||||
<InputGroupInput class="w-full max-w-[200px]" type="number" />
|
||||
<InputGroupSuffix>USD</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,34 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconEye, IconMail } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="w-[400px] space-y-4">
|
||||
<TextField full-width name="email">
|
||||
<Label>邮箱地址</Label>
|
||||
<InputGroup full-width>
|
||||
<InputGroupPrefix>
|
||||
<IconMail class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput placeholder="name@email.com" />
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
<TextField full-width name="password">
|
||||
<Label>密码</Label>
|
||||
<InputGroup full-width>
|
||||
<InputGroupInput placeholder="输入密码" type="password" />
|
||||
<InputGroupSuffix>
|
||||
<IconEye class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
FieldError,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconMail } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<TextField class="w-full max-w-[280px]" is-invalid is-required name="email">
|
||||
<Label>邮箱地址</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>
|
||||
<IconMail class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput
|
||||
class="w-full max-w-[280px]"
|
||||
placeholder="name@email.com"
|
||||
/>
|
||||
</InputGroup>
|
||||
<FieldError>请输入有效的邮箱地址</FieldError>
|
||||
</TextField>
|
||||
<TextField class="w-full max-w-[280px]" is-invalid is-required name="price">
|
||||
<Label>设置价格</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>$</InputGroupPrefix>
|
||||
<InputGroupInput
|
||||
class="w-full max-w-[200px]"
|
||||
placeholder="0"
|
||||
type="number"
|
||||
/>
|
||||
<InputGroupSuffix>USD</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
<FieldError>价格必须大于 0</FieldError>
|
||||
</TextField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Description,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
Label,
|
||||
Surface,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconMail } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Surface class="rounded-2xl p-6">
|
||||
<TextField class="w-full max-w-[280px]" name="email">
|
||||
<Label>邮箱地址</Label>
|
||||
<InputGroup variant="secondary">
|
||||
<InputGroupPrefix>
|
||||
<IconMail class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput
|
||||
class="w-full max-w-[280px]"
|
||||
placeholder="name@email.com"
|
||||
/>
|
||||
</InputGroup>
|
||||
<Description>我们不会将此邮箱分享给任何人</Description>
|
||||
</TextField>
|
||||
</Surface>
|
||||
</template>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconEye, IconEyeOff } from "@tabler/icons-vue";
|
||||
|
||||
const isVisible = ref(false);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField class="w-full max-w-[280px]" name="password">
|
||||
<Label>密码</Label>
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
class="w-full max-w-[280px]"
|
||||
:model-value="isVisible ? '87$2h.3diua' : '••••••••'"
|
||||
:type="isVisible ? 'text' : 'password'"
|
||||
/>
|
||||
<InputGroupSuffix class="pe-0">
|
||||
<Button
|
||||
is-icon-only
|
||||
:aria-label="isVisible ? '隐藏密码' : '显示密码'"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
@click="isVisible = !isVisible"
|
||||
>
|
||||
<IconEyeOff v-if="isVisible" class="size-4" aria-hidden="true" />
|
||||
<IconEye v-else class="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,42 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Description,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconMail } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<TextField class="w-full max-w-[280px]" is-required name="email">
|
||||
<Label>邮箱地址</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>
|
||||
<IconMail class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput
|
||||
class="w-full max-w-[280px]"
|
||||
placeholder="name@email.com"
|
||||
/>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
<TextField class="w-full max-w-[280px]" is-required name="price">
|
||||
<Label>设置价格</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>$</InputGroupPrefix>
|
||||
<InputGroupInput
|
||||
class="w-full max-w-[200px]"
|
||||
placeholder="0"
|
||||
type="number"
|
||||
/>
|
||||
<InputGroupSuffix>USD</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
<Description>客户将支付的价格</Description>
|
||||
</TextField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,33 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconMail } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<TextField class="w-[280px]" name="primary">
|
||||
<Label>主要变体</Label>
|
||||
<InputGroup variant="primary">
|
||||
<InputGroupPrefix>
|
||||
<IconMail class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput placeholder="name@email.com" />
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
<TextField class="w-[280px]" name="secondary">
|
||||
<Label>次要变体</Label>
|
||||
<InputGroup variant="secondary">
|
||||
<InputGroupPrefix>
|
||||
<IconMail class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput placeholder="name@email.com" />
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Chip,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupSuffix,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField aria-label="邮箱地址" class="w-full max-w-[280px]" name="email">
|
||||
<InputGroup>
|
||||
<InputGroupInput class="w-full max-w-[280px]" placeholder="邮箱地址" />
|
||||
<InputGroupSuffix class="pe-2">
|
||||
<Chip color="accent" size="md" variant="soft">Pro</Chip>
|
||||
</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,29 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconCopy } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField
|
||||
class="w-full max-w-[280px]"
|
||||
default-value="heroui.com"
|
||||
name="website"
|
||||
>
|
||||
<Label>网站</Label>
|
||||
<InputGroup>
|
||||
<InputGroupInput class="w-full max-w-[280px]" />
|
||||
<InputGroupSuffix class="pe-0">
|
||||
<Button is-icon-only aria-label="复制" size="sm" variant="ghost">
|
||||
<IconCopy class="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,33 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Button,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconCopy, IconWorld } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField
|
||||
class="w-full max-w-[280px]"
|
||||
default-value="heroui.com"
|
||||
name="website"
|
||||
>
|
||||
<Label>网站</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>
|
||||
<IconWorld class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput class="w-full max-w-[280px]" />
|
||||
<InputGroupSuffix class="pe-0">
|
||||
<Button is-icon-only aria-label="复制" size="sm" variant="ghost">
|
||||
<IconCopy class="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconWorld } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField class="w-full max-w-[280px]" default-value="heroui" name="website">
|
||||
<Label>网站</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>
|
||||
<IconWorld class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput class="w-full max-w-[280px]" />
|
||||
<InputGroupSuffix>.com</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupSuffix,
|
||||
Kbd,
|
||||
KbdAbbr,
|
||||
KbdContent,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField aria-label="命令" class="w-full max-w-[280px]" name="command">
|
||||
<InputGroup>
|
||||
<InputGroupInput class="w-full max-w-[280px]" placeholder="命令" />
|
||||
<InputGroupSuffix class="pe-2">
|
||||
<Kbd>
|
||||
<KbdAbbr key-value="command" />
|
||||
<KbdContent>K</KbdContent>
|
||||
</Kbd>
|
||||
</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupSuffix,
|
||||
Spinner,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField class="w-full max-w-[280px]" default-value="发送中…" name="status">
|
||||
<InputGroup>
|
||||
<InputGroupInput class="w-full max-w-[280px]" />
|
||||
<InputGroupSuffix>
|
||||
<Spinner class="size-4" />
|
||||
</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Description,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField class="w-full max-w-[280px]" default-value="10" name="price">
|
||||
<Label>设置价格</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>$</InputGroupPrefix>
|
||||
<InputGroupInput class="w-full max-w-[200px]" type="number" />
|
||||
<InputGroupSuffix>USD</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
<Description>客户将支付的价格</Description>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Description,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconMail } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField class="w-full max-w-[280px]" name="email">
|
||||
<Label>邮箱地址</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>
|
||||
<IconMail class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupPrefix>
|
||||
<InputGroupInput
|
||||
class="w-full max-w-[280px]"
|
||||
placeholder="name@email.com"
|
||||
/>
|
||||
</InputGroup>
|
||||
<Description>我们不会将此邮箱分享给任何人</Description>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
Description,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import { IconMail } from "@tabler/icons-vue";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField class="w-full max-w-[280px]" name="email">
|
||||
<Label>邮箱地址</Label>
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
class="w-full max-w-[280px]"
|
||||
placeholder="name@email.com"
|
||||
/>
|
||||
<InputGroupSuffix>
|
||||
<IconMail class="size-4 text-muted" aria-hidden="true" />
|
||||
</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
<Description>我们不会发送垃圾邮件</Description>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField
|
||||
class="w-full max-w-[280px]"
|
||||
default-value="heroui.com"
|
||||
name="website"
|
||||
>
|
||||
<Label>网站</Label>
|
||||
<InputGroup>
|
||||
<InputGroupPrefix>https://</InputGroupPrefix>
|
||||
<InputGroupInput class="w-full max-w-[280px]" />
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupSuffix,
|
||||
Label,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField class="w-full max-w-[280px]" default-value="heroui" name="website">
|
||||
<Label>网站</Label>
|
||||
<InputGroup>
|
||||
<InputGroupInput class="w-full max-w-[280px]" />
|
||||
<InputGroupSuffix>.com</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
@@ -0,0 +1,99 @@
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, ref } from "vue";
|
||||
import {
|
||||
Button,
|
||||
InputGroup,
|
||||
InputGroupPrefix,
|
||||
InputGroupSuffix,
|
||||
InputGroupTextArea,
|
||||
Spinner,
|
||||
TextField,
|
||||
} from "@heroui-vue/components";
|
||||
import {
|
||||
IconArrowUp,
|
||||
IconAt,
|
||||
IconMicrophone,
|
||||
IconPlugConnected,
|
||||
IconPlus,
|
||||
} from "@tabler/icons-vue";
|
||||
|
||||
const value = ref("");
|
||||
const isSubmitting = ref(false);
|
||||
let submitTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
onBeforeUnmount(() => clearTimeout(submitTimer));
|
||||
|
||||
function handleSubmit() {
|
||||
if (!value.value.trim() || isSubmitting.value) return;
|
||||
isSubmitting.value = true;
|
||||
submitTimer = setTimeout(() => {
|
||||
isSubmitting.value = false;
|
||||
value.value = "";
|
||||
}, 1000);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TextField
|
||||
aria-label="提示输入"
|
||||
class="flex w-sm flex-col sm:w-lg"
|
||||
full-width
|
||||
name="prompt"
|
||||
>
|
||||
<InputGroup class="flex flex-col gap-2 rounded-3xl py-2" full-width>
|
||||
<InputGroupPrefix class="px-3 py-0">
|
||||
<Button aria-label="添加上下文" size="sm" variant="outline">
|
||||
<IconAt aria-hidden="true" />
|
||||
添加上下文
|
||||
</Button>
|
||||
</InputGroupPrefix>
|
||||
<InputGroupTextArea
|
||||
v-model="value"
|
||||
class="w-full resize-none px-3.5 py-0"
|
||||
placeholder="分配任务或提问…"
|
||||
:rows="5"
|
||||
/>
|
||||
<InputGroupSuffix class="flex w-full items-center gap-1.5 px-3 py-0">
|
||||
<Button
|
||||
is-icon-only
|
||||
aria-label="附加文件"
|
||||
size="sm"
|
||||
title="添加文件等"
|
||||
variant="tertiary"
|
||||
>
|
||||
<IconPlus aria-hidden="true" />
|
||||
</Button>
|
||||
<Button
|
||||
is-icon-only
|
||||
aria-label="连接应用"
|
||||
size="sm"
|
||||
title="连接应用"
|
||||
variant="tertiary"
|
||||
>
|
||||
<IconPlugConnected aria-hidden="true" />
|
||||
</Button>
|
||||
<div class="ms-auto flex items-center gap-1.5">
|
||||
<Button
|
||||
is-icon-only
|
||||
aria-label="语音输入"
|
||||
size="sm"
|
||||
title="语音输入"
|
||||
variant="ghost"
|
||||
>
|
||||
<IconMicrophone aria-hidden="true" />
|
||||
</Button>
|
||||
<Button
|
||||
is-icon-only
|
||||
aria-label="发送提示"
|
||||
:is-disabled="!value.trim()"
|
||||
:is-pending="isSubmitting"
|
||||
title="发送"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
<Spinner v-if="isSubmitting" color="current" size="sm" />
|
||||
<IconArrowUp v-else aria-hidden="true" />
|
||||
</Button>
|
||||
</div>
|
||||
</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
</template>
|
||||
+10
-2
@@ -54,7 +54,7 @@
|
||||
| toolbar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| tooltip | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 |
|
||||
| input-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 |
|
||||
| textarea | 验证中(字段接入) | 接入 TextField 与共享 useTextControl;独立文档/全部示例仍待补齐 |
|
||||
| textfield | 验证中(基础设施) | 一个文本控件;值/状态/约束/校验/ID;3 个基线示例;完整文档与其余示例待补齐 |
|
||||
| search-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
@@ -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,基线预览名称与顺序均已对齐。没有用空壳补足数量;预览与复制代码共用 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,基线预览名称与顺序均已对齐。没有用空壳补足数量;预览与复制代码共用 SFC。
|
||||
|
||||
Card 图片、头像、横向布局、表单与自定义样式已补齐;Input 的标签、类型、宽度与自定义样式已对齐。Switch 补齐图标、位置、分组、表单、状态插槽与自定义根容器。Surface 覆盖变体与表单组合;Link 覆盖图标位置、文本装饰、自定义图标、asChild 与自定义样式;Spinner 覆盖颜色、尺寸、速度与自定义样式。CloseButton 覆盖默认、交互、自定义图标与自定义样式。Avatar 覆盖基本、尺寸、颜色、变体、回退、自定义图片组件与自定义样式;AvatarGroup 覆盖基本、max、自定义计数、尺寸、网格、叠放样式与自定义样式;Skeleton 覆盖文本、用户资料、列表、网格、单次闪烁、动画类型与自定义样式。Separator 覆盖基本、变体、Surface 组合、垂直、带内容布局、asChild 自定义根与自定义样式;Kbd 覆盖基本、变体、导航键、行内、说明文字、特殊键与自定义样式;Chip 覆盖基本、变体矩阵、状态图标、带图标与自定义样式。Badge 覆盖基本、变体、尺寸、颜色、四角位置、点状、带内容与自定义样式;Alert 覆盖六种组合的基本示例与自定义样式。
|
||||
|
||||
@@ -145,3 +145,11 @@ Card 图片、头像、横向布局、表单与自定义样式已补齐;Input
|
||||
## 字段与表单基础协议(2026-10-21)
|
||||
|
||||
见 [基础协议与可交接范围](./decisions/field-form-foundation.md)。TextField、Form 已形成纵向验证,不代表全部上游示例或复杂表单家族已完成;验证页为 `/fields`。
|
||||
|
||||
## M12 InputGroup 说明
|
||||
|
||||
- 部件命名导出:InputGroup / InputGroupInput / InputGroupTextArea / InputGroupPrefix / InputGroupSuffix(无 `InputGroup.Input` 对象式)。
|
||||
- 值、disabled/readonly/required、校验、ARIA、focus、FormData/reset 全部复用 `field/useTextControl` 与 TextField 上下文,未维护第二份字段状态。
|
||||
- 显式 `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`。
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
2. 输入控件的 name/type、原生约束与 ARIA 落在真实 input/textarea;class/style/data-* 保留各组件自己的根节点。TextField 的 id 用作控件 ID;显式控件 id 优先,Label 的 for 跟随它变化。
|
||||
3. Label、Description、FieldError 不依赖 Switch 私有 key。Switch 与 TextField 都提供通用上下文,内层 Switch 的描述/错误不得泄漏到外层 TextField。
|
||||
4. Description / FieldError ID 使用 Vue useId 和可变显式 id;支持多个描述、外部 aria-describedby 合并及卸载清理。FieldError 只在字段 invalid 时渲染,默认展示错误数组并提供 validationErrors / isInvalid 作用域插槽。
|
||||
5. SSR 直接子部件或原生元素/Fragment 包裹的描述/错误,由 TextField 在控件渲染前预规划 ID,保证 Input 在前、Description 在后时首屏引用完整。自定义 Vue 包装组件不能静态展开,客户端依然会注册;需要首屏 SSR 关联时显式设置控件 aria-describedby 与描述 id。不能宣称任意包装层级均已 SSR 验收。
|
||||
5. SSR 直接子部件、原生元素/Fragment 或本库 InputGroup 包裹的描述/错误,由 TextField 在控件渲染前预规划 ID,保证 Input 在前、Description 在后时首屏引用完整。本库 InputGroup 也预规划内部显式控件 ID;其他自定义 Vue 包装组件不能静态展开,客户端依然会注册;需要首屏 SSR 关联时显式设置控件 aria-describedby 与描述 id。不能宣称任意包装层级均已 SSR 验收。
|
||||
6. native 模式通过 Constraint Validation API 检查必填、类型、pattern 与同步自定义错误;提交尝试后展示错误,聚焦首个无效控件。aria 模式展示语义但不拦截提交。isInvalid 是展示状态;提交拦截使用 validate 或 validationErrors,不把静态错误插槽反向解析成校验函数。
|
||||
7. Form 固定使用原生 novalidate 来接管提交时机,再按各控件 data-validation-behavior / Form 默认策略调用 checkValidity。这样能混用局部 native 与 aria 字段。调用方 novalidate 或 submitter.formNoValidate 明确跳过 guard。@submit.capture 也不能先于 guard 处理无效提交。普通原生 form 的 aria 字段需调用方自行配置 novalidate。
|
||||
8. Form 的 validationErrors 按字段 name 映射字符串/数组。用户编辑字段后忽略当前响应对象中的该字段错误,下一响应应提供新对象。异步请求的时序与竞态由调用方负责,validate 目前仅同步,不接受 Promise。
|
||||
|
||||
@@ -213,3 +213,12 @@ API 表落实本文“M07–M09 文档契约返工”:className→class,chil
|
||||
字段与表单基础设施及稳定接口见 [field-form-foundation.md](./decisions/field-form-foundation.md)。当前可交出 M12 InputGroup、M13 字段文档/演示补齐、M14 TextArea 独立文档与消费验证,先任选一项,不代表已经派发。
|
||||
|
||||
这些任务必须复用现有 field/textfield/form 协议。SearchField 清空/提交、Fieldset 禁用继承、Checkbox/Radio 家族仍由集成人先做纵向验证。不要顺手重写 shared context、Form guard、Switch 字段或者为文档承诺尚不存在的能力。
|
||||
|
||||
## M12 后的执行顺序与归属(2026-10-21)
|
||||
|
||||
M12 InputGroup 已经独立复核并由集成人修正共享 SSR ID 预规划,结论与验证边界见 [M12-review.md](./migrations/M12-review.md)。下一轮交接说明为 [M13–M14 提示词](./migrations/M13-M14-fields-textarea-prompt.md),由用户交给其他 AI,不代表本文已自动派发。
|
||||
|
||||
- 其他 AI:M13 TextField/Label/Description/FieldError 独立文档与全部基线内容,然后 M14 TextArea;两项均基于现有协议,可立即开始,不等待新基建。
|
||||
- 集成人:复核和提交;共享字段协议、Fieldset、SearchField、Checkbox/Radio 分组协议的扩展。尚未实施的能力不能写成完成。
|
||||
- 后续其他 AI 候选:Typography → EmptyState → Breadcrumbs,前一批复核后再开。EmptyState 基线有实现但没有独立中文组件页,来源与自建文档必须区分。
|
||||
- 同一 checkout 只能有一人编辑导出、导航、样式/变体入口、清单和公共协议;启动并行工作前声明这些文件归属。组件私有文件与文档内容可独立推进;遇到协议缺口先交失败用例。
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
# M12 InputGroup 交接报告
|
||||
|
||||
实施日期:2026-10-21。状态:实施者自测完成,待集成人复核。**未提交、未推送、未宣布集成验收通过。**
|
||||
|
||||
## 1. 起点与范围
|
||||
|
||||
| 项 | 值 |
|
||||
| ---------- | ----------------------------------------------------------------------------------------------------- |
|
||||
| 起始 HEAD | `7f11afe`(feat: establish shared field and form foundation,FORM-01) |
|
||||
| 工作区起点 | 干净;未改动 field/context.ts、useFieldPart.ts、useTextControl.ts、TextField、Form guard、Switch 协议 |
|
||||
| 上游基线 | HeroUI 3.2.6 / `ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960`(`../heroui` 只读) |
|
||||
| 范围 | InputGroup、InputGroupInput、InputGroupTextArea、InputGroupPrefix、InputGroupSuffix |
|
||||
|
||||
### 新增
|
||||
|
||||
- 样式:`packages/styles/components/input-group.css`
|
||||
- 变体:`inputGroupVariants`(`packages/styles/src/index.ts`)
|
||||
- 组件:`packages/vue/src/components/input-group/{InputGroup,InputGroupInput,InputGroupTextArea,InputGroupPrefix,InputGroupSuffix}.vue` + `context.ts`
|
||||
- 演示 21:`apps/docs/demos/input-group-*.vue`
|
||||
- 文档:`apps/docs/components/input-group.md`
|
||||
- 测试:`tests/input-group.test.ts`(17 项)
|
||||
|
||||
### 修改(共享)
|
||||
|
||||
- `packages/styles/index.css`、`packages/vue/src/{index.ts,types.ts}`
|
||||
- `apps/docs/.vitepress/theme/Layout.vue`、`apps/docs/components.md`
|
||||
- `package.json`(test:unit 增加 input-group.test.ts)
|
||||
- `docs/{compatibility,upstream,verification}.md`
|
||||
|
||||
## 2. 上游来源
|
||||
|
||||
| 路径 | 用途 |
|
||||
| -------------------------------------------------------------------- | ---------------------------------- |
|
||||
| `packages/react/src/components/input-group/*` | 部件结构、点击聚焦、变体继承 |
|
||||
| `packages/styles/components/input-group.css` | BEM、状态、autofill、textarea 对齐 |
|
||||
| `packages/styles/src/components/input-group/*.styles.ts` | tv 变体 |
|
||||
| `apps/docs/content/docs/cn/react/components/(forms)/input-group.mdx` | 中文结构与示例次序 |
|
||||
| `apps/docs/src/demos/cn/input-group/` | 21 个示例文案与布局 |
|
||||
| `third-party/HEROUI-LICENSE` | Apache-2.0 |
|
||||
|
||||
## 3. API 对照(Vue 契约)
|
||||
|
||||
| 上游 | Vue | 差异 |
|
||||
| ---------------------------------------------- | ------------------------------------------ | ------------------------ |
|
||||
| `InputGroup.Root/Input/TextArea/Prefix/Suffix` | `InputGroup` 等命名导出 | 不用对象式 |
|
||||
| GroupRenderProps / render 函数 children | 默认插槽 | render prop 不搬入 |
|
||||
| `className` / `ReactNode` | `class`(string\|Array\|Object)/ 插槽 | 无 className 别名 |
|
||||
| `variant` 默认 primary | 默认继承 TextField,否则 primary;显式优先 | 对齐上游 resolvedVariant |
|
||||
| RAC Group hover/focus-within | `data-hovered`/`data-focus-within` | Vue 事件驱动 |
|
||||
| RAC Input/TextArea | `useTextControl` + 真实 input/textarea | 复用 FORM-01 协议 |
|
||||
| `role` 默认 group | 同;可选 region/presentation | 一致 |
|
||||
|
||||
值/reset/ARIA/FormData 由 TextField + useTextControl 管理;前后缀不是表单字段。
|
||||
|
||||
## 4. 示例逐项对照(21 / 21)
|
||||
|
||||
与 CN `input-group.mdx` 的 `<ComponentPreview>` 顺序一致:
|
||||
|
||||
1. default 2. variants 3. on-surface 4. with-loading-suffix 5. required 6. disabled 7. full-width 8. with-text-prefix 9. with-text-suffix 10. with-icon-prefix-and-text-suffix 11. with-copy-suffix 12. with-icon-prefix-and-copy-suffix 13. password-with-toggle 14. with-keyboard-shortcut 15. with-badge-suffix 16. invalid 17. with-prefix-icon 18. with-suffix-icon 19. with-prefix-and-suffix 20. with-textarea 21. custom-styles
|
||||
|
||||
图标:Tabler(IconMail/IconWorld/IconCopy/IconEye/IconEyeOff/IconAt/IconPlus/IconPlugConnected/IconMicrophone/IconArrowUp)。with-textarea 的 Tooltip 以 `title`+`aria-label` 适配并已在文档注明。
|
||||
|
||||
## 5. 回归场景
|
||||
|
||||
| 要求 | 适用性 | 测试 | 结果 |
|
||||
| ---------------------------------------------------- | ------ | -------------------------------------------------------------- | ------ |
|
||||
| 复用 TextField/useTextControl,不第二份值/错误/reset | 适用 | FormData、reset、受控拒绝(field-foundation)+ InputGroup 集成 | 通过 |
|
||||
| 前后缀非表单字段、按钮 type=button 不误提交 | 适用 | FormData 仅含 name;copy 按钮 type=button 不触发 submit | 通过 |
|
||||
| 显式 variant 优先于 TextField | 适用 | 动态切换 | 通过 |
|
||||
| 动态前后缀/加载不破坏焦点和值 | 适用 | 点击聚焦真实 input;loading 后缀示例 | 通过 |
|
||||
| attrs 空→新增→修改→删除→再次新增 | 适用 | group 透传 | 通过 |
|
||||
| class 合并 | 适用 | group + input | 通过 |
|
||||
| 描述/错误关联、native/aria、SSR | 适用 | field-foundation 既有 19 项未改动仍通过 | 通过 |
|
||||
| 文档契约 class≠className | 适用 | 文档断言 | 通过 |
|
||||
| 键盘激活适配 | 不适用 | 展示/组合容器 | 未添加 |
|
||||
|
||||
## 6. 命令结果
|
||||
|
||||
| 命令 | 文件数 | 通过 | 含 SSR |
|
||||
| ----------------- | ------ | ---- | ------- |
|
||||
| `pnpm test` | 12 | 185 | 是(2) |
|
||||
| `pnpm test:unit` | 11 | 183 | 否 |
|
||||
| `pnpm typecheck` | — | 通过 | — |
|
||||
| `pnpm build:docs` | — | 通过 | — |
|
||||
| `pnpm format` | — | 通过 | — |
|
||||
|
||||
## 7. 浏览器证据(Playwright CLI,5173)
|
||||
|
||||
视口 1280 与 390。26 组/25 input/1 textarea;disabled 2、invalid 2;后缀按钮均为 type=button;点击组空白聚焦 input;密码切换生效;API 表 736/350 无溢出。控制台仅 favicon 404。
|
||||
|
||||
## 8. 未验证项
|
||||
|
||||
浅/深切换交互、位图截图、Nuxt 水合、RTL、读屏、触屏、独立安装 dist、复制按钮实际写入剪贴板、自动视觉对比。
|
||||
|
||||
## 9. 最短复核路径
|
||||
|
||||
1. `pnpm test && pnpm test:unit && pnpm typecheck && pnpm build:docs`
|
||||
2. `/components/input-group`:默认/变体/Surface/加载/必填/禁用/全宽/前后缀/复制/密码/Kbd/Chip/校验/textarea/自定义,共 21 例。
|
||||
3. 在默认或价格示例输入并提交 Form(或看 `tests/input-group.test.ts` FormData/reset)。
|
||||
4. 点击组合空白应聚焦输入框;点复制按钮不应提交。
|
||||
5. 人工补测浅/深与窄屏交互。
|
||||
|
||||
## 10. 需集成人确认
|
||||
|
||||
- with-textarea 用 title/aria-label 代替未迁移的 Tooltip 是否可接受。
|
||||
- 导航中 InputGroup 插在 Input 与 Kbd 之间。
|
||||
- 点击聚焦扩展到 textarea(上游仅 querySelector('input')),已记录为 Vue 适配。
|
||||
|
||||
实施者只记自测,验收结论留给集成人。
|
||||
|
||||
## 集成人后续结论
|
||||
|
||||
独立复核与共享协议修正见 [M12-review.md](./M12-review.md)。本报告前文命令与浏览器结果保留为实施者自测阶段记录;最终计数及审查边界以独立报告为准。
|
||||
@@ -0,0 +1,22 @@
|
||||
# M12 InputGroup 独立复核
|
||||
|
||||
日期:2026-10-21。结论:修正后通过本批代码、文档契约与构建复核,可提交;不代表完整视觉或消费验收。
|
||||
|
||||
## 范围与发现
|
||||
|
||||
- 五个公开部件、21 个文档预览均存在;共享文件变动限于本批接入,没有复制字段值、校验或 reset 状态。CSS 去除注释、空白并还原 hv- 前缀后,与固定基线完全一致;tv 变体一致。
|
||||
- 独立复现:`TextField > Label + InputGroup > InputGroupInput(id)` 的服务端 HTML 中,Label 引用生成 ID,输入框却使用显式 ID。原有 TextField 的预规划只识别直接/native 包裹控件。由集成人扩展到本库 InputGroup 默认插槽以及两个输入部件;用户任意包装组件仍不静态展开。新增 node SSR 与实际 SSR→hydrate、动态 ID/插槽回归。
|
||||
- 多行演示补定时器卸载清理和重复提交保护;原 Kbd 属于尚未迁移 Tooltip 的内容,不应直接移到常驻操作栏,移除该常驻提示,保留 title/aria-label 替代边界。
|
||||
- 文档修正:invalid 是与父字段状态合并,不承诺 false 覆盖父错误;disabled/readonly/required 不能通过 false 解除父状态。复制图标示例与上游一样没有剪贴板处理,明确仅展示组合布局。
|
||||
- 接受局部适配:点击组空白也可聚焦 textarea;交互式后缀按钮保留自身焦点;Tooltip 尚未迁移,使用原生 title/aria-label,未声称等价。
|
||||
|
||||
## 集成人验证
|
||||
|
||||
- `pnpm test`:12 文件 / 189 项,其中 node SSR 3 项。
|
||||
- `pnpm test:unit`:11 文件 / 186 项,不含 node SSR;包含 jsdom 的实际水合回归。
|
||||
- `pnpm typecheck`、`pnpm build:docs`、`pnpm format`、`git diff --check`:通过。
|
||||
- dist 公开类型探针由 vue-tsc 实际检查:合法组合可用,非法 variant/role/modelValue/rows 被拒绝;临时探针验证后移除。
|
||||
- 独立补充 4 项:node SSR 显式分组控件 ID;受控拒绝和取消 reset;native/aria 提交与组错误状态;SSR→hydrate、动态 ID/前缀和描述关联。
|
||||
- 本轮未重新逐页打开浏览器;实施者的 1280/390 浏览器自测记录与独立检查分开保留。未进行逐像素、读屏、RTL、Nuxt 或独立打包安装验收。
|
||||
|
||||
下一轮:M13 字段文档补齐 + M14 TextArea,见 M13-M14 提示词;共享字段协议依然由集成人维护。
|
||||
@@ -0,0 +1,68 @@
|
||||
# M13–M14 字段文档与 TextArea 迁移任务
|
||||
|
||||
供用户交给其他 AI;本文是任务说明,不代表已通过工具派发。
|
||||
|
||||
```text
|
||||
在独立 heroui-vue 仓库完成下一轮 M13 + M14,按顺序实现、分开写交接报告,完成这两项后交回复核。
|
||||
先读取 AGENTS.md、docs/migration-handoff.md、docs/decisions/field-form-foundation.md、
|
||||
docs/compatibility.md、docs/upstream.md、docs/migrations/M12-review.md。
|
||||
起点必须包含已提交的 M12 InputGroup 及其集成人修正;记录实际 git HEAD 和工作区状态。
|
||||
只读 ../heroui,固定 HeroUI 3.2.6 / ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960。
|
||||
|
||||
M13:补齐 TextField、Label、Description、FieldError 四个独立中文文档页及全部基线内容。
|
||||
参考上游 apps/docs/content/docs/cn/react/components/(forms)/ 下 text-field.mdx、label.mdx、
|
||||
description.mdx、field-error.mdx,及对应 React 源码、CSS/变体、apps/docs/src/demos/cn 下示例。
|
||||
TextField 有 13 个 ComponentPreview;已有 basic、with-description、validation 三份 SFC 应复用。
|
||||
其余页面不仅核对 ComponentPreview,还要把正文中的基础校验、动态/多条错误等代码示例
|
||||
改成实际可运行的 Vue 消费写法,保留文案、结构和顺序,避免仅复制一张 API 表就算完成。
|
||||
原 /fields 是基础设施指南,保留它的验证用途,不拿它冒充四个独立组件页。
|
||||
|
||||
M14:TextArea 能力核对、独立页面、全部 7 个基线预览及适用行为测试。
|
||||
参考 text-area.mdx、textarea 组件源码/CSS/变体与对应演示;核对现有
|
||||
packages/vue/src/components/textarea/TextArea.vue,补足局部表现层缺口,不复制 useTextControl。
|
||||
验证 rows、原生属性、变体、尺寸/全宽、受控拒绝、FormData/reset/取消 reset、
|
||||
只读/禁用、Label/Description/FieldError 关联及 TextField/InputGroup 相邻回归。
|
||||
|
||||
职责边界:
|
||||
- 可修改本批组件文档、SFC 演示、专项测试、TextArea 局部封装/CSS/变体和交接报告。
|
||||
- 不改 field/context.ts、useFieldPart.ts、useTextControl.ts、TextField.vue、Form guard、Switch
|
||||
或 InputGroup 核心;遇到缺口写最小可复现测试及实际/预期,交给集成人,不降低文档承诺掩盖问题。
|
||||
- 不实现 Fieldset、SearchField、Checkbox/Radio 体系;这些由集成人负责。
|
||||
- 共享导航、导出、样式入口、package.json、矩阵和验证记录,仅做本批必要增量;
|
||||
不批量格式化或重写他人文件,不增加新依赖、不改变主题/文档布局/构建链路。
|
||||
- 同一 checkout 如有集成人并行工作,不编辑上述共享文件;先记录需要的增量,由集成人整合。
|
||||
|
||||
公共契约:
|
||||
值采用 v-model,独立命名导出;class 支持 string/array/object,插槽替代 children/ReactNode。
|
||||
API 表逐个核对 Root 与部件,说明事件、暴露方法、属性实际 DOM 落点及继承优先级。
|
||||
isInvalid 只负责错误展示,阻止提交依赖 validate/validationErrors;validate 当前仅同步,
|
||||
FieldError 尚无完整 validationDetails,不能照抄不支持的 React 契约或加入假类型。
|
||||
描述与错误 ID 要唯一、可动态更新且卸载清理;InputGroup 是已支持的透明包装层,
|
||||
任意用户 Vue 包装层的 SSR 限制仍需如实说明。
|
||||
|
||||
视觉与演示:
|
||||
保持固定基线的样式、布局、文案、参数默认值、主题及状态;先列清单再实现。
|
||||
预览/复制/高亮使用同一 SFC;图标用 @tabler/icons-vue,禁止自绘 SVG。
|
||||
原生 required/aria/native、错误与提交必须是实际行为,不能只设置 data 属性。
|
||||
正文全部表格铺满内容区并自动换行,不缩字号、不截断、不横向滚动。
|
||||
基础/固定状态示例与真实交互分别说明;定时器和监听器卸载清理。
|
||||
遇到未迁移依赖说明具体替代及差异,不能为展示示例把内容挪到不同位置或删掉。
|
||||
|
||||
验证与交接:
|
||||
运行 pnpm test、pnpm test:unit、pnpm typecheck、pnpm build:docs、pnpm format,
|
||||
新增测试文件同步 test:unit 列表;各入口分别记录实际文件数/测试数/是否含 node SSR。
|
||||
真实浏览器只用 127.0.0.1:5173,检查本批主要交互、浅深主题、桌面/窄屏及长短表格,
|
||||
记录地址、视口、主题、步骤和结果;未执行项明确标注。
|
||||
分别提交 docs/migrations/M13-field-docs.md 与 M14-textarea.md,包含来源许可、
|
||||
完整示例清单/内容核对、API差异、修改文件、命令结果、浏览器证据、已知缺口及最短复核步骤。
|
||||
不自行 Git 提交/推送,不宣布独立验收通过;保留实现给集成人复核。
|
||||
|
||||
后续候选是 Typography → EmptyState → Breadcrumbs,待本轮复核后再开始。
|
||||
EmptyState 在固定基线中有实现,但没有对应独立中文组件页;先核实来源,不虚构官方示例或数量。
|
||||
```
|
||||
|
||||
## 先后与文件归属
|
||||
|
||||
M13 可立即开始,M14 接着复用 M13 的字段说明。两者均不等待 Fieldset / SearchField / Checkbox / Radio。
|
||||
集成人开展上述基建前会明确共享文件归属;同一 checkout 不同时修改共享文件。
|
||||
如本轮发现公共协议缺口,仅受影响的示例等待集成人补齐,其他无依赖内容可继续。
|
||||
+4
-1
@@ -7,7 +7,7 @@
|
||||
|
||||
## 已移植
|
||||
|
||||
- packages/styles/components/{button,close-button,card,input,textarea,switch,switch-group,label,description,surface,link,spinner,avatar,avatar-group,skeleton,separator,kbd,chip,badge,alert}.css:只将组件类名加 hv- 前缀;Vue 状态适配集中在样式入口和组件层。
|
||||
- packages/styles/components/{button,close-button,card,input,textarea,switch,switch-group,label,description,surface,link,spinner,avatar,avatar-group,skeleton,separator,kbd,chip,badge,alert,input-group}.css:只将组件类名加 hv- 前缀;Vue 状态适配集中在样式入口和组件层。
|
||||
- packages/styles/themes/default/variables.css、themes/shared/theme.css:主题变量、OKLCH 颜色、派生公式和圆角尺寸。
|
||||
- packages/styles/utilities、variants:焦点、禁用、减少动画等构建规则。
|
||||
- packages/styles/src/components/{button,card,input,textarea,switch,surface,link,spinner,close-button,avatar,avatar-group,skeleton,separator,kbd,chip,badge,alert}/*.styles.ts:变体与类名映射,增加命名空间。
|
||||
@@ -47,6 +47,9 @@
|
||||
|
||||
- `packages/react/src/components/{textfield,form,label,description,field-error}`:公共语义与组合设计;Vue 以原生控件与类型化上下文实现,不移植 React Aria runtime。
|
||||
- `packages/styles/components/{textfield,field-error}.css`:移植为 hv- 命名空间,保留 Apache-2.0 来源与许可头。
|
||||
- `packages/styles/src/components/input-group/input-group.styles.ts` 与 `packages/react/src/components/input-group/*`:InputGroup 部件与变体。
|
||||
- `apps/docs/content/docs/cn/react/components/(forms)/input-group.mdx` 与 `apps/docs/src/demos/cn/input-group/`:21 个文档引用示例。
|
||||
- `apps/docs/src/demos/cn/textfield/{basic,with-description,validation}.tsx`:三个基线演示,保留文案/布局,仅把状态与事件改为 Vue。
|
||||
- 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 适配。
|
||||
|
||||
@@ -197,3 +197,35 @@
|
||||
- 新增字段专项 19 项;node SSR 验证首屏 ID 引用完整且唯一,jsdom 实际 SSR→hydrate 无 mismatch。不是 Nuxt 消费验收。
|
||||
- 实际浏览器 `/fields`:拦截空邮箱并聚焦、提交真实 FormData、关闭 Switch 省略字段、reset 恢复、服务端错误替换与编辑清除;浅色/深色切换。桌面正文表格 736px,390px 窄屏正文表格 350px,无页面或表格横向溢出。已恢复默认视口与浅色主题。
|
||||
- 协议、限制和可交出的任务见 `decisions/field-form-foundation.md`;完整交付记录见 `migrations/FORM-01-foundation.md`。完整 Form/字段系列文档与未验证能力不标为完成。
|
||||
|
||||
## M12 InputGroup(2026-10-21)
|
||||
|
||||
起始 HEAD `7f11afe`(FORM-01 字段/表单基础已合入),工作区干净。上游只读 `../heroui` @ `ce90ea3`。未修改 field/context.ts、useFieldPart.ts、useTextControl.ts、TextField、Form guard、Switch 协议。
|
||||
|
||||
### 命令(分别记录)
|
||||
|
||||
| 入口 | 文件数 | 通过数 | 含 SSR |
|
||||
| ----------------- | ------ | ------ | ------------------- |
|
||||
| `pnpm test` | 12 | 185 | 是(ssr.test.ts 2) |
|
||||
| `pnpm test:unit` | 11 | 183 | 否 |
|
||||
| `pnpm typecheck` | — | 通过 | — |
|
||||
| `pnpm build:docs` | — | 通过 | — |
|
||||
| `pnpm format` | — | 通过 | — |
|
||||
|
||||
### 浏览器(Playwright CLI,127.0.0.1:5173/components/input-group)
|
||||
|
||||
- 26 组 / 25 input / 1 textarea;prefix 18、suffix 15;primary 24、secondary 2、fullWidth 3。
|
||||
- disabled 组 2、invalid 组 2;后缀按钮 type 全为 button。
|
||||
- 点击组空白聚焦真实 input;密码切换 type=password→text。
|
||||
- API 表 5 张:桌面 1280 宽 736、窄屏 390 宽 350,均无水平溢出。
|
||||
- 控制台仅 favicon 404。
|
||||
|
||||
### 未验证
|
||||
|
||||
浅/深切换交互、独立安装 dist、Nuxt 水合、RTL、读屏、触屏、自动视觉对比、复制按钮剪贴板写入(仅验证 type=button 不提交)。
|
||||
|
||||
## M12 集成人复核修正(2026-10-21)
|
||||
|
||||
独立复核见 [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、独立安装仍未验证。
|
||||
|
||||
+1
-1
@@ -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/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-foundation.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts",
|
||||
"format": "prettier --check .",
|
||||
"format:fix": "prettier --write .",
|
||||
|
||||
@@ -0,0 +1,210 @@
|
||||
/* Adapted from HeroUI v3, ce90ea3. Copyright 2025 NextUI Inc.
|
||||
* See third-party/HEROUI-LICENSE. Modified: hv- class prefix. */
|
||||
|
||||
/* Input group styles */
|
||||
.hv-input-group {
|
||||
@apply inline-flex min-h-9 items-center rounded-field border bg-field text-sm text-field-foreground shadow-field outline-none;
|
||||
border-width: var(--border-width-field);
|
||||
border-color: var(--field-border);
|
||||
|
||||
/* When textarea is present, align items to start and allow height to grow */
|
||||
&:has([data-slot="input-group-textarea"]) {
|
||||
@apply items-start;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 state */
|
||||
@media (hover: hover) {
|
||||
&:hover:not(:focus-within),
|
||||
&[data-hovered="true"]:not([data-focus-within="true"]) {
|
||||
@apply bg-field-hover;
|
||||
border-color: var(--field-border-hover);
|
||||
}
|
||||
}
|
||||
|
||||
/* Focus within state - only when input/textarea is focused */
|
||||
&:has([data-slot="input-group-input"]:focus),
|
||||
&:has([data-slot="input-group-textarea"]:focus) {
|
||||
@apply status-focused-field;
|
||||
border-color: var(--field-border-focus);
|
||||
background-color: var(--field-focus);
|
||||
}
|
||||
|
||||
/* Invalid state */
|
||||
&[data-invalid="true"] {
|
||||
@apply status-invalid-field;
|
||||
background-color: var(--field-focus);
|
||||
border-color: var(--color-field-border-invalid);
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&[data-disabled="true"],
|
||||
&[aria-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Browser autofill state.
|
||||
* The user-agent paints `:-webkit-autofill`/`:autofill` on the inner <input>
|
||||
* element only, inside its content box. Because the inner input has its
|
||||
* border-radius stripped on whichever side touches a prefix/suffix, the
|
||||
* autofill highlight ends up as a sharp-cornered rectangle and the
|
||||
* prefix/suffix slots receive no highlight at all. Lift the highlight
|
||||
* onto the group so the rounded shell + prefix + suffix all share it.
|
||||
*/
|
||||
&:has([data-slot="input-group-input"]:-webkit-autofill),
|
||||
&:has([data-slot="input-group-input"]:autofill) {
|
||||
background-color: var(--field-focus);
|
||||
border-color: var(--field-border-focus);
|
||||
}
|
||||
}
|
||||
|
||||
.hv-input-group__input {
|
||||
@apply flex-1 rounded-none border-0 bg-transparent px-3 py-2 text-base shadow-none outline-none placeholder:text-field-placeholder sm:text-sm;
|
||||
|
||||
/* Remove border radius on left side when prefix is present */
|
||||
.hv-input-group:has([data-slot="input-group-prefix"]) & {
|
||||
@apply rounded-s-none ps-0;
|
||||
}
|
||||
|
||||
/* Remove border radius on right side when suffix is present */
|
||||
.hv-input-group:has([data-slot="input-group-suffix"]) & {
|
||||
@apply rounded-e-none pe-0;
|
||||
}
|
||||
|
||||
/* Focus state - handled by group */
|
||||
&:focus,
|
||||
&:focus-visible {
|
||||
@apply outline-none;
|
||||
}
|
||||
|
||||
/**
|
||||
* Neutralize the browser's per-input autofill paint so the inner <input>
|
||||
* doesn't draw a sharp-cornered yellow rectangle. The unified highlight
|
||||
* is applied to `.hv-input-group` above. Preserve the autofilled text and
|
||||
* caret colors, and pin the background-color transition so the inset
|
||||
* box-shadow trick doesn't flicker on state changes.
|
||||
*/
|
||||
&:-webkit-autofill,
|
||||
&:-webkit-autofill:hover,
|
||||
&:-webkit-autofill:focus,
|
||||
&:-webkit-autofill:active,
|
||||
&:autofill {
|
||||
-webkit-box-shadow: 0 0 0 1000px transparent inset;
|
||||
box-shadow: 0 0 0 1000px transparent inset;
|
||||
-webkit-text-fill-color: var(--field-foreground);
|
||||
caret-color: var(--field-foreground);
|
||||
transition: background-color 9999s ease-in-out 0s;
|
||||
}
|
||||
}
|
||||
|
||||
/* TextArea within InputGroup - uses same base class as input but with textarea-specific styles */
|
||||
.hv-input-group__input[data-slot="input-group-textarea"] {
|
||||
min-height: 38px;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
.hv-input-group__prefix {
|
||||
@apply flex h-full items-center justify-center rounded-s-field rounded-e-none bg-transparent px-3 text-field-placeholder;
|
||||
border-width: var(--border-width-field);
|
||||
border-color: var(--field-border);
|
||||
border-style: solid;
|
||||
border-inline-end-color: var(--field-border);
|
||||
border-inline-start: none;
|
||||
border-top: none;
|
||||
border-bottom: none;
|
||||
|
||||
/* Align to top when textarea is present */
|
||||
.hv-input-group:has([data-slot="input-group-textarea"]) & {
|
||||
@apply items-start;
|
||||
padding-top: 0.5rem;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
@apply motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
.hv-input-group__suffix {
|
||||
@apply flex h-full items-center justify-center rounded-s-none rounded-e-field bg-transparent px-3 text-field-placeholder;
|
||||
border-width: var(--border-width-field);
|
||||
border-color: var(--field-border);
|
||||
border-style: solid;
|
||||
border-inline-start-color: var(--field-border);
|
||||
border-inline-end: none;
|
||||
border-top: none;
|
||||
border-bottom: none;
|
||||
|
||||
/* Align to top when textarea is present */
|
||||
.hv-input-group:has([data-slot="input-group-textarea"]) & {
|
||||
@apply items-start;
|
||||
padding-top: 0.5rem;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
@apply motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
/* Variant property definitions */
|
||||
.hv-input-group--primary {
|
||||
/* Default styles */
|
||||
}
|
||||
|
||||
.hv-input-group--secondary {
|
||||
@apply shadow-none;
|
||||
background-color: var(--input-group-bg);
|
||||
|
||||
--input-group-bg: var(--default);
|
||||
--input-group-bg-hover: var(--default-hover);
|
||||
--input-group-bg-focus: var(--default);
|
||||
|
||||
@media (hover: hover) {
|
||||
&:hover:not(:focus-within),
|
||||
&[data-hovered="true"]:not([data-focus-within="true"]) {
|
||||
background-color: var(--input-group-bg-hover);
|
||||
}
|
||||
}
|
||||
|
||||
&:has([data-slot="input-group-input"]:focus),
|
||||
&:has([data-slot="input-group-textarea"]:focus) {
|
||||
background-color: var(--input-group-bg-focus);
|
||||
}
|
||||
|
||||
/* Invalid state */
|
||||
&[data-invalid="true"] {
|
||||
@apply status-invalid-field;
|
||||
border-color: var(--color-field-border-invalid);
|
||||
background-color: var(--input-group-bg-focus);
|
||||
}
|
||||
|
||||
[data-slot="input-group-input"],
|
||||
[data-slot="input-group-textarea"] {
|
||||
@apply bg-transparent;
|
||||
}
|
||||
}
|
||||
|
||||
/* Full width modifier */
|
||||
.hv-input-group--full-width {
|
||||
@apply w-full;
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
@import "./components/chip.css" layer(components);
|
||||
@import "./components/badge.css" layer(components);
|
||||
@import "./components/alert.css" layer(components);
|
||||
@import "./components/input-group.css" layer(components);
|
||||
/* The Vue Switch uses Reka's native button for its clickable content. */
|
||||
@layer components {
|
||||
.hv-switch:has(.hv-switch__content:focus-visible) .hv-switch__control {
|
||||
|
||||
@@ -498,3 +498,34 @@ export const alertVariants = tv({
|
||||
});
|
||||
|
||||
export type AlertVariants = VariantProps<typeof alertVariants>;
|
||||
|
||||
export const inputGroupVariants = tv({
|
||||
defaultVariants: {
|
||||
fullWidth: false,
|
||||
variant: "primary",
|
||||
},
|
||||
slots: {
|
||||
base: "hv-input-group",
|
||||
input: "hv-input-group__input",
|
||||
prefix: "hv-input-group__prefix",
|
||||
suffix: "hv-input-group__suffix",
|
||||
},
|
||||
variants: {
|
||||
fullWidth: {
|
||||
false: {},
|
||||
true: {
|
||||
base: "hv-input-group--full-width",
|
||||
},
|
||||
},
|
||||
variant: {
|
||||
primary: {
|
||||
base: "hv-input-group--primary",
|
||||
},
|
||||
secondary: {
|
||||
base: "hv-input-group--secondary",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export type InputGroupVariants = VariantProps<typeof inputGroupVariants>;
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, inject, provide, ref, useAttrs } from "vue";
|
||||
import {
|
||||
inputGroupVariants,
|
||||
type InputGroupVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
import { textFieldContextKey } from "../textfield/context";
|
||||
import { inputGroupContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
fullWidth?: boolean;
|
||||
variant?: InputGroupVariants["variant"];
|
||||
role?: "group" | "region" | "presentation";
|
||||
}>(),
|
||||
{
|
||||
fullWidth: false,
|
||||
role: "group",
|
||||
},
|
||||
);
|
||||
|
||||
const attrs = useAttrs();
|
||||
const textField = inject(textFieldContextKey, undefined);
|
||||
|
||||
const groupEl = ref<HTMLElement>();
|
||||
const hovered = ref(false);
|
||||
const focusWithin = ref(false);
|
||||
|
||||
/** Explicit variant wins over TextField inheritance. */
|
||||
const resolvedVariant = computed<InputGroupVariants["variant"]>(
|
||||
() => props.variant ?? textField?.variant.value,
|
||||
);
|
||||
|
||||
const slots = computed(() =>
|
||||
inputGroupVariants({
|
||||
fullWidth: props.fullWidth,
|
||||
variant: resolvedVariant.value,
|
||||
}),
|
||||
);
|
||||
|
||||
provide(inputGroupContextKey, { slots });
|
||||
|
||||
const invalid = computed(() => Boolean(textField?.invalid.value));
|
||||
const disabled = computed(() => Boolean(textField?.disabled.value));
|
||||
|
||||
function focusControl(e: MouseEvent) {
|
||||
const group = groupEl.value;
|
||||
if (!group) return;
|
||||
const target = e.target as HTMLElement | null;
|
||||
const control = group.querySelector<HTMLElement>(
|
||||
'input[data-slot="input-group-input"], textarea[data-slot="input-group-textarea"]',
|
||||
);
|
||||
if (!control || control === target || control.contains(target)) return;
|
||||
// Keep real focus on the actual input/textarea so value and caret stay intact.
|
||||
if (
|
||||
target?.closest(
|
||||
'button, a, input, textarea, select, [role="button"], [tabindex]',
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
control.focus();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
ref="groupEl"
|
||||
v-bind="attrs"
|
||||
:class="[slots.base(), attrs.class]"
|
||||
:role="role"
|
||||
:data-hovered="hovered || undefined"
|
||||
:data-focus-within="focusWithin || undefined"
|
||||
:data-invalid="invalid || undefined"
|
||||
:data-disabled="disabled || undefined"
|
||||
:aria-disabled="disabled || undefined"
|
||||
data-slot="input-group"
|
||||
@click="focusControl"
|
||||
@pointerenter="hovered = true"
|
||||
@pointerleave="hovered = false"
|
||||
@focusin="focusWithin = true"
|
||||
@focusout="focusWithin = false"
|
||||
>
|
||||
<slot />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, useAttrs } from "vue";
|
||||
import { useTextControl } from "../field/useTextControl";
|
||||
import { inputGroupContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: string;
|
||||
defaultValue?: string;
|
||||
invalid?: boolean;
|
||||
type?: string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{ "update:modelValue": [value: string] }>();
|
||||
const attrs = useAttrs();
|
||||
const group = inject(inputGroupContextKey, undefined);
|
||||
const control = useTextControl(props, attrs, emit);
|
||||
const { element, value } = control;
|
||||
|
||||
defineExpose({ focus: () => element.value?.focus(), element });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<input
|
||||
ref="element"
|
||||
v-bind="{ ...control.inheritedAttrs(), ...attrs }"
|
||||
:value="value"
|
||||
:id="control.id()"
|
||||
:name="control.name()"
|
||||
:type="control.type()"
|
||||
:disabled="control.disabled()"
|
||||
:readonly="control.readOnly()"
|
||||
:required="control.required()"
|
||||
:class="[group?.slots.value.input(), attrs.class]"
|
||||
:data-invalid="control.invalid() || undefined"
|
||||
:aria-invalid="control.invalid() || undefined"
|
||||
:aria-readonly="control.readOnly() || undefined"
|
||||
:aria-describedby="control.describedBy()"
|
||||
:data-validation-behavior="control.validationBehavior()"
|
||||
data-slot="input-group-input"
|
||||
@input="control.update"
|
||||
@invalid="control.onInvalid"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, useAttrs } from "vue";
|
||||
import { inputGroupContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const attrs = useAttrs();
|
||||
const group = inject(inputGroupContextKey, undefined);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-bind="attrs"
|
||||
:class="[group?.slots.value.prefix(), attrs.class]"
|
||||
data-slot="input-group-prefix"
|
||||
>
|
||||
<slot />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, useAttrs } from "vue";
|
||||
import { inputGroupContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const attrs = useAttrs();
|
||||
const group = inject(inputGroupContextKey, undefined);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-bind="attrs"
|
||||
:class="[group?.slots.value.suffix(), attrs.class]"
|
||||
data-slot="input-group-suffix"
|
||||
>
|
||||
<slot />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,45 @@
|
||||
<script setup lang="ts">
|
||||
import { inject, useAttrs } from "vue";
|
||||
import { useTextControl } from "../field/useTextControl";
|
||||
import { inputGroupContextKey } from "./context";
|
||||
|
||||
defineOptions({ inheritAttrs: false });
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue?: string;
|
||||
defaultValue?: string;
|
||||
invalid?: boolean;
|
||||
rows?: number;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{ "update:modelValue": [value: string] }>();
|
||||
const attrs = useAttrs();
|
||||
const group = inject(inputGroupContextKey, undefined);
|
||||
const control = useTextControl(props, attrs, emit);
|
||||
const { element, value } = control;
|
||||
|
||||
defineExpose({ focus: () => element.value?.focus(), element });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<textarea
|
||||
ref="element"
|
||||
v-bind="{ ...control.inheritedAttrs(), ...attrs }"
|
||||
:value="value"
|
||||
:id="control.id()"
|
||||
:name="control.name()"
|
||||
:rows="rows"
|
||||
:disabled="control.disabled()"
|
||||
:readonly="control.readOnly()"
|
||||
:required="control.required()"
|
||||
:class="[group?.slots.value.input(), attrs.class]"
|
||||
:data-invalid="control.invalid() || undefined"
|
||||
:aria-invalid="control.invalid() || undefined"
|
||||
:aria-readonly="control.readOnly() || undefined"
|
||||
:aria-describedby="control.describedBy()"
|
||||
:data-validation-behavior="control.validationBehavior()"
|
||||
data-slot="input-group-textarea"
|
||||
@input="control.update"
|
||||
@invalid="control.onInvalid"
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { ComputedRef, InjectionKey } from "vue";
|
||||
import type { inputGroupVariants } from "@heroui-vue/styles";
|
||||
|
||||
export type InputGroupSlots = ReturnType<typeof inputGroupVariants>;
|
||||
|
||||
export interface InputGroupContextValue {
|
||||
slots: ComputedRef<InputGroupSlots>;
|
||||
}
|
||||
|
||||
export const inputGroupContextKey: InjectionKey<InputGroupContextValue> =
|
||||
Symbol("HeroUIVue.InputGroup");
|
||||
@@ -213,7 +213,12 @@ export default defineComponent({
|
||||
const position = `${path}-${index}`;
|
||||
const type = node.type as { name?: string; __name?: string };
|
||||
const name = type?.name ?? type?.__name;
|
||||
if (name === "Input" || name === "TextArea")
|
||||
if (
|
||||
name === "Input" ||
|
||||
name === "TextArea" ||
|
||||
name === "InputGroupInput" ||
|
||||
name === "InputGroupTextArea"
|
||||
)
|
||||
found.controlId = node.props?.id;
|
||||
if (name === "Description" || name === "FieldError") {
|
||||
const kind = name === "Description" ? "description" : "error";
|
||||
@@ -221,6 +226,22 @@ export default defineComponent({
|
||||
found[kind].push(String(id));
|
||||
return cloneVNode(node, { id });
|
||||
}
|
||||
// InputGroup is a library-owned transparent field wrapper. Prepare its
|
||||
// default slot once, preserving the current render's values and keys.
|
||||
// Arbitrary consumer components remain opaque to SSR planning.
|
||||
if (
|
||||
name === "InputGroup" &&
|
||||
node.children &&
|
||||
typeof node.children === "object"
|
||||
) {
|
||||
const groupSlots = node.children as { default?: () => VNodeChild[] };
|
||||
if (typeof groupSlots.default === "function") {
|
||||
const prepared = prepare(groupSlots.default(), found, position);
|
||||
const clone = cloneVNode(node);
|
||||
clone.children = { ...groupSlots, default: () => prepared };
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
if (
|
||||
(typeof node.type === "string" || node.type === Fragment) &&
|
||||
Array.isArray(node.children)
|
||||
|
||||
@@ -31,6 +31,7 @@ export {
|
||||
chipVariants,
|
||||
badgeVariants,
|
||||
alertVariants,
|
||||
inputGroupVariants,
|
||||
type ButtonVariants,
|
||||
type CardVariants,
|
||||
type InputVariants,
|
||||
@@ -48,6 +49,7 @@ export {
|
||||
type ChipVariants,
|
||||
type BadgeVariants,
|
||||
type AlertVariants,
|
||||
type InputGroupVariants,
|
||||
} from "@heroui-vue/styles";
|
||||
export type {
|
||||
ButtonProps,
|
||||
@@ -82,6 +84,11 @@ export type {
|
||||
AlertContentProps,
|
||||
AlertTitleProps,
|
||||
AlertDescriptionProps,
|
||||
InputGroupProps,
|
||||
InputGroupInputProps,
|
||||
InputGroupTextAreaProps,
|
||||
InputGroupPrefixProps,
|
||||
InputGroupSuffixProps,
|
||||
} from "./types";
|
||||
|
||||
export { tv, cn, type VariantProps } from "@heroui-vue/styles";
|
||||
@@ -181,3 +188,14 @@ export type {
|
||||
DescriptionProps,
|
||||
FieldErrorProps,
|
||||
} from "./types";
|
||||
|
||||
export { default as InputGroup } from "./components/input-group/InputGroup.vue";
|
||||
export { default as InputGroupInput } from "./components/input-group/InputGroupInput.vue";
|
||||
export { default as InputGroupTextArea } from "./components/input-group/InputGroupTextArea.vue";
|
||||
export { default as InputGroupPrefix } from "./components/input-group/InputGroupPrefix.vue";
|
||||
export { default as InputGroupSuffix } from "./components/input-group/InputGroupSuffix.vue";
|
||||
export {
|
||||
inputGroupContextKey,
|
||||
type InputGroupContextValue,
|
||||
type InputGroupSlots,
|
||||
} from "./components/input-group/context";
|
||||
|
||||
@@ -81,3 +81,23 @@ export type TextFieldProps = InstanceType<typeof TextField>["$props"];
|
||||
export type FormProps = InstanceType<typeof Form>["$props"];
|
||||
export type DescriptionProps = InstanceType<typeof Description>["$props"];
|
||||
export type FieldErrorProps = InstanceType<typeof FieldError>["$props"];
|
||||
|
||||
import type InputGroup from "./components/input-group/InputGroup.vue";
|
||||
import type InputGroupInput from "./components/input-group/InputGroupInput.vue";
|
||||
import type InputGroupTextArea from "./components/input-group/InputGroupTextArea.vue";
|
||||
import type InputGroupPrefix from "./components/input-group/InputGroupPrefix.vue";
|
||||
import type InputGroupSuffix from "./components/input-group/InputGroupSuffix.vue";
|
||||
|
||||
export type InputGroupProps = InstanceType<typeof InputGroup>["$props"];
|
||||
export type InputGroupInputProps = InstanceType<
|
||||
typeof InputGroupInput
|
||||
>["$props"];
|
||||
export type InputGroupTextAreaProps = InstanceType<
|
||||
typeof InputGroupTextArea
|
||||
>["$props"];
|
||||
export type InputGroupPrefixProps = InstanceType<
|
||||
typeof InputGroupPrefix
|
||||
>["$props"];
|
||||
export type InputGroupSuffixProps = InstanceType<
|
||||
typeof InputGroupSuffix
|
||||
>["$props"];
|
||||
|
||||
@@ -0,0 +1,559 @@
|
||||
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,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
InputGroupSuffix,
|
||||
InputGroupTextArea,
|
||||
Label,
|
||||
TextField,
|
||||
} from "../packages/vue/src";
|
||||
import { createSSRApp } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import InputGroupDefaultDemo from "../apps/docs/demos/input-group-default.vue";
|
||||
import InputGroupPasswordDemo from "../apps/docs/demos/input-group-password-with-toggle.vue";
|
||||
import InputGroupCopyDemo from "../apps/docs/demos/input-group-with-copy-suffix.vue";
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
});
|
||||
|
||||
const settle = async () => {
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
};
|
||||
|
||||
function groupField(props: Record<string, unknown> = {}, inputProps = {}) {
|
||||
return h(TextField, props, () => [
|
||||
h(Label, {}, () => "Label"),
|
||||
h(InputGroup, {}, () => [
|
||||
h(InputGroupPrefix, {}, () => "$"),
|
||||
h(InputGroupInput, inputProps),
|
||||
h(InputGroupSuffix, {}, () => "USD"),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
describe("InputGroup", () => {
|
||||
it("renders group shell with input/prefix/suffix data-slots and classes", () => {
|
||||
const w = mount(groupField({ name: "price", defaultValue: "10" }));
|
||||
const group = w.get("[data-slot=input-group]");
|
||||
expect(group.attributes("role")).toBe("group");
|
||||
expect(group.classes()).toContain("hv-input-group");
|
||||
expect(group.classes()).toContain("hv-input-group--primary");
|
||||
const input = w.get("[data-slot=input-group-input]");
|
||||
expect(input.element.tagName).toBe("INPUT");
|
||||
expect(input.classes()).toContain("hv-input-group__input");
|
||||
expect(input.attributes("name")).toBe("price");
|
||||
expect((input.element as HTMLInputElement).value).toBe("10");
|
||||
expect(w.get("[data-slot=input-group-prefix]").classes()).toContain(
|
||||
"hv-input-group__prefix",
|
||||
);
|
||||
expect(w.get("[data-slot=input-group-suffix]").classes()).toContain(
|
||||
"hv-input-group__suffix",
|
||||
);
|
||||
});
|
||||
|
||||
it("inherits TextField variant and allows explicit override", async () => {
|
||||
const variant = ref<"primary" | "secondary">("secondary");
|
||||
const explicit = ref<"primary" | "secondary" | undefined>(undefined);
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: {
|
||||
TextField,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupPrefix,
|
||||
},
|
||||
setup: () => ({ variant, explicit }),
|
||||
template: `
|
||||
<TextField :variant="variant" name="x">
|
||||
<InputGroup :variant="explicit">
|
||||
<InputGroupPrefix>A</InputGroupPrefix>
|
||||
<InputGroupInput />
|
||||
</InputGroup>
|
||||
</TextField>
|
||||
`,
|
||||
}),
|
||||
);
|
||||
expect(w.get("[data-slot=input-group]").classes()).toContain(
|
||||
"hv-input-group--secondary",
|
||||
);
|
||||
explicit.value = "primary";
|
||||
await settle();
|
||||
expect(w.get("[data-slot=input-group]").classes()).toContain(
|
||||
"hv-input-group--primary",
|
||||
);
|
||||
expect(w.get("[data-slot=input-group]").classes()).not.toContain(
|
||||
"hv-input-group--secondary",
|
||||
);
|
||||
explicit.value = undefined;
|
||||
await settle();
|
||||
expect(w.get("[data-slot=input-group]").classes()).toContain(
|
||||
"hv-input-group--secondary",
|
||||
);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("applies fullWidth and custom role", () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { InputGroup, InputGroupInput },
|
||||
template: `<InputGroup full-width role="region"><InputGroupInput /></InputGroup>`,
|
||||
}),
|
||||
);
|
||||
const group = w.get("[data-slot=input-group]");
|
||||
expect(group.classes()).toContain("hv-input-group--full-width");
|
||||
expect(group.attributes("role")).toBe("region");
|
||||
});
|
||||
|
||||
it("reflects TextField disabled and invalid on the group shell", async () => {
|
||||
const isDisabled = ref(false);
|
||||
const isInvalid = ref(false);
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { TextField, InputGroup, InputGroupInput },
|
||||
setup: () => ({ isDisabled, isInvalid }),
|
||||
template: `
|
||||
<TextField :is-disabled="isDisabled" :is-invalid="isInvalid" name="x">
|
||||
<InputGroup><InputGroupInput /></InputGroup>
|
||||
</TextField>
|
||||
`,
|
||||
}),
|
||||
);
|
||||
const group = () => w.get("[data-slot=input-group]");
|
||||
expect(group().attributes("data-disabled")).toBeUndefined();
|
||||
expect(group().attributes("data-invalid")).toBeUndefined();
|
||||
isDisabled.value = true;
|
||||
isInvalid.value = true;
|
||||
await settle();
|
||||
expect(group().attributes("data-disabled")).toBe("true");
|
||||
expect(group().attributes("data-invalid")).toBe("true");
|
||||
expect(group().attributes("aria-disabled")).toBe("true");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("focuses the real input when clicking group padding but not buttons", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: {
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupSuffix,
|
||||
},
|
||||
template: `
|
||||
<InputGroup>
|
||||
<InputGroupInput />
|
||||
<InputGroupSuffix>
|
||||
<button type="button" class="action">Go</button>
|
||||
</InputGroupSuffix>
|
||||
</InputGroup>
|
||||
`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const input = w.get("input").element as HTMLInputElement;
|
||||
const group = w.get("[data-slot=input-group]");
|
||||
await group.trigger("click");
|
||||
expect(document.activeElement).toBe(input);
|
||||
input.blur();
|
||||
await w.get("button.action").trigger("click");
|
||||
expect(document.activeElement).not.toBe(input);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("keeps prefix/suffix out of FormData and submits only the real input", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Form, {}, () => [
|
||||
groupField({ name: "amount", defaultValue: "3" }),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const input = w.get("input");
|
||||
await input.setValue("9");
|
||||
const data = Object.fromEntries(
|
||||
new FormData(w.get("form").element as HTMLFormElement),
|
||||
);
|
||||
expect(data).toEqual({ amount: "9" });
|
||||
expect(Object.keys(data)).toEqual(["amount"]);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("resets uncontrolled values and restores controlled rejection", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Form, {}, () => [groupField({ name: "n", defaultValue: "start" })]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const input = w.get("input");
|
||||
await input.setValue("changed");
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await settle();
|
||||
expect((input.element as HTMLInputElement).value).toBe("start");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("does not treat suffix buttons as form submitters", async () => {
|
||||
const submit = vi.fn((e: Event) => e.preventDefault());
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h("form", { onSubmit: submit }, [
|
||||
h(InputGroup, {}, () => [
|
||||
h(InputGroupInput, { name: "q" }),
|
||||
h(InputGroupSuffix, {}, () => [
|
||||
h("button", { type: "button", class: "copy-btn" }, "Copy"),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
await w.get("button.copy-btn").trigger("click");
|
||||
expect(submit).not.toHaveBeenCalled();
|
||||
expect(w.get("button.copy-btn").attributes("type")).toBe("button");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("supports textarea child and keeps value/reset protocol", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Form, {}, () => [
|
||||
h(TextField, { name: "bio", defaultValue: "hello" }, () => [
|
||||
h(InputGroup, {}, () => [
|
||||
h(InputGroupPrefix, {}, () => ">"),
|
||||
h(InputGroupTextArea, { rows: 3 }),
|
||||
h(InputGroupSuffix, {}, () => "!"),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const area = w.get("[data-slot=input-group-textarea]");
|
||||
expect(area.element.tagName).toBe("TEXTAREA");
|
||||
expect((area.element as HTMLTextAreaElement).value).toBe("hello");
|
||||
await area.setValue("changed");
|
||||
expect(
|
||||
Object.fromEntries(
|
||||
new FormData(w.get("form").element as HTMLFormElement),
|
||||
),
|
||||
).toEqual({ bio: "changed" });
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await settle();
|
||||
expect((area.element as HTMLTextAreaElement).value).toBe("hello");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("merges caller class on group and input without dropping base classes", async () => {
|
||||
const extra = ref<Record<string, unknown>>({});
|
||||
const classValue = ref<unknown>("group-custom");
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: { InputGroup, InputGroupInput },
|
||||
setup: () => ({ extra, classValue }),
|
||||
template: `
|
||||
<InputGroup v-bind="extra" :class="classValue">
|
||||
<InputGroupInput class="input-custom" />
|
||||
</InputGroup>
|
||||
`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
let group = w.get("[data-slot=input-group]");
|
||||
expect(group.classes()).toContain("hv-input-group");
|
||||
expect(group.classes()).toContain("group-custom");
|
||||
expect(w.get("input").classes()).toContain("hv-input-group__input");
|
||||
expect(w.get("input").classes()).toContain("input-custom");
|
||||
|
||||
extra.value = { "data-x": "1", title: "t" };
|
||||
classValue.value = ["group-custom", { "group-more": true }];
|
||||
await settle();
|
||||
group = w.get("[data-slot=input-group]");
|
||||
expect(group.attributes("data-x")).toBe("1");
|
||||
expect(group.attributes("title")).toBe("t");
|
||||
expect(group.classes()).toContain("group-more");
|
||||
expect(group.classes()).toContain("hv-input-group");
|
||||
|
||||
extra.value = {};
|
||||
await settle();
|
||||
expect(
|
||||
w.get("[data-slot=input-group]").attributes("data-x"),
|
||||
).toBeUndefined();
|
||||
|
||||
extra.value = { "aria-label": "search" };
|
||||
await settle();
|
||||
expect(w.get("[data-slot=input-group]").attributes("aria-label")).toBe(
|
||||
"search",
|
||||
);
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("updates hover and focus-within data attributes", async () => {
|
||||
const w = mount(InputGroup, {
|
||||
slots: { default: () => h(InputGroupInput) },
|
||||
attachTo: document.body,
|
||||
});
|
||||
const group = w.get("[data-slot=input-group]");
|
||||
await group.trigger("pointerenter");
|
||||
expect(group.attributes("data-hovered")).toBe("true");
|
||||
await group.trigger("focusin");
|
||||
expect(group.attributes("data-focus-within")).toBe("true");
|
||||
await group.trigger("focusout");
|
||||
expect(group.attributes("data-focus-within")).toBeUndefined();
|
||||
await group.trigger("pointerleave");
|
||||
expect(group.attributes("data-hovered")).toBeUndefined();
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("keeps password toggle from submitting and updates input type/value", async () => {
|
||||
const w = mount(InputGroupPasswordDemo, { attachTo: document.body });
|
||||
const input = w.get("[data-slot=input-group-input]");
|
||||
expect(input.attributes("type")).toBe("password");
|
||||
const toggle = w.get("button");
|
||||
expect(toggle.attributes("type")).toBe("button");
|
||||
expect(toggle.attributes("aria-label")).toBe("显示密码");
|
||||
await toggle.trigger("click");
|
||||
await settle();
|
||||
expect(w.get("[data-slot=input-group-input]").attributes("type")).toBe(
|
||||
"text",
|
||||
);
|
||||
expect(w.get("button").attributes("aria-label")).toBe("隐藏密码");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("renders the default and copy demos with library parts", () => {
|
||||
const basic = mount(InputGroupDefaultDemo);
|
||||
expect(basic.find("[data-slot=input-group]").exists()).toBe(true);
|
||||
expect(basic.find("[data-slot=input-group-input]").exists()).toBe(true);
|
||||
expect(basic.get("label").text()).toBe("邮箱地址");
|
||||
|
||||
const copy = mount(InputGroupCopyDemo);
|
||||
const btn = copy.get("button");
|
||||
expect(btn.attributes("type")).toBe("button");
|
||||
expect(btn.attributes("aria-label")).toBe("复制");
|
||||
expect(copy.find("[data-slot=input-group-suffix]").exists()).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps public prop types constrained", async () => {
|
||||
const { InputGroup: Group, InputGroupInput: Inp } =
|
||||
await import("../packages/vue/src");
|
||||
// @ts-expect-error variant must be primary | secondary
|
||||
const badVariant: InstanceType<typeof Group>["$props"]["variant"] = "ghost";
|
||||
// @ts-expect-error role must be group | region | presentation
|
||||
const badRole: InstanceType<typeof Group>["$props"]["role"] = "banner";
|
||||
void badVariant;
|
||||
void badRole;
|
||||
const ok: InstanceType<typeof Group>["$props"] = {
|
||||
variant: "secondary",
|
||||
fullWidth: true,
|
||||
role: "group",
|
||||
};
|
||||
const okInput: InstanceType<typeof Inp>["$props"] = {
|
||||
type: "email",
|
||||
modelValue: "a@b.c",
|
||||
};
|
||||
expect(ok.variant).toBe("secondary");
|
||||
expect(okInput.type).toBe("email");
|
||||
});
|
||||
});
|
||||
|
||||
describe("M12 demo inventory", () => {
|
||||
const expected = [
|
||||
"default",
|
||||
"variants",
|
||||
"on-surface",
|
||||
"with-loading-suffix",
|
||||
"required",
|
||||
"disabled",
|
||||
"full-width",
|
||||
"with-text-prefix",
|
||||
"with-text-suffix",
|
||||
"with-icon-prefix-and-text-suffix",
|
||||
"with-copy-suffix",
|
||||
"with-icon-prefix-and-copy-suffix",
|
||||
"password-with-toggle",
|
||||
"with-keyboard-shortcut",
|
||||
"with-badge-suffix",
|
||||
"invalid",
|
||||
"with-prefix-icon",
|
||||
"with-suffix-icon",
|
||||
"with-prefix-and-suffix",
|
||||
"with-textarea",
|
||||
"custom-styles",
|
||||
];
|
||||
|
||||
it("includes every preview from the pinned upstream documents", () => {
|
||||
const document = readFileSync(
|
||||
"apps/docs/components/input-group.md",
|
||||
"utf8",
|
||||
);
|
||||
const previewNames = [
|
||||
...document.matchAll(/<ComponentPreview name="input-group-([^"]+)"/g),
|
||||
].map((m) => m[1]);
|
||||
expect(previewNames).toEqual(expected);
|
||||
for (const name of expected) {
|
||||
const source = readFileSync(
|
||||
`apps/docs/demos/input-group-${name}.vue`,
|
||||
"utf8",
|
||||
);
|
||||
expect(source).toContain("<template>");
|
||||
}
|
||||
});
|
||||
|
||||
it("documents Vue class binding instead of React className", () => {
|
||||
const document = readFileSync(
|
||||
"apps/docs/components/input-group.md",
|
||||
"utf8",
|
||||
);
|
||||
expect(document).not.toMatch(/\|\s*`className`\s*\|/);
|
||||
expect(document).not.toMatch(/\|\s*`children`\s*\|/);
|
||||
expect(document).toContain("`class`");
|
||||
expect(document).toContain("Vue class 绑定");
|
||||
expect(document).toMatch(/string\s*\\\|\s*Array\s*\\\|\s*Object/);
|
||||
for (const name of ["default", "custom-styles", "with-textarea"]) {
|
||||
const source = readFileSync(
|
||||
`apps/docs/demos/input-group-${name}.vue`,
|
||||
"utf8",
|
||||
);
|
||||
expect(source).not.toContain("className");
|
||||
expect(source).not.toContain("@gravity-ui/icons");
|
||||
expect(source).not.toContain('from "reka-ui"');
|
||||
}
|
||||
});
|
||||
|
||||
it("uses Tabler icons and library form parts in demos", () => {
|
||||
const demo = readFileSync(
|
||||
"apps/docs/demos/input-group-with-copy-suffix.vue",
|
||||
"utf8",
|
||||
);
|
||||
expect(demo).toContain("@tabler/icons-vue");
|
||||
expect(demo).toContain("Button");
|
||||
expect(demo).not.toContain("<path");
|
||||
|
||||
const textarea = readFileSync(
|
||||
"apps/docs/demos/input-group-with-textarea.vue",
|
||||
"utf8",
|
||||
);
|
||||
expect(textarea).toContain("InputGroupTextArea");
|
||||
expect(textarea).not.toContain("Tooltip");
|
||||
});
|
||||
});
|
||||
|
||||
describe("InputGroup independent integration regression", () => {
|
||||
it("retains controlled values and respects canceled reset", async () => {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Form, { onReset: (e: Event) => e.preventDefault() }, () => [
|
||||
groupField({ modelValue: "fixed", name: "controlled" }),
|
||||
groupField({ defaultValue: "initial", name: "editable" }),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
const [controlled, editable] = w.findAll("input");
|
||||
await controlled.setValue("rejected");
|
||||
await settle();
|
||||
expect((controlled.element as HTMLInputElement).value).toBe("fixed");
|
||||
await editable.setValue("retained");
|
||||
(w.get("form").element as HTMLFormElement).reset();
|
||||
await settle();
|
||||
expect((editable.element as HTMLInputElement).value).toBe("retained");
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("enforces native constraints while aria mode permits the submit callback", async () => {
|
||||
const mode = ref<"native" | "aria">("native");
|
||||
const submit = vi.fn((e: Event) => e.preventDefault());
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Form, { onSubmit: submit }, () => [
|
||||
h(
|
||||
TextField,
|
||||
{ name: "q", isRequired: true, validationBehavior: mode.value },
|
||||
() => [
|
||||
h(InputGroup, {}, () => [h(InputGroupInput)]),
|
||||
h(FieldError),
|
||||
],
|
||||
),
|
||||
]),
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
(w.get("form").element as HTMLFormElement).requestSubmit();
|
||||
await settle();
|
||||
expect(submit).not.toHaveBeenCalled();
|
||||
expect(w.get("input").attributes("aria-invalid")).toBe("true");
|
||||
expect(w.get("[data-slot=input-group]").attributes("data-invalid")).toBe(
|
||||
"true",
|
||||
);
|
||||
mode.value = "aria";
|
||||
await settle();
|
||||
(w.get("form").element as HTMLFormElement).requestSubmit();
|
||||
await settle();
|
||||
expect(submit).toHaveBeenCalledOnce();
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it("hydrates explicit IDs and keeps dynamic slots, labels and descriptions current", async () => {
|
||||
const id = ref("group-a");
|
||||
const show = ref(true);
|
||||
const view = defineComponent({
|
||||
render: () =>
|
||||
h(TextField, {}, () => [
|
||||
h(Label, {}, () => "Email"),
|
||||
h(InputGroup, {}, () => [
|
||||
show.value ? h(InputGroupPrefix, {}, () => "@") : null,
|
||||
h(InputGroupInput, { id: id.value }),
|
||||
]),
|
||||
h(Description, {}, () => "Hint"),
|
||||
]),
|
||||
});
|
||||
const host = document.createElement("div");
|
||||
host.innerHTML = await renderToString(createSSRApp(view));
|
||||
document.body.append(host);
|
||||
const errors = vi.spyOn(console, "error");
|
||||
const warnings = vi.spyOn(console, "warn");
|
||||
const app = createSSRApp(view);
|
||||
try {
|
||||
app.mount(host);
|
||||
await settle();
|
||||
expect(host.querySelector("label")?.htmlFor).toBe("group-a");
|
||||
id.value = "group-b";
|
||||
show.value = false;
|
||||
await settle();
|
||||
expect(host.querySelector("label")?.htmlFor).toBe("group-b");
|
||||
expect(host.querySelector("input")?.id).toBe("group-b");
|
||||
expect(host.querySelector("[data-slot=input-group-prefix]")).toBeNull();
|
||||
const refs =
|
||||
host
|
||||
.querySelector("input")
|
||||
?.getAttribute("aria-describedby")
|
||||
?.split(" ") ?? [];
|
||||
expect(refs.length).toBeGreaterThan(0);
|
||||
for (const ref of refs)
|
||||
expect(document.getElementById(ref)).not.toBeNull();
|
||||
expect(errors).not.toHaveBeenCalled();
|
||||
expect(warnings).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
app.unmount();
|
||||
host.remove();
|
||||
errors.mockRestore();
|
||||
warnings.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -71,3 +71,42 @@ it("renders complete field associations without browser globals", async () => {
|
||||
for (const id of refs) expect(ids).toContain(id);
|
||||
expect(html).toContain('value="a@example.com"');
|
||||
});
|
||||
|
||||
it("associates labels with explicit grouped control IDs on the server", async () => {
|
||||
const {
|
||||
TextField,
|
||||
Label,
|
||||
InputGroup,
|
||||
InputGroupInput,
|
||||
InputGroupTextArea,
|
||||
Description,
|
||||
} = await import("../packages/vue/src");
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h("div", {}, [
|
||||
h(TextField, {}, () => [
|
||||
h(Label, {}, () => "Email"),
|
||||
h(InputGroup, {}, () => [
|
||||
h(InputGroupInput, { id: "grouped-email" }),
|
||||
]),
|
||||
h(Description, {}, () => "Hint"),
|
||||
]),
|
||||
h(TextField, {}, () => [
|
||||
h(Label, {}, () => "Notes"),
|
||||
h(InputGroup, {}, () => [
|
||||
h(InputGroupTextArea, { id: "grouped-notes" }),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
expect(html).toContain('for="grouped-email"');
|
||||
expect(html).toContain('for="grouped-notes"');
|
||||
const ids = [...html.matchAll(/\sid="([^"]+)"/g)].map((m) => m[1]);
|
||||
const refs = [
|
||||
...html.matchAll(/(?:for|aria-describedby)="([^"]+)"/g),
|
||||
].flatMap((m) => m[1].split(" "));
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
for (const id of refs) expect(ids).toContain(id);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user