Loading component…
Loading component…
The multi-line twin of the Text Field
To reuse this local React demo, copy all files from the Code tab into the same folder, then import TextArea from ./text-area.
import { useState } from "react";
import { TextArea } from "@/components/ui/text-area";
export function CompanyContext({ onSave }: { onSave: (text: string) => void }) {
const [text, setText] = useState("");
return (
<TextArea
label="Company context"
hint="Added to every chat in this workspace."
value={text}
onChange={(e) => setText(e.target.value)}
maxLength={2000}
counter
minRows={3}
maxRows={8}
expandable
onSubmitShortcut={onSave}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| label | ReactNode | Shown above the field; clicking it focuses the textarea | |
| hint | ReactNode | A quiet line under the field – the error takes its place while there is one | |
| error | ReactNode | Marks the field invalid (red edge and a faint red fill, aria-invalid) and shows the message where the hint was | |
| optional | boolean | false | Adds "Optional" next to the label |
| counter | boolean | false | Shows "120/2,000" under the field, red once a prefilled value is over the limit; needs maxLength |
| minRows | number | 3 | Height when empty, in lines |
| maxRows | number | 10 | It grows with the text up to this many lines, then scrolls inside |
| expandable | boolean | false | A small button in the top corner that gives the field more room – and back |
| expandedRows | number | 16 | Lines while expanded |
| expanded | boolean | Controls the expanded state from outside; pair with onExpandedChange | |
| onExpandedChange | (expanded: boolean) => void | Called when the button gives more or less room | |
| onSubmitShortcut | (value: string) => void | ⌘/Ctrl+Enter – save or send without reaching for the mouse; Enter alone still makes a new line | |
| inputClassName | string | Extra class on the textarea itself, e.g. a monospace font for prompts | |
| className | string | Extra class on the wrapper | |
| ...textarea props | ComponentProps<"textarea"> | Everything else – value, defaultValue, onChange, name, placeholder, required, disabled, readOnly, maxLength, ref – goes to the textarea |
Fills its container; it measures again when its width changes, because the text wraps differently
On touch screens it uses 16px text, so iOS doesn't zoom in on focus, and the corner button grows to 32px
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
@import "tailwindcss"; in your main CSS file.