Components
- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Dialog
- Empty
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Label
- Menu
- Meter
- Number Field
- Pagination
- Popover
- Preview Card
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Skeleton
- Slider
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Toolbar
- Tooltip
Textarea
A native textarea element.
import { Textarea } from "@/components/ui/textarea"
export default function TextareaDemo() {
return <Textarea placeholder="Type your message here" />
}
Installation
npx love-ui@latest add textareaUsage
import { Textarea } from "@/components/ui/textarea"<Textarea />Examples
For accessible labelling and validation, prefer using the Field component to wrap textareas. See the related example: Textarea field.
Small Size
import { Textarea } from "@/components/ui/textarea"
export default function TextareaSm() {
return <Textarea size="sm" placeholder="Type your message here" />
}
Large Size
import { Textarea } from "@/components/ui/textarea"
export default function TextareaLg() {
return <Textarea size="lg" placeholder="Type your message here" />
}
Disabled
import { Textarea } from "@/components/ui/textarea"
export default function TextareaDisabled() {
return <Textarea placeholder="Can't type here" disabled />
}
With Label
import { useId } from "react"
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
export default function TextareaWithLabel() {
const id = useId()
return (
<div className="flex flex-col items-start gap-2">
<Label htmlFor={id}>Message</Label>
<Textarea id={id} placeholder="Type your message here" />
</div>
)
}
Form Integration
"use client"
import * as React from "react"
import { Button } from "@/components/ui/button"
import {
Field,
FieldControl,
FieldError,
FieldLabel,
} from "@/components/ui/field"
import { Form } from "@/components/ui/form"
import { Textarea } from "@/components/ui/textarea"
export default function TextareaForm() {
const [loading, setLoading] = React.useState(false)
const onSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
const formData = new FormData(e.currentTarget)
setLoading(true)
await new Promise((r) => setTimeout(r, 800))
setLoading(false)
alert(`Message: ${formData.get("message") || ""}`)
}
return (
<Form onSubmit={onSubmit} className="max-w-64">
<Field>
<FieldLabel>Message</FieldLabel>
<FieldControl
name="message"
placeholder="Type your message here"
disabled={loading}
required
render={(props) => <Textarea {...props} />}
/>
<FieldError>This field is required.</FieldError>
</Field>
<Button type="submit" disabled={loading}>
Submit
</Button>
</Form>
)
}
Comparing with shadcn
Compared to shadcn/ui, our Textarea component includes size variants (sm, default, lg) for better density control. For visual consistency, if you're using size="lg" on other form elements like inputs, you should add the same size to textareas as well.