Textarea
A flexible multi-line text input with character counting and validation states. Designed for collecting longer form content with accessibility in mind.
Installation
Add Text Area to your project with the CK-UI CLI. It copies the source into your project, so the code is yours to change.
- Adds
Textarea.tsxField.tsxLabel.tsxto your CK-UI folder (src/components/ck-ui by default)- Installs
@radix-ui/react-label@radix-ui/react-slotif your project does not have them yet
First time with CK-UI in this project? Run npx ck-ui-cli@latest init once before adding components. The installation guide explains what it sets up.
Manual installationInstall the packages and copy the files yourself.
Install the following dependencies
Run these commands in your terminal to install the required packages
Add the Field component
Textarea imports ./Field, so add this file next to it
Add the Label component
Textarea imports ./Label, so add this file next to it
Create or update your Textarea component
Copy this code to create your Textarea component
Test Your Component
- 1. Add the component to a test page
- 2. Check all props and variants work as expected
- 3. Verify responsive behavior
- 4. Test with different content/data
- 5. Ensure accessibility features work correctly
Character Counter
Track and limit the number of characters with a built-in counter component.
Disabled State
Textareas can be disabled to prevent user interaction.
Error State
Display error states to indicate validation issues or input errors.
Full Example
A complete example with label, textarea, character counter, and hint text.
This is a hint text to help user.
API Reference
The Textarea component is a custom implementation built with native HTML textarea elements and enhanced with additional features like character counting and custom resizing.
Textarea.Root
The main textarea component that users interact with.
| Prop | Type | Default | Description |
|---|---|---|---|
invalid | "boolean" | "false" | Error styling and aria-invalid. Also set automatically inside Field.Root invalid. (The old error prop still works but is deprecated.) |
value | "string" | "undefined" | The controlled value of the textarea. |
defaultValue | "string" | "undefined" | The initial value when uncontrolled. |
onChange | "(event: React.ChangeEvent<HTMLTextAreaElement>) => void" | "undefined" | Native change event handler, compatible with form libraries. |
onValueChange | "(value: string) => void" | "undefined" | Called with the new text on every change. |
resizable | "boolean" | "true" | Shows the drag handle for resizing (mouse, touch and pen). |
disabled | "boolean" | "false" | Prevents interaction. Also taken from Field.Root disabled. |
className | "string" | "undefined" | Classes for the <textarea> element. |
wrapperClassName | "string" | "undefined" | Classes for the outer wrapper. |
Textarea.CharCounter
A component that displays the current character count and optional maximum limit.
| Prop | Type | Default | Description |
|---|---|---|---|
current | "number" | "undefined" | Override the counted length. By default the counter reads the textarea value. |
max | "number" | "undefined" | The maximum character count, shown as current/max. Without it only the current count is shown. |
className | "string" | "undefined" | Additional CSS classes to apply to the character counter. |
Used in these blocks
Block families with at least one block built on this component. Each page previews its blocks and lists the components and packages they use.