Textarea
Enter multiple lines of text, such as a message, description or note.
Basic usage
Edit multiline text in the textarea and provide an associated field label.
import { Form, FormField, Textarea } from '@ifhover/leaf-ui';
export function TextareaBasic() {
return (
<Form layout="vertical">
<FormField label="Project description">
<Textarea name="description" placeholder="Describe your new idea" />
</FormField>
</Form>
);
}
Examples
States
Use readOnly, disabled or a FormField error to communicate field state.
import { Form, FormField, Textarea } from '@ifhover/leaf-ui';
export function TextareaStates() {
return (
<Form layout="vertical">
<FormField label="Read only">
<Textarea defaultValue="The public project description." readOnly />
</FormField>
<FormField label="Disabled">
<Textarea placeholder="Currently unavailable" disabled />
</FormField>
<FormField label="Error" error="Add a description.">
<Textarea placeholder="Add a description" />
</FormField>
</Form>
);
}
Automatic height
autoSize adjusts height to the content. Bound the row count with minRows and maxRows; additional content scrolls inside the textarea.
import { Form, FormField, Textarea } from '@ifhover/leaf-ui';
export function TextareaAutoHeight() {
return (
<Form layout="vertical">
<FormField label="Project description">
<Textarea autoSize={{ minRows: 2, maxRows: 6 }} placeholder="Type more content" />
</FormField>
</Form>
);
}
Character count
Set showCount to display the count and maxLength to limit input length.
import { Form, FormField, Textarea } from '@ifhover/leaf-ui';
export function TextareaCount() {
return (
<Form layout="vertical">
<FormField label="Notes">
<Textarea showCount maxLength={120} defaultValue="Start your plan here." />
</FormField>
</Form>
);
}
Manage content with value and onChange. The example derives its length hint from the current value.
import { Form, FormField, Textarea } from '@ifhover/leaf-ui';
import { useState } from 'react';
export function TextareaControlled() {
const [value, setValue] = useState('');
return (
<Form layout="vertical">
<FormField label="Message" help={`${value.length} / 120`}>
<Textarea
value={value}
maxLength={120}
resize="none"
placeholder="Up to 120 characters"
onChange={(event) => setValue(event.target.value)}
/>
</FormField>
</Form>
);
}
Provide a name with FormField or aria-label. Set name for native form submission. Uncontrolled values support form reset; reset controlled values in application state. See Form for form integration.
API
Textarea API
Configure multiline text, length limits and input state.
TextareaAutoSize API
Limit the minimum and maximum rows used by automatic height adjustment.