Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Form examples · Advanced

Form with Radio Buttons for React

A plan picker with three radio buttons, Free, Pro and Enterprise, that needs a choice before it continues.

Framework
UI library

Exclusive choices need radio buttons: one plan out of three, and none picked until the user decides. The RadioGroup sits in a FieldSet with a FieldLegend and a FieldDescription, wired to React Hook Form by a Controller, and a Zod enum makes the choice required. Use it for plan selection, payment methods or shipping options.

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

What values can the plan field take?

plan is z.enum(["free", "pro", "enterprise"]). The labels are "Free - $0/month", "Pro - $9/month" and "Enterprise - Contact us", and the form stores the enum value, such as pro.

How does a choice get into React Hook Form?

A Controller named plan renders the group, and each option is a horizontal Field. RadioGroup takes value={field.value ?? null} and passes the next value to field.onChange; each RadioGroupItem has an id its FieldLabel targets.

What error shows if nothing is selected?

The enum's error is "You need to select a plan." Continue with no choice marks the Field invalid and shows it in the FieldError under the description.

Is a plan selected on first paint?

No. useForm gets only the resolver, so plan starts unset and no option is checked. The group's legend is "Select your plan".

Where is the helper text?

After the group, a FieldDescription says "Choose the plan that best fits your needs." The FieldError follows it, inside the same FieldSet.

What does Continue submit?

Continue is a type="submit" button. form.handleSubmit(onSubmit) runs the schema and logs { plan } with the chosen value to the console.