Textarea
Neobrutalist-styled multi-line text input with variants, sizes, and v-model.
Demo
变体
尺寸
状态
v-model 绑定
值:
Installation
pnpm dlx brutx-vue@latest add textareaUsage
<script setup>
import { ref } from 'vue'
import { Textarea } from 'brutx-ui-vue'
const message = ref('')
</script>
<template>
<Textarea v-model="message" placeholder="Type your message here..." />
</template>With Label
<script setup>
import { ref } from 'vue'
import { Textarea, Label } from 'brutx-ui-vue'
const bio = ref('')
</script>
<template>
<div class="space-y-2">
<Label for="bio">Bio</Label>
<Textarea id="bio" v-model="bio" placeholder="Tell us about yourself..." />
</div>
</template>Disabled State
<script setup>
import { Textarea } from 'brutx-ui-vue'
</script>
<template>
<Textarea disabled placeholder="Disabled textarea" />
</template>Readonly State
Set a readonly textarea via the readonly prop. In readonly state, the textarea is not editable but remains focusable for text selection. The cursor style is cursor-default, and opacity is not reduced (unlike disabled).
<script setup>
import { ref } from 'vue'
import { Textarea } from 'brutx-ui-vue'
const content = ref('This is readonly content. Users can select and copy text but cannot modify it. Suitable for displaying agreement terms, history records, etc.')
</script>
<template>
<Textarea v-model="content" readonly />
</template>Error Messages
Use variant="error" and errorMessage to show an error below the textarea. The message uses role="alert" for screen reader announcements.
<script setup>
import { ref } from 'vue'
import { Textarea } from 'brutx-ui-vue'
const message = ref('')
</script>
<template>
<Textarea
v-model="message"
variant="error"
error-message="A message is required"
placeholder="Enter a message..."
/>
</template>Variants
| Variant | Description |
|---|---|
default | Standard border |
error | Destructive border with primary focus shadow |
success | Success border with secondary focus shadow |
Set different border styles via the variant prop:
<template>
<Textarea variant="default" placeholder="Default variant" />
<Textarea variant="error" placeholder="Error variant" />
<Textarea variant="success" placeholder="Success variant" />
</template>Sizes
| Size | Padding | Font Size |
|---|---|---|
sm | px-3 py-2 | text-sm |
default | px-4 py-3 | text-base |
lg | px-5 py-4 | text-lg |
Set different sizes via the size prop:
<template>
<Textarea size="sm" placeholder="Small size" />
<Textarea size="default" placeholder="Default size" />
<Textarea size="lg" placeholder="Large size" />
</template>Programmatic Control
Access the component instance via ref to call the following methods:
<script setup>
import { ref } from 'vue'
import { Textarea } from 'brutx-ui-vue'
const textareaRef = ref(null)
function handleFocus() {
textareaRef.value?.focus()
}
</script>
<template>
<Textarea ref="textareaRef" placeholder="Click button to focus" />
<button @click="handleFocus">Focus Textarea</button>
</template>API Reference
| Name | Type | Default | Description |
|---|---|---|---|
modelValue | string | undefined | undefined | The textarea string value, synchronized through v-model. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
variant | "default" | "error" | "success" | undefined | "default" | The textarea border and state style. The error variant displays an error message when errorMessage is non-empty. |
DetailsDeclared typeNonNullable<"default" | "success" | "error" | null | undefined> | undefined Literal values
Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
size | "default" | "lg" | "sm" | undefined | "default" | The textarea size variant, controlling its height, padding, and text size. |
DetailsDeclared typeNonNullable<"default" | "lg" | "sm" | null | undefined> | undefined Literal values
Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
resize | "both" | "horizontal" | "none" | "vertical" | undefined | "none" | The directions in which the browser allows the user to resize the textarea. |
DetailsDeclared typeNonNullable<"vertical" | "horizontal" | "none" | "both" | null | undefined> | undefined Literal values
Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
disabled | boolean | undefined | false | Disables the native textarea, preventing focus and editing. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
readonly | boolean | undefined | false | Prevents editing while retaining focus, text selection, and copying. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
placeholder | string | undefined | undefinedRuntime fallback: | Hint text displayed when the textarea is empty. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
errorMessage | string | undefined | undefined | The error message displayed below the textarea with role="alert" when variant is error and the text is non-empty. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
ariaLabel | string | undefined | undefined | The accessible name passed to the native textarea. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
ariaLabelledby | string | undefined | undefined | The ID of the element labeling the native textarea. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
ariaDescribedby | string | undefined | undefined | The description element ID; when omitted and an error is shown, automatically references the error message. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
ariaInvalid | boolean | undefined | undefined | Explicitly sets the invalid state. When omitted, it is true while an error message is displayed. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
ariaErrormessage | string | undefined | undefined | The error message element ID, also used for the built-in error message. When omitted, the built-in message uses an automatically generated ID. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
ariaRequired | boolean | undefined | undefined | Declares the required state of the textarea to assistive technology. |
DetailsDeclared typeboolean | undefined Literal values
Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
class | string | undefined | undefined | Custom CSS classes merged onto the native textarea element. |
DetailsDeclared typestring | undefined Default value details
Sourcepackages/ui/src/components/textarea/Textarea.vue | |||
| Name | Signature or type | Description |
|---|---|---|
@update:modelValue | [value: string] | Emits the new string value on user input. Intermediate IME composition values are suppressed, and the final value is committed when composition ends. |
DetailsDeclared type[value: string] Sourcepackages/ui/src/components/textarea/Textarea.vue | ||
| Name | Signature or type | Description |
|---|---|---|
focus | () => void | undefined | Moves focus to the native textarea. |
DetailsDeclared type() => void | undefined Sourcepackages/ui/src/components/textarea/Textarea.vue | ||
blur | () => void | undefined | Removes focus from the native textarea. |
DetailsDeclared type() => void | undefined Sourcepackages/ui/src/components/textarea/Textarea.vue | ||
select | () => void | undefined | Selects the text in the native textarea. |
DetailsDeclared type() => void | undefined Sourcepackages/ui/src/components/textarea/Textarea.vue | ||
ref | Ref<HTMLTextAreaElement | null, HTMLTextAreaElement | null> | The internal native textarea reference. Vue unwraps top-level refs on public component instances, so the instance ref property provides the HTMLTextAreaElement. |
DetailsDeclared typeRef<HTMLTextAreaElement | null, HTMLTextAreaElement | null> Literal values
Sourcepackages/ui/src/components/textarea/Textarea.vue | ||
Accessibility
- ARIA attributes: Supports
aria-label,aria-labelledby,aria-describedby,aria-invalid,aria-requiredattributes for assistive technologies (e.g. screen readers)
<script setup>
import { ref } from 'vue'
import { Textarea } from 'brutx-ui-vue'
const bio = ref('')
</script>
<template>
<Textarea
v-model="bio"
aria-label="Bio"
aria-required="true"
aria-invalid="false"
placeholder="Enter your bio..."
/>
</template>Customization
Textarea defaults to resize-none. To allow resizing, override with a custom class:
<script setup>
import { Textarea } from 'brutx-ui-vue'
</script>
<template>
<Textarea class="resize-y" placeholder="Resizable textarea" />
</template>