# Radio **📖 Live documentation:** https://cds.coinbase.com/components/inputs/Radio/ Radio is a control component that allows users to select one option from a set of mutually exclusive options. ## Import ```tsx import { Radio } from '@coinbase/cds-web/controls/Radio' ``` ## Examples ### Basic Usage Radio components are typically used individually as part of a radio group. Each radio represents a single option in a mutually exclusive set. ```jsx live function BasicRadio() { const [selectedValue, setSelectedValue] = useState('option1'); return ( setSelectedValue(e.target.value)} > Option 1 setSelectedValue(e.target.value)} > Option 2 setSelectedValue(e.target.value)} > Option 3 ); } ``` ### Radio Groups The recommended way to use Radio components is with a ControlGroup for better accessibility and easier state management. ```jsx live function RadioGroupExample() { const options = [ { value: 'btc', children: 'Bitcoin' }, { value: 'eth', children: 'Ethereum' }, { value: 'ltc', children: 'Litecoin' }, ]; const [selectedCurrency, setSelectedCurrency] = useState('btc'); return ( setSelectedCurrency(e.target.value)} name="currency-radio-group" /> ); } ``` ### Custom Colors You can customize the radio's color using the `controlColor` prop. ```jsx live function CustomColorRadio() { const [selectedColor, setSelectedColor] = useState('default'); return ( setSelectedColor(e.target.value)} > Default Color setSelectedColor(e.target.value)} controlColor="accentBoldGreen" > Custom Green setSelectedColor(e.target.value)} controlColor="accentBoldPurple" > Custom Purple ); } ``` ### Disabled State Radio components can be disabled to prevent user interaction. ```jsx live function DisabledRadio() { const [selectedValue, setSelectedValue] = useState('enabled'); return ( setSelectedValue(e.target.value)} > Enabled Radio setSelectedValue(e.target.value)} > Disabled & Unchecked setSelectedValue(e.target.value)} > Disabled & Checked ); } ``` ### Custom Styling You can further customize the radio's appearance using style props. ```jsx live function CustomStyledRadio() { const [selectedStyle, setSelectedStyle] = useState('styled1'); return ( setSelectedStyle(e.target.value)} background="bgSecondary" borderColor="accentBoldBlue" controlColor="accentBoldBlue" > Custom Background & Border setSelectedStyle(e.target.value)} controlColor="accentBoldOrange" borderColor="accentBoldOrange" > Orange Theme ); } ``` ## Props | Prop | Type | Required | Default | Description | | --- | --- | --- | --- | --- | | `accessibilityLabel` | `string` | No | `-` | Accessibility label describing the element. | | `background` | `Color` | No | `-` | Background color of the overlay (element being interacted with). | | `borderColor` | `Color` | No | `-` | Border color of the element. | | `borderRadius` | `ResponsiveProp` | No | `-` | - | | `borderWidth` | `((BorderWidth \| { base?: BorderWidth; phone?: BorderWidth \| undefined; tablet?: BorderWidth \| undefined; desktop?: BorderWidth \| undefined; }) & BorderWidth) \| undefined` | No | `100` | Sets the border width of the radio. | | `children` | `ReactNode` | No | `-` | Label for the control option. | | `color` | `ResponsiveProp` | No | `black` | - | | `controlColor` | `Color` | No | `bgPrimary` | Sets the checked/active color of the radio. | | `controlSize` | `number` | No | `theme.controlSize.radioSize` | Sets the outer radio control size in pixels. | | `dotSize` | `number` | No | `2/3 of controlSize` | Sets the inner dot size in pixels. | | `elevation` | `ResponsiveProp` | No | `-` | - | | `iconStyle` | `CSSProperties` | No | `-` | Style for the icon element | | `indeterminate` | `boolean` | No | `-` | Enable indeterminate state. Useful when you want to indicate that sub-items of a control are partially filled. | | `labelStyle` | `CSSProperties` | No | `-` | Style for the label element | | `onChange` | `FormEventHandler` | No | `-` | - | | `ref` | `Ref` | No | `-` | - | | `testID` | `string` | No | `-` | Used to locate this element in unit and end-to-end tests. Under the hood, testID translates to data-testid on Web. On Mobile, testID stays the same - testID | | `type` | `button \| reset \| submit` | No | `-` | - | | `value` | `string` | No | `-` | Value of the option. Useful for multiple choice. |