Files
maoyingjie 145a208687 docs: close documentation facts, structure and related-component mapping
HD-04 scope, against heroui ce90ea3 cn sources:

- stale/fictional content: input.md no longer claims TextField is
  unmigrated; color-field.md no longer claims ColorPicker is private;
  header.md drops the fictional Header.Root subcomponent and the stale
  'menus not migrated' wording (MenuSection label registration is now
  documented from HeaderRoot source); radio-group.md drops three copied
  CheckboxGroup wordings (variant override is Radio's, scalar emits,
  native single-value submit); input-otp.md drops the fictional
  data-complete state and lists the real missing upstream props
- toggle-button disabled row now matches the real CSS hooks
  (:disabled / [aria-disabled], with data-disabled as a marker only)
- part API / CSS classes / interactive states restored per pinned
  sources: button (full class lists + real variable-based global CSS),
  accordion (per-part tables + variant/state lists), card (per-part
  tables + variant list), switch (SwitchGroup snippet + Switch/
  SwitchGroup class lists + states), color-field Group (class list +
  states), input-otp (variant notes, global CSS, class/state lists);
  input-group gains the two upstream usage chapters
- RelatedComponents restored from the pinned componentRelationships
  (first-3, filtered against componentsMap): 64 pages rewritten,
  list-box/slider sections added, 7 empty-mapping pages' fabricated
  entries removed; RelatedShowcases left unmigrated with its real data
  inventory recorded (2 cases, showcase-site cards)
- defaults unified on implementation evidence: granularity (inferred
  day/minute) and visibleYears (full min-max span, no "or 20" fallback);
  HD-03 hand-offs resolved (trigger focus-visible noted for HD-06,
  width guards kept)
- new demos: header-collection-grouping (MenuSection/ListBoxSection
  label wiring), empty-state-collection (collection empty slot);
  empty-state page deduplicated with a boundary compatibility note
- ComponentPreview minHeight/isBgSolid restored per the 30 upstream
  marks; tabs-overflow max-w-full kept after measuring internal scroll
- tests: +3 header registration/demo cases, +1 empty-state collection
  case; full suite 110 files / 1630 tests, typecheck and build:docs
  pass
2026-10-28 22:32:10 +08:00

99 lines
3.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: Input 输入框
description: 接受标准 HTML 属性的原生单行文本输入组件
component: input
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import { Input } from "@heroui-vue/components";
</script>
```
<ComponentPreview name="input-basic" />
::: info 字段组合
校验、标签与错误消息请参阅 [TextField 文本字段](/components/text-field)。
:::
## 示例
### 变体
Input 组件支持两种视觉变体:
- **primary**(默认):标准样式带阴影,适用于大多数场景。
- **secondary**:低强调变体无阴影,适用于 Surface 组件内。
<ComponentPreview name="input-variants" />
### 表面样式
在表面容器内使用 `variant="secondary"` 以应用适合背景的低强调变体。
<ComponentPreview name="input-on-surface" />
### 宽度充满
<ComponentPreview name="input-full-width" />
### 输入类型
<ComponentPreview name="input-types" />
### 受控组件
<ComponentPreview name="input-controlled" />
## 自定义样式
### Tailwind CSS
<ComponentPreview name="input-custom-styles" />
### 全局 CSS
```css
@layer components {
.hv-input {
border-radius: 8px;
}
}
```
## 样式参考
基础类 `.hv-input`;变体 `.hv-input--primary` / `.hv-input--secondary`;宽度修饰符 `.hv-input--full-width`。保留原生 hover / focus / disabled 和 `data-invalid` 状态。
## API 参考
### Input
Input 接受标准 HTML input 属性,以及以下 props:
| Prop | 类型 | 默认值 | 描述 |
| --------------------------------------------------- | -------------------------- | ----------- | --------------------------------- |
| `modelValue` | `string` | — | 受控值,使用 v-model |
| `defaultValue` | `string` | `''` | 非受控初始值 |
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 视觉变体 |
| `fullWidth` | `boolean` | `false` | 是否占满容器宽度 |
| `type` | `string` | `'text'` | 原生输入类型 |
| `invalid` | `boolean` | `false` | 设置 aria-invalid 和 data-invalid |
| `disabled` / `readonly` / `required` | `boolean` | `false` | 原生表单状态 |
| `name` / `placeholder` / `autocomplete` / `pattern` | `string` | — | 原生输入属性 |
| `maxlength` / `minlength` | `number` | — | 长度限制 |
| `min` / `max` / `step` | `string / number` | — | 数值与日期约束 |
### 事件与方法
`update:modelValue` 传递字符串;`@input` / `@change` 保留原生事件。`focus()` 可通过模板引用调用。原生表单 reset 还原非受控初始值;受控值由父组件管理。
不把 React 的 `value` + `onChange` 直接复制为 Vue 状态 API。`className` 改为 `class`。Input 作为 TextField 的控件自动接入其字段上下文(id、name、aria-describedby、禁用/只读/必填等状态继承)。
## 相关组件
[TextField 文本输入框](./text-field) · [TextArea 多行文本框](./textarea) · [Label 标签](./label)