Radio

Controlled radio button. Group multiple Radio components sharing the same name.

Radio group

import { useState } from 'react'
import { Radio } from '@canarist/ui'

function PlanSelector() {
  const [plan, setPlan] = useState('monthly')
  return (
    <>
      <Radio
        name="plan"
        label="Monthly"
        value="monthly"
        checked={plan === 'monthly'}
        onChange={() => setPlan('monthly')}
      />
      <Radio
        name="plan"
        label="Annual"
        value="annual"
        checked={plan === 'annual'}
        onChange={() => setPlan('annual')}
      />
    </>
  )
}

With description

<Radio
  name="role"
  label="Admin"
  description="Full access to all settings."
  value="admin"
  checked={role === 'admin'}
  onChange={() => setRole('admin')}
/>

Reference

PropTypeDefaultDescription
labelstringVisible label next to the radio button.
descriptionstringSecondary text below the label.
namestringHTML name attribute — groups radios together.
valuestringHTML value attribute.
checkedbooleanControlled checked state.
onChangeReact.ChangeEventHandler<HTMLInputElement>Called when this radio is selected.
disabledbooleanDisable the radio.