DocsBlog

Get Started

Components

Data Grid

Signals

Styling

Theming

↑↓Navigate
↵Select
EscClose
  • 1.8.0

  • Day

    Night

    Preview

    Switch mode
  • cerberus

    acheron

    elysium

    oceanus

Get Started
Components
Data Grid
Signals
Styling
Theming

Concepts

OverviewCompositionCerberus ContextTesting

Layout

Aspect RatioBleedBoxCenterContainerContainer QueryDividerFlexFloatGridGroupLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTA ModalDate PickerDialogFieldFieldsetFile UploaderIconButtonInputLoading StatesMarqueeMenuNotificationsNumber InputPaginationPin InputPopoverProgress IndicatorsPrompt ModalRadioRatingSelectSliderSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFormat Relative TimeFrameHighlightJSON Tree ViewLocalePortalPresenceShowSwapsplitPropsTheme

Radio

The Radio component allows users to select one option from a set of choices.

  • npm
  • source
  • recipe
  • Ark
View as Markdown
Open this page in Markdown
Anthropic
Open in Claude
Ask questions about this page
OpenAI
Open in ChatGPT
Ask questions about this page

Import

import { RadioGroup, Radio, RadioParts } from '@cerberus/react'

Usage

The Radio component is a controlled component that can be used to select one option from a set. Simply wrap the Radio components in a RadioGroup component to create a group of radio buttons.

Loading example...

Orientation

The RadioGroup component supports two orientations: horizontal, and vertical. The default orientation is horizontal.

Loading example...

Sizes

The Radio component supports two sizes: sm, and md.

Loading example...

Customizing

To customize the Radio, use style props or the Primitives.

Loading example...

Primitives

You can utilize the primitive components or the css prop to customize the radio.

ComponentDescription
RadioGroupRootThe context provider for the RadioGroup parts
RadioGroupLabelThe label of the radio
RadioGroupIndicatorThe indicator of the radio state
RadioGroupItemThe container of the label and control of the radio
RadioGroupItemTextThe label for a single radio
RadioGroupItemControlThe visual input of a single radio
RadioGroupItemHiddenInputThe native input for the radio

API

Root

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.
defaultValuestringfalseundefinedThe initial value of the checked radio when rendered.
Use when you don't need to control the value of the radio group.
disabledbooleanfalseundefinedIf true, the radio group will be disabled
formstringfalseundefinedThe associate form of the underlying input.
idstringfalseundefinedThe unique identifier of the machine.
idsPartial<{ root: string, label: string, indicator: string, item: (value: string) => string, itemLabel: (value: string) => string, itemControl: (value: string) => string, itemHiddenInput: (value: string) => string }>falseundefinedThe ids of the elements in the radio. Useful for composition.
invalidbooleanfalseundefinedIf true, the radio group is marked as invalid.
namestringfalseundefinedThe name of the input fields in the radio
(Useful for form submission).
onValueChange(details: ValueChangeDetails) => voidfalseundefinedFunction called once a radio is checked
orientation'horizontal' | 'vertical'falseundefinedOrientation of the radio group
readOnlybooleanfalseundefinedWhether the radio group is read-only
requiredbooleanfalseundefinedIf true, the radio group is marked as required.
valuestringfalseundefinedThe controlled value of the radio group

Data Attributes

AttributeDescription / Value
data-scoperadio-group
data-partroot
data-orientationThe orientation of the radio-group
data-disabledPresent when disabled
data-invalidPresent when invalid
data-requiredPresent when required

Indicator

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scoperadio-group
data-partindicator
data-disabledPresent when disabled
data-orientationThe orientation of the indicator

ItemControl

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scoperadio-group
data-partitem-control
data-activePresent when active or pressed

ItemHiddenInput

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Item

Props

PropTypeRequiredDefaultDescription
valuestringtrueundefinedundefined
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.
disabledbooleanfalseundefinedundefined
invalidbooleanfalseundefinedundefined

ItemText

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Label

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scoperadio-group
data-partlabel
data-orientationThe orientation of the label
data-disabledPresent when disabled
data-invalidPresent when invalid
data-requiredPresent when required

RootProvider

Props

PropTypeRequiredDefaultDescription
valueUseRadioGroupReturntrueundefinedundefined
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Context

API:

PropertyTypeDescription
valuestring | nullThe current value of the radio group
setValue(value: string) => voidFunction to set the value of the radio group
clearValueVoidFunctionFunction to clear the value of the radio group
focusVoidFunctionFunction to focus the radio group
getItemState(props: ItemProps) => ItemStateReturns the state details of a radio input

Accessibility

Complies with the Radio WAI-ARIA design pattern.

Keyboard Support

KeyDescription
TabMoves focus to either the checked radio item or the first radio item in the group.
SpaceWhen focus is on an unchecked radio item, checks it.
ArrowDownMoves focus and checks the next radio item in the group.
ArrowRightMoves focus and checks the next radio item in the group.
ArrowUpMoves focus to the previous radio item in the group.
ArrowLeftMoves focus to the previous radio item in the group.

On this page

  • Import
  • Usage
  • Orientation
  • Sizes
  • Customizing
  • Primitives
  • API
    • Root
      • Props
      • Data Attributes
    • Indicator
      • Props
      • Data Attributes
    • ItemControl
      • Props
      • Data Attributes
    • ItemHiddenInput
      • Props
    • Item
      • Props
    • ItemText
      • Props
    • Label
      • Props
      • Data Attributes
    • RootProvider
      • Props
    • Context
  • Accessibility
    • Keyboard Support
Edit this page on Github