145a208687
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
129 lines
4.1 KiB
Markdown
129 lines
4.1 KiB
Markdown
---
|
||
title: TextArea 多行文本框
|
||
description: 原语级多行文本输入组件,可接受标准 HTML 属性。
|
||
component: textarea
|
||
group: 组件
|
||
---
|
||
|
||
## 用法
|
||
|
||
```vue
|
||
<script setup lang="ts">
|
||
import { TextArea } from "@heroui-vue/components";
|
||
</script>
|
||
```
|
||
|
||
<ComponentPreview name="textarea-basic" />
|
||
|
||
> 校验、标签与错误消息请参阅 **[TextField](/components/text-field)**。
|
||
|
||
## 示例
|
||
|
||
### 变体
|
||
|
||
TextArea 组件支持两种视觉变体:
|
||
|
||
- **`primary`**(默认)— 带阴影的标准样式,适用于大多数场景
|
||
- **`secondary`** — 低强调、无阴影,适合在 Surface 等表面背景上使用
|
||
|
||
<ComponentPreview name="textarea-variants" />
|
||
|
||
### 表面样式
|
||
|
||
在 [Surface](/components/surface) 内使用时,请使用 `variant="secondary"`,以应用适合表面背景的低强调变体。
|
||
|
||
<ComponentPreview name="textarea-on-surface" />
|
||
|
||
### 宽度充满
|
||
|
||
<ComponentPreview name="textarea-full-width" />
|
||
|
||
### 受控组件
|
||
|
||
<ComponentPreview name="textarea-controlled" />
|
||
|
||
### 行数与尺寸调整
|
||
|
||
<ComponentPreview name="textarea-rows" />
|
||
|
||
## 自定义样式
|
||
|
||
### Tailwind CSS
|
||
|
||
<ComponentPreview name="textarea-custom-styles" />
|
||
|
||
### 全局 CSS
|
||
|
||
若要自定义组件类,可使用 `@layer components` 指令。
|
||
|
||
```css
|
||
@layer components {
|
||
.hv-textarea {
|
||
@apply rounded-xl border border-border bg-surface px-4 py-3 text-sm leading-6 shadow-sm;
|
||
|
||
&:hover,
|
||
&[data-hovered="true"] {
|
||
@apply bg-surface-secondary border-border/80;
|
||
}
|
||
|
||
&:focus-visible,
|
||
&[data-focus-visible="true"] {
|
||
@apply border-accent ring-2 ring-accent/20;
|
||
}
|
||
|
||
&[data-invalid="true"] {
|
||
@apply border-danger bg-danger-soft text-danger;
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
## 样式参考
|
||
|
||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||
|
||
### CSS 类
|
||
|
||
#### 基础类 [!toc]
|
||
|
||
- `.hv-textarea` – 底层 `<textarea>` 元素样式
|
||
|
||
### 交互状态
|
||
|
||
- **悬停**:`:hover` 或 `[data-hovered="true"]`
|
||
- **可见焦点**:`:focus-visible` 或 `[data-focus-visible="true"]`
|
||
- **无效**:`[data-invalid="true"]`
|
||
- **禁用**:`:disabled` 或 `[aria-disabled="true"]`
|
||
|
||
## API 参考
|
||
|
||
### TextArea
|
||
|
||
TextArea 接受所有标准 HTML `<textarea>` 属性,以及以下属性:
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| -------------- | --------------------------- | ----------- | -------------------------------- |
|
||
| `modelValue` | `string` | - | 受控值(`v-model`) |
|
||
| `defaultValue` | `string` | - | 非受控初始值 |
|
||
| `rows` | `number` | `3` | 可见文本行数 |
|
||
| `fullWidth` | `boolean` | `false` | 是否占满容器宽度 |
|
||
| `variant` | `'primary' \| 'secondary'` | `'primary'` | 视觉变体 |
|
||
| `invalid` | `boolean` | - | 展示无效状态;与父级字段状态合并 |
|
||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||
|
||
原生属性(`name`、`placeholder`、`disabled`、`readonly`、`required`、`cols`、`wrap`、`autocomplete`、`minlength`、`maxlength` 等)透传到真实 `<textarea>`。在 TextField 内时,`name`/禁用/只读/必填/校验/ARIA 由字段上下文统一管理。
|
||
|
||
### 事件与暴露
|
||
|
||
| 接口 | 说明 |
|
||
| ------------------- | ---------------------------------------------- |
|
||
| `update:modelValue` | 值变化时发出;配合 `v-model` |
|
||
| `focus()` | 模板 ref 暴露,聚焦真实 `<textarea>` |
|
||
| `element` | 模板 ref 暴露的底层 `HTMLTextAreaElement` 引用 |
|
||
|
||
> 对于 `isInvalid`、`isRequired` 等校验 prop 以及错误处理,请将 TextArea 作为子组件与 **[TextField](/components/text-field)** 一起使用。
|
||
|
||
## 相关组件
|
||
|
||
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [Label 标签](./label)
|