shadcn.io is not affiliated with official shadcn/ui
Radio Group examples · Form
Radio Group in Form for React
A required notification setting in a form that shows an error when it is submitted with no option picked.
A radio group with no default can be submitted empty. This form asks how to notify you, starts with nothing selected, and on submit either confirms the choice or marks the group invalid with a message. It is built from FieldSet, FieldLegend, FieldDescription and FieldError in plain React state, with no form library, and Base UI renders the group.
Preview
Installation
FAQ
What does the form require?
One of the three options. On submit the handler looks the value up in the options list. With no match it sets the field invalid, and FieldError shows You need to select a notification type.
How is the radio group connected to the state?
The group is controlled, and picking an option stores it and clears the error. It also has name set to type, so a real form submit sends the value. value is the state, and onValueChange receives the next string.
What are the three values?
all is All new messages, mentions is Direct messages and mentions, and none is Nothing. They come from a list at the top of the file.
How does the invalid state look?
The outer Field and each option's Field get invalid, so the legend and the radios turn the destructive color, and FieldError appears under the description.
Related
- Radio Group with Disabled StatesThree radio groups compared: all enabled
- Basic Radio GroupA vertical radio group of three options
- Radio Group with DescriptionsA radio group with a line of muted text
- Required Field Validation FormA name and an email field marked with
- Form with Radio ButtonsA plan picker with three radio buttons
- Radio Group with Custom ContentPricing tiers as selectable cards, each