@biem/ui

Textarea

A field that lets users enter several lines of text, such as a note.

A textarea takes several lines of text from users, such as a note, a reason or a message. It accepts every attribute of the native textarea element, fills the width of its container and grows with the text that users enter. A label names the text that the textarea asks for, and htmlFor on the label refers to the id of the textarea, so a click on the label moves the focus into the textarea.

Usage

textarea-default.tsx
import { Field, FieldLabel } from "@biem/ui/components/ui/field";
import { Textarea } from "@biem/ui/components/ui/textarea";

export function TextareaDefault() {
	return (
		<div className="w-full max-w-sm">
			<Field>
				<FieldLabel htmlFor="delivery-instructions">Delivery instructions</FieldLabel>
				<Textarea id="delivery-instructions"/>
			</Field>
		</div>
	);
}

Examples

With Placeholder

Some entries are easier to write when users know what to include, such as the details a complaint needs. While the textarea is empty, placeholder offers such a hint, and the hint disappears as soon as users type, so the label still names what the textarea asks for.

Default Value

Prepared text spares users from writing the same words again, such as the standard note on a recurring order. With defaultValue the textarea starts with that text, and users adjust only what differs this time.

Controlled

Sometimes the application needs the text while users are still writing it, for example to save a draft or to allow sending only once there is something to send. Through value and onChange it holds the text itself, so other parts of the interface can read, replace or clear it.

Disabled

Not every note applies to every order, such as a note for the courier when users collect the goods in the store. Marked as disabled, the textarea accepts neither focus nor input and exposes its state to assistive technology. Its text also stays out of the submitted form, so the order carries no note that no longer applies.

Read-Only

Approved texts, such as a statement that a store manager has signed, belong in front of users without being open to change. Unlike a disabled textarea, one with readOnly stays focusable, so users reach it with the keyboard, and the form submits its text together with the other values.

Invalid

Before a form goes out, users need to see which text still falls short, such as a report that lacks a required detail. Once aria-invalid is set, the textarea shows the error and reports it to assistive technology, so users find the entry that needs their attention.

API Reference

Propvalue
Typestring | readonly string[] | number
Default–
DescriptionSets the value of the textarea and makes it controlled. Update it in onChange.
PropdefaultValue
Typestring | number | readonly string[]
Default–
DescriptionSets the value of the textarea at first render. The textarea then tracks its value itself.
ProponChange
Type(event: ChangeEvent<HTMLTextAreaElement>) => void
Default–
DescriptionRuns when users change the value. It receives the change event, and event.target.value holds the value that follows.
Propplaceholder
Typestring
Default–
DescriptionShows a hint in muted text while the textarea is empty. The hint disappears as soon as users type, so it doesn't replace the label.
Propdisabled
Typeboolean
Defaultfalse
DescriptionPrevents users from focusing and changing the textarea, dims it and exposes the disabled state to assistive technology. A disabled textarea is not submitted with the form.
PropreadOnly
Typeboolean
Defaultfalse
DescriptionPrevents users from changing the value. Unlike a disabled textarea, it stays focusable and is submitted with the form.
Proprequired
Typeboolean
Defaultfalse
DescriptionRequires users to fill in the textarea before they can submit the form.
Proparia-invalid
Typeboolean | "false" | "true" | "grammar" | "spelling"
Default–
DescriptionMarks the value as invalid for assistive technology. With true, the border takes the destructive color.