Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Form examples · Advanced

Form with Textarea for React

A bio textarea that needs 10 to 500 characters, with a live character count under it.

Framework
UI library

Length limits keep free text useful: long enough to say something, short enough to read. The Textarea sits in a Field with its FieldLabel, a FieldDescription that counts characters as you type, and a FieldError for the Zod min and max checks, wired to React Hook Form by a Controller. Use it for bios, comments or descriptions with a length limit.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How is the bio textarea registered?

A Controller named bio spreads field onto the Textarea, which has rows={5}, resize-none and the placeholder "Tell us a little about yourself". defaultValues sets bio to "".

What length does the schema allow?

bio is .min(10) with "Bio must be at least 10 characters." and .max(500) with "Bio must not exceed 500 characters." The FieldError shows the one that fails.

How does the character count update?

The FieldDescription prints field.value.length followed by /500 characters, so it follows every keystroke. The length checks still wait for Save, because mode is the default, on submit.

What does an empty bio do?

"" fails .min(10), so Save shows "Bio must be at least 10 characters." The counter starts at 0/500 characters.

What is the order inside the field?

FieldLabel Bio, the Textarea, the FieldDescription with the count, then the FieldError, all in one Field marked invalid while the bio fails.

What does Save submit?

Save is a type="submit" button. form.handleSubmit(onSubmit) logs { bio } to the console after the length checks pass.