4.1 KiB
4.1 KiB
title, description, component, group
| title | description | component | group |
|---|---|---|---|
| TextArea 多行文本框 | 原语级多行文本输入组件,可接受标准 HTML 属性。 | textarea | 组件 |
用法
<script setup lang="ts">
import { TextArea } from "@heroui-vue/components";
</script>
校验、标签与错误消息请参阅 TextField。
示例
变体
TextArea 组件支持两种视觉变体:
primary(默认)— 带阴影的标准样式,适用于大多数场景secondary— 低强调、无阴影,适合在 Surface 等表面背景上使用
表面样式
在 Surface 内使用时,请使用 variant="secondary",以应用适合表面背景的低强调变体。
宽度充满
受控组件
行数与尺寸调整
自定义样式
Tailwind CSS
全局 CSS
若要自定义组件类,可使用 @layer components 指令。
@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 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 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 一起使用。