Textarea
Enter and edit multiple lines of text.
Textarea
Usage
import { Textarea } from "@bedform/ui/textarea";
import { useState } from "react";
export function WorldDescription() {
const [value, setValue] = useState("");
return (
<Textarea
label="World description"
description="Shown on the world selection screen"
name="description"
placeholder="Describe your world"
rows={4}
value={value}
onChange={(event) => setValue(event.currentTarget.value)}
/>
);
}Textarea renders the label, the framed native textarea, and the description and error text. It links them with id and aria-describedby, generating an id when you do not pass one.
Resize
Textarea can be resized horizontally and vertically by default, and it can be customized through its public class.
.ore-textarea > .ore-textarea-control > .ore-textarea-input {
resize: none;
}Selection and scrolling
The ref points to the native <textarea>, which directly provides selectionStart, selectionEnd, setSelectionRange(), scrollTop, and focus().
const ref = useRef<HTMLTextAreaElement>(null);
function selectTitle() {
ref.current?.focus();
ref.current?.setSelectionRange(0, 5);
}
<Textarea ref={ref} label="World description" />;Validation
Set error to show a message. Textarea passes it to setCustomValidity(), sets aria-invalid, and announces it politely.
<Textarea label="World description" error="The description is too long" />Events
The native textarea dispatches input whenever its value changes and change when the edit is committed. In React, onChange fires on every edit, as on any textarea.
API
Textarea accepts every textarea attribute, such as autoComplete, disabled, inputMode, maxLength, minLength, name, placeholder, readOnly, required, rows, spellCheck and wrap, and passes them to the native textarea. className and style apply to the root element instead.
| Prop | Type | Default |
|---|---|---|
description | string | — |
error | string | — |
label | string | — |
Public classes
| Class | Purpose |
|---|---|
.ore-textarea-label | Visible label |
.ore-textarea-control | Textarea frame |
.ore-textarea-input | Native textarea |
.ore-textarea-description | Supporting text |
.ore-textarea-error | Validation message |
CSS variables
Textarea exposes the same styling roles as Textfield with the --ore-textarea-* prefix, including background, shadow, border, foreground, input-foreground, description, error, focus-ring, and caret.
Accessibility
Use a visible label with a matching for and id. Associate supporting or error text through aria-describedby; use the native required, minlength, maxlength, readonly, and disabled attributes for their respective states.