Radio

An easily stylable radio button component.

Best apple

Anatomy

Radio is always placed within Radio Group. Import the components and place them together:

Anatomy

API reference

RadioGroup

Provides a shared state to a series of radio buttons. Renders a <div> element.

PropTypeDefault
name

string

undefined

defaultValue

any

undefined

value

any

undefined

onValueChange

((value: unknown, event: Event) => void)

undefined

disabled

boolean

false

readOnly

boolean

false

required

boolean

false

inputRef

Ref<HTMLInputElement>

undefined

className

| string
| ((state: Radio.Group.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Radio.Group.State) => ReactElement)

undefined

Attribute
Description
data-disabled

Root

Represents the radio button itself. Renders a <button> element and a hidden <input> beside.

PropTypeDefault
value*

any

nativeButton

boolean

true

disabled

boolean

false

readOnly

boolean

false

required

boolean

false

inputRef

Ref<HTMLInputElement>

undefined

className

| string
| ((state: Radio.Root.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Radio.Root.State) => ReactElement)

undefined

Attribute
Description
data-checked
data-unchecked
data-disabled
data-readonly
data-required
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused

Indicator

Indicates whether the radio button is selected. Renders a <span> element.

PropTypeDefault
className

| string
| ((state: Radio.Indicator.State) => string)

undefined

keepMounted

boolean

false

render

| ReactElement
| ((props: HTMLProps, state: Radio.Indicator.State) => ReactElement)

undefined

Attribute
Description
data-checked
data-unchecked
data-disabled
data-readonly
data-required
data-valid
data-invalid
data-dirty
data-touched
data-filled
data-focused

Examples

Form integration

To use a radio group in a form:

  1. Pass the group’s name to Field
  2. Use Field.Label to label each radio
  3. Use the render prop to render the field as a Fieldset in order to label the group
Using RadioGroup in a form