Radio group
Radio Group allow users to select a single option from a list of mutually exclusive options.
Installation
The above command is for individual installation only. You may skip this step if @nextui-org/react
is already installed globally.
Import
Usage
Disabled
Default Value
With Description
Horizontal
Controlled
You can use the value
and onValueChange
properties to control the radio input value.
Note: NextUI
Radio
also supports native events likeonChange
, useful for form libraries such as Formik and React Hook Form.
Invalid
Slots
-
RadioGroup Slots
- base: Radio group root wrapper, it wraps the label and the wrapper.
- wrapper: Radio group wrapper, it wraps all Radios.
- label: Radio group label, it is placed before the wrapper.
- description: Description slot for the radio group.
- errorMessage: Error message slot for the radio group.
-
Radio Slots
- base: Radio root wrapper, it wraps all elements.
- wrapper: Radio wrapper, it wraps the control element.
- labelWrapper: Label and description wrapper.
- label: Label slot for the radio.
- control: Control element, it is the circle element.
- description: Description slot for the radio.
Custom Styles
You can customize the RadioGroup
and Radio
component by passing custom Tailwind CSS classes to the component slots.
Custom Implementation
In case you need to customize the radio group even further, you can use the useRadio
hook to create your own implementation.
Data Attributes
-
RadioGroup has the following attributes on the
base
element:- data-orientation:
The orientation of the radio group. Based on
orientation
prop.
- data-orientation:
The orientation of the radio group. Based on
-
Radio has the following attributes on the
base
element:- data-selected:
When the radio is checked. Based on
isSelected
prop. - data-pressed: When the radio is pressed. Based on usePress.
- data-invalid:
When the radio is invalid. Based on
validationState
prop. - data-readonly:
When the radio is readonly. Based on
isReadOnly
prop. - data-hover-unselected: When the radio is being hovered and unchecked. Based on useHover.
- data-hover: When the radio is being hovered. Based on useHover.
- data-focus: When the radio is being focused. Based on useFocusRing.
- data-focus-visible: When the radio is being focused with the keyboard. Based on useFocusRing.
- data-disabled:
When the radio is disabled. Based on
isDisabled
prop.
- data-selected:
When the radio is checked. Based on
Accessibility
- Radio groups are exposed to assistive technology via ARIA.
- Each radio is built with a native HTML
<input>
element, which can be optionally visually hidden to allow custom styling. - Full support for browser features like form autofill.
- Keyboard event support for arrows keys.
- Keyboard focus management and cross browser normalization.
- Group and radio labeling support for assistive technology.
API
RadioGroup Props
Prop | Type | Default |
children |
| |
label |
| |
size |
| "md" |
color |
| "primary" |
orientation |
| "vertical" |
name |
| |
value |
| |
defaultValue |
| |
description |
| |
errorMessage |
| |
validate |
| |
validationBehavior |
| "native" |
isDisabled |
| false |
isRequired |
| false |
isReadOnly |
| |
isInvalid |
| false |
validationState |
| false |
disableAnimation |
| false |
classNames |
|
RadioGroup Events
Prop | Type | Default |
onChange |
| |
onValueChange |
|
Radio Props
Prop | Type | Default |
children |
| |
label |
| |
size |
| "md" |
color |
| "primary" |
description |
| |
isDisabled |
| false |
isRequired |
| false |
isReadOnly |
| |
isInvalid |
| false |
disableAnimation |
| false |
classNames |
|