Textarea
A multi-line text field that grows with its text.
textarea-demo.tsx
import { Textarea } from './ui/textarea.tsx'
export default () => (
<Textarea placeholder="Type your message here." aria-label="Message" style="max-width: 24rem" />
)
Installation
dui add textareaOr copy ui/textarea.tsx and ui/textarea.css into your project, with lib/jsx/jsx-runtime.ts, lib/jsx/jsx-dev-runtime.ts, lib/css.d.ts, and lib/theme.css.
Examples
In a field
Share your thoughts about our service.
Also uses Field.
textarea-field.tsx
import { Field, FieldDescription, FieldLabel } from './ui/field.tsx'
import { Textarea } from './ui/textarea.tsx'
export default () => (
<Field style="max-width: 24rem">
<FieldLabel for="feedback">Feedback</FieldLabel>
<Textarea id="feedback" name="feedback" placeholder="Your feedback helps us improve." />
<FieldDescription>Share your thoughts about our service.</FieldDescription>
</Field>
)
Filled, disabled, and invalid
textarea-states.tsx
import { Textarea } from './ui/textarea.tsx'
export default () => (
<div style="display: grid; gap: 0.75rem; width: 100%; max-width: 24rem">
<Textarea value="It grows as you type, up to what the page allows." aria-label="Message" />
<Textarea placeholder="Disabled" aria-label="Disabled" disabled />
<Textarea value="Too short" aria-label="Bio" aria-invalid="true" />
</div>
)
With Datastar
140 left
Also uses Button.
textarea-datastar.tsx
import { Button } from './ui/button.tsx'
import { Textarea } from './ui/textarea.tsx'
// Count what's typed, and stop at 140.
export default () => (
<div data-signals:post="''" style="display: grid; gap: 0.5rem; width: 100%; max-width: 24rem">
<Textarea placeholder="What's happening?" aria-label="Post" maxlength="140" data-bind:post />
<div style="display: flex; align-items: center; justify-content: space-between">
<span
style="color: var(--muted-foreground); font-size: 0.875rem"
data-text="140 - $post.length + ' left'"
>
140 left
</span>
<Button size="sm" data-attr:disabled="!$post.trim()" disabled>
Post
</Button>
</div>
</div>
)
Compared to shadcn/ui
- The same look, and it grows with its text (
field-sizing: content) as shadcn's does. - Its
valueprop is the text inside it, as a<textarea>has no value attribute.