Radio

Radios allow users to select a single option from a list of mutually exclusive options. All possible options are exposed up front for users to compare. Radio implementation is based on @react-aria/radio

import { Radio } from '@nextui-org/react';

Anatomy

  • Radio.Group: Radio group component that holds all radios in a group and provides a common API for managing the group state.
  • Radio: Radio component that represents a single option

Default

Radio.Group accepts multiple Radio elements as children. Each Radio represents an item that can only be checked singularly, labeled by its children.

Note: A Radio cannot be used outside of a Radio.Group.

Disabled

Unusable and un-clickable Radio.

Sizes

Change the size of the entire Radio including padding, font-size and border with the size property.

Colors

You can change the color with color prop.

Label Colors

You can change the Radio label color with labelColor prop.

Squared

You can change the full style to a squared Radio with the isSquared prop.

Description

You can add a description to the Radio with description prop.

Invalid

Radios can display a validation state to communicate to the user if the current value is invalid. Implement your own validation logic in your app and pass invalid to the Radio.Group via the validationState prop.

Row

Radio groups are vertically oriented by default. The orientation prop can be used to change the orientation to horizontal.

Disable Animation

You can disable the animation of the entire Radio with the property disableAnimation.

Controlled vs Uncontrolled

An initial, uncontrolled value can be provided to the Radio.Group using the defaultValue prop. Alternatively, a controlled value can be provided using the value prop.

Note: See React's documentation on uncontrolled components for more info.

Events

Radio.Group accepts an onChange prop, which is triggered when a user checks an item from the list. The example below uses onChange to log how the user is interacting with the component.

A11y: If a visible label isn't specified for a Radio.Group, an aria-label must be provided for accessibility. If the field is labeled by a separate element, an aria-labelledby prop must be provided using the id of the labeling element instead. Radio elements within a group should always have a visible label.

Keyboard Interactions

KeyDescription
ArrowDown ArrowRightWhen focus is on an item, moves focus to the next item.
ArrowUp ArrowLeftWhen focus is on an item, moves focus to the previous item.

APIs

Radio.Group Props

AttributeTypeDescriptionDefault
children*ReactNode[]The content of the radio group. It must be a list of radio items.-
labelReactNodeThe content to display as the label.-
valuestringThe current value (controlled).-
defaultValuestringThe default value (uncontrolled).-
colorSimpleColors stringChange radio group colorprimary
labelColorSimpleColors stringChange radio group label colordefault
sizeNormalSizesSize of all radios in the groupmd
namestringThe name of the RadioGroup, used when submitting an HTML form. See MDN-
orientationhorizontal verticalThe axis the radio group items should align with.vertical
validationStatevalid invalidWhether the input should display its "valid" or "invalid" visual styling.-
isDisabledbooleanWhether the radio group items are disabled.false
isReadOnlybooleanWhether the input can be selected but not changed by the user.false
isRequiredbooleanWhether user input is required on the input before form submission. Often paired with the necessityIndicator prop to add a visual indicator to the input.false
cssStitches.CSSOverride Default CSS style-
askeyof JSX.IntrinsicElementsChanges which tag component outputsdiv

Radio.Group Events

AttributeTypeDescriptionDefault
onChange(value: T) => voidHandler that is called when the value changes.-

Radio.Group Accessibility Props

AttributeTypeDescriptionDefault
idstringThe element's unique identifier. See MDN-
aria-labelstringDefines a string value that labels the current element-
aria-labelledbystringIdentifies the element (or elements) that labels the current element-
aria-describedbystringIdentifies the element (or elements) that describes the object.-
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.-
aria-errormessagestringIdentifies the element that provides an error message for the object.-

Radio Props

AttributeTypeDescriptionDefault
value*stringThe value of the radio button, used when submitting an HTML form. See MDN-
childrenReactNodeThe label for the Radio. Accepts any renderable node.-
colorSimpleColors stringThe radio colorprimary
labelColorSimpleColors stringThe radio label colordefault
descriptionstring ReactNodeThe radio description text-
sizeNormalSizesThe radio sizemd
isSquaredbooleanWhether the radio button has squared cornersfalse
isDisabledbooleanWhether the radio button is disabled or not. Shows that a selection exists, but is not available in that circumstance.false
disableAnimationbooleanWhether the checkbox has animationsfalse
autoFocusbooleanWhether the element should receive focus on render.false
cssStitches.CSSOverride Default CSS style-
askeyof JSX.IntrinsicElementsChanges which tag component outputslabel

Radio Events

AttributeTypeDescriptionDefault
onFocus(e: FocusEvent) => anyHandler that is called when the element receives focus.-
onBlur(e: FocusEvent) => anyHandler that is called when the element loses focus.-
onFocusChange(isFocused: boolean) => voidHandler that is called when the element's focus status changes.-
onKeyDown(e: KeyboardEvent) => anyHandler that is called when a key is pressed.-
onKeyUp(e: KeyboardEvent) => anyHandler that is called when a key is released.-

Radio Accessibility Props

AttributeTypeDescriptionDefault
idstringThe element's unique identifier. See MDN-
aria-labelstringDefines a string value that labels the current element-
aria-labelledbystringIdentifies the element (or elements) that labels the current element-
aria-describedbystringIdentifies the element (or elements) that describes the object.-
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.-

Radio types

Simple Colors

type SimpleColors =
  | 'default'
  | 'primary'
  | 'secondary'
  | 'success'
  | 'warning'
  | 'error';

Normal Sizes

type NormalSizes = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
gradient blue backgroundgradient violet background