Displays a form textarea for several lines of text.
The box grows as you type.
import { Label } from "@/components/ui/label"import { VStack } from "@/components/ui/stack"import { Textarea } from "@/components/ui/textarea"import { Text } from "@/components/ui/text"import { widths } from "@/theme/widths"export default function TextareaDemo() { return ( <VStack gap={2} xstyle={widths.sm}> <Label htmlFor="textarea-demo-message">Message</Label> <Textarea id="textarea-demo-message" placeholder="Write a message to the lab." /> <Text size="sm" tone="muted"> The box grows as you type. </Text> </VStack> )}
Set up the token layer and the StyleX compiler, if you have not already. See
Installation, and paste states.ts from the same page.
The textarea's field surface, its focus ring and its invalid ring come from
it. The examples
caption their textareas with a Label or a
Field.
Paste field-state.ts from the same installation page.
Paste this source into the file named in its title.
Change the @/ imports if your project uses different aliases.
Usage
import { Textarea } from "@/components/ui/textarea"
<Textarea placeholder="Write a message to the lab." />
The control is a plain <textarea>, so value, defaultValue, onChange,
name, maxLength and the rest of the element's attributes work as they
always do. Pair it with a Label and match htmlFor to the textarea's id.
The box sizes itself to its content from a two-line floor, so it grows as the
text does instead of scrolling at a fixed height.
rows sets no height here. field-sizing: content measures the content
instead, and the attribute is ignored. Pass a minHeight or a maxHeight
through xstyle to change where the growing starts and stops.
Field
Use a Field to add a label and a description around
the control.
Everyone in the lab can read it.
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"import { Textarea } from "@/components/ui/textarea"import { widths } from "@/theme/widths"export default function TextareaField() { return ( <Field xstyle={widths.sm}> <FieldLabel>Message</FieldLabel> <FieldDescription>Everyone in the lab can read it.</FieldDescription> <Textarea id="textarea-field-message" placeholder="Write a message to the lab." /> </Field> )}
Disabled
Set disabled on Field to disable its control and dim its label, or on a bare control directly.
import { Field, FieldLabel } from "@/components/ui/field"import { Textarea } from "@/components/ui/textarea"import { widths } from "@/theme/widths"export default function TextareaDisabled() { return ( <Field disabled xstyle={widths.sm}> <FieldLabel>Message</FieldLabel> <Textarea id="textarea-disabled-message" placeholder="Write a message to the lab." /> </Field> )}
Invalid
Set invalid on Field to style its control, or aria-invalid on a bare control. The examples show both.
Write at least 20 characters.
Write at least 20 characters.
import { Textarea } from "@/components/ui/textarea"import { Field, FieldLabel, FieldError } from "@/components/ui/field"import { Label } from "@/components/ui/label"import { VStack } from "@/components/ui/stack"export default function TextareaInvalid() { return ( <VStack gap={5} width="100%" maxWidth="24rem"> <VStack gap={2}> <Label htmlFor="textarea-invalid-bare">Message</Label> <Textarea id="textarea-invalid-bare" defaultValue="Hi" aria-invalid aria-describedby="textarea-invalid-bare-error" /> <FieldError id="textarea-invalid-bare-error">Write at least 20 characters.</FieldError> </VStack> <Field invalid> <FieldLabel>Message</FieldLabel> <Textarea defaultValue="Hi" /> <FieldError>Write at least 20 characters.</FieldError> </Field> </VStack> )}
Button
Put the textarea and its submit button in a VStack for a comment form.
import { Button } from "@/components/ui/button"import { HStack, VStack } from "@/components/ui/stack"import { Textarea } from "@/components/ui/textarea"import { widths } from "@/theme/widths"export default function TextareaButton() { return ( <VStack gap={2} xstyle={widths.sm}> <Textarea placeholder="Write a message to the lab." aria-label="Message" /> <HStack justify="end"> <Button>Send message</Button> </HStack> </VStack> )}
Input group
To draw one frame around the textarea and a toolbar, wrap it in an
InputGroup. There is no InputGroupTextarea.
Give the control data-slot="input-group-control" so the group's focus ring
finds it, and textareaStyles.inGroup so it drops its own frame.
Markdown supported
import * as stylex from "@stylexjs/stylex"import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupText } from "@/components/ui/input-group"import { Textarea, textareaStyles } from "@/components/ui/textarea"import { widths } from "@/theme/widths"const styles = stylex.create({ toolbar: { justifyContent: "space-between" },})export default function TextareaInputGroup() { return ( <InputGroup xstyle={widths.sm}> <Textarea placeholder="Leave a comment" aria-label="Comment" data-slot="input-group-control" xstyle={textareaStyles.inGroup} /> <InputGroupAddon align="block-end" xstyle={styles.toolbar}> <InputGroupText>Markdown supported</InputGroupText> <InputGroupButton variant="default">Comment</InputGroupButton> </InputGroupAddon> </InputGroup> )}
API reference
Pass render to replace a part's element or compose it with another component.
Textarea renders a <textarea> and accepts every attribute the element
takes.
Textarea
Prop
Type
Default
disabled
boolean
false
aria-invalid
boolean
—
placeholder
string
—
xstyle
StyleXStyles
—
className
string
—
textareaStyles
The style maps behind the component. Spread them onto any element.
Key
What it is
base
The control: frame, fill, type scale, placeholder, disabled
invalid
The destructive border and ring
inGroup
The frameless form a textarea takes inside an InputGroup
base is three styles, in merge order: the control's own, the shared
states.focusRing, and states.fieldSurface, which is the hairline edge, the
fill and the drop. invalid is states.invalidRing from theme/states.ts. Set
a border of your own through --arene-border-color rather than borderColor.
A flat borderColor replaces the property with all of its conditions, so the ring loses its focus colour.