Textarea
Standalone multiline text field with count, resize, and status states.
Textarea
Basic Usage
Textarea
Loading demo...
Interaction Contract
v-modelowns a string value and emits bothupdate:modelValueandinputon native input.- Wrapper
classandstylestay on the root; other attrs are forwarded to the inner<textarea>. showCountdisplays the current length; whenmaxLengthis present the format iscurrent/max.statusonly changes visual state. Put validation copy in the host form item.focus()andblur()are exposed for form flows and editor shortcuts.
API
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue / v-model | string | '' | Textarea value. |
placeholder | string | '' | Placeholder text. |
rows | number | 4 | Native textarea row count. |
disabled | boolean | false | Native disabled state. |
readonly | boolean | false | Native read-only state. |
maxLength | number | - | Native maximum length and count denominator. |
showCount | boolean | false | Show character count footer. |
resize | 'none' | 'vertical' | 'horizontal' | 'both' | 'vertical' | CSS resize behavior. |
status | 'default' | 'success' | 'error' | 'default' | Visual validation state. |
Events
| Event | Params | Description |
|---|---|---|
update:modelValue | (value: string) | v-model update. |
input | (value: string) | Mirrors value updates. |
focus | (event: FocusEvent) | Native focus event. |
blur | (event: FocusEvent) | Native blur event. |
Exposed Methods
| Method | Description |
|---|---|
focus() | Focus the native textarea. |
blur() | Blur the native textarea. |
textareaRef | Native textarea ref. |
Slots
TxTextarea does not expose slots. Keep labels, help text, counters beyond showCount, and validation messages in the surrounding form item.
Best Practices
- Use
maxLengthwithshowCountfor bounded notes, summaries, and prompts. - Keep
resize="vertical"for normal forms; usenoneonly when the surrounding layout already controls height. - Use
statusas a visual hint and keep accessible validation messages outside the component. - Forward
id,name, and form-related attrs directly; the component passes them to the textarea.
Review Notes
- Source:
packages/tuffex/packages/components/src/textarea/src/TxTextarea.vueconfirms attr forwarding,class/styleplacement, count formatting, resize classes, status classes, focus state, and exposed helpers. - Verified coverage: Coverage:
packages/tuffex/packages/components/src/textarea/__tests__/textarea.test.tscovers value/placeholder/rows, attr forwarding,input/update:modelValue, count text, status/resize classes, and focus/blur helper exposure. - Export:
packages/tuffex/packages/components/src/textarea/index.tswraps the component withwithInstalland exportsTxTextareaInstance.
Source
查看源码
packages/tuffex/packages/components/src/textarea/index.ts