# 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` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent` | No | `-` | Background color of the overlay (element being interacted with). | | `borderColor` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent` | No | `-` | Border color of the element. | | `borderRadius` | `0 \| 100 \| 200 \| 300 \| 400 \| 500 \| 600 \| 700 \| 800 \| 900 \| 1000` | No | `-` | - | | `borderWidth` | `0 \| 100 \| 200 \| 300 \| 400 \| 500` | No | `-` | - | | `children` | `null \| string \| number \| false \| true \| ReactElement> \| Iterable \| ReactPortal` | No | `-` | Label for the control option. | | `color` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent` | No | `black` | - | | `controlColor` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent` | No | `bgPrimary` | Sets the checked/active color of the control. | | `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` | `ChangeEventHandler` | No | `-` | - | | `ref` | `null \| (instance: HTMLInputElement \| null) => void \| RefObject` | 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` | `number \| color \| button \| search \| time \| image \| text \| hidden \| string & {} \| email \| checkbox \| radio \| tel \| url \| date \| submit \| reset \| datetime-local \| file \| month \| password \| range \| week` | No | `-` | - | | `value` | `string` | No | `-` | Value of the option. Useful for multiple choice. |