shadcn.io is not affiliated with official shadcn/ui
Textarea examples · Form
Textarea with Error for React
An invalid textarea with a destructive border and an error message under it.
Tell people exactly what's wrong, next to the field that's wrong. Here the Field is marked invalid, which gives the Textarea aria-invalid and a destructive border and ring, and a FieldError under it says how to fix the value.
Preview
Installation
FAQ
When should I show textarea validation errors?
After people leave the field or try to submit, not on the first keystroke: an error that appears while someone is still typing reads as a scolding. Once it's shown, clear it as soon as the value becomes valid.
Why use aria-invalid on the textarea element?
It tells screen readers the value is invalid when the field gets focus, and the Textarea's styles read it to turn the border and ring destructive.
Base UI's Field passes it only to Base UI controls, and the Textarea is a native textarea, so the demo sets aria-invalid on it too.
What makes a good error message for textareas?
Say what's wrong and how to fix it, as Feedback must be at least 10 characters does. Invalid input or Error leaves people guessing.
Can I use colors other than red for error messages?
The error uses the destructive theme color, so change that token to restyle errors everywhere at once. Keep the message text itself, since color alone doesn't reach everyone.
How do I show multiple validation errors for one textarea?
Show the most important one first, such as empty before too short. If several apply at once, list them all inside the FieldError.
FieldError also takes errors, a list of objects with a message such as a form library returns, and renders them as a list.
Related
- Required TextareaA required textarea with a red asterisk
- Textarea with Helper TextA textarea with helper text under it that
- Textarea with Character CountA textarea with a live count of its
- Error State InputAn invalid email field with an error
- Required Field Validation FormA name and an email field marked with
- Textarea with HintA textarea with an Optional hint at the