组件 · 输入
Textarea
A multi-line text field for forms, at least three lines high, with an optional character counter.
import { Textarea } from "@botiverse/raft-ui";A textarea takes several lines of text in a form: a description, a note, instructions for an agent. It has the same ink border and states as an Input, is at least three lines of field text high (96px on a phone, 90px on a desktop), and people can drag it taller.
When to use
| Situation | Use |
|---|---|
| Several lines of text that are saved with a form | Textarea |
| One line of text | Input |
| A message that is sent | Composer |
Anatomy
Textarea: the field. Required.TextareaGroup: holds the textarea and its counter. Needed only with a counter.TextareaCounter: the count and the limit, below the field at its end (72/280).
States
- Invalid:
data-invalidgives the textarea adanger-strongborder; the message goes in the field (Field). - Over the limit: the counter turns bold
danger-strongonce the count passes the limit. - Disabled: the shared disabled look (States), and it can no longer be resized. Disabled wins over invalid.
Behavior
- Let people drag the textarea taller. It never gets shorter than three lines of field text.
- To make it grow with its content, use
field-sizing-contenttogether with a maximum height, so a long draft scrolls inside the field instead of pushing the page down. - Add a counter when the value has a limit. Pass the current value and the limit to
TextareaCounter. - Leave out the native
maxLengthwhen the counter shows the limit:maxLengthstops typing at the limit, so the counter could never show that the text is over it.
Accessibility
Textarea renders a native <textarea>; it is not a Base UI control.
- Name it with a
FieldLabelwhosehtmlFormatches the textarea'sid(Field). data-invalidalso setsaria-invalid.- Reference the counter from
aria-describedbywhen the limit matters, so it is read with the field.
API
Textarea
接受其元素的全部属性。
TextareaCounter
| Prop | 类型 | 默认值 |
|---|---|---|
| number | ||
| (value: string) => number | ||
| number | ||
| string |
Also takes the attributes of its element.
TextareaGroup
接受其元素的全部属性。
相关组件
改动
- 0.10.0 · Breaking ChangesField frames (
Input,Textarea,InputGroup,Select,Combobox,ComboboxSelect,Composer, optionCard,SearchTrigger) are drawn at 1px inline-fieldinstead of 1.5px, on the phone too. - 0.4.0 · Breaking ChangesInvalid-state styling now keys off
data-invalidinstead ofaria-invalid.Input,Textarea, and form controls style the error visual fromdata-invalidand mirror it toaria-invalid; passingaria-invalidalone no longer shows the error style. Update callers to passdata-invalid. ([b3786da](https://github.com/botiverse/rui/commit/b3786da))