Radio
Use Radio Buttons to offer a visible list of choices where only a single selection is possible. Only one Radio Button of a group can be active at a time. You must never use single Radios, you might need to use a Checkbox or a Switch instead.
Example
<> <p>Please select your payment method</p> <Radio id="mc" name="Zahlmethode" value="Mastercard" label="Mastercard" /> <br /> <Radio id="vi" name="Zahlmethode" value="Visa" label="Visa" /> <br /> <Radio id="ae" name="Zahlmethode" value="AmericanExpress" label="American Express" /> </>
Usage Rules
Do:
- Have one option (usually the most desired one) set by default
- Layout your option list vertically, with one choice per line
- Use active wording and avoid negations in labels
- Use Radio button instead of a Select if there are less than 4 options to choose from
Don’t:
- Use as action buttons
- Use if multiple options can be selected
- Use to toggle items on or off. Use Switch instead
Variants
Disabled
<> <Radio id="radio-disabled" disabled label="You can't select me" /> </>
Helper Text
You can add an extra description to radio using helperText
.
<> <p>Please select your recording</p> <Radio id="precise" name="recording" value="Precise" label="Precise recording" helperText="This requires to add a recording script to your app." /> <br /> </>
Icons
Using prefixIcon
or suffixIcon
to render the icon and colorIcon
to color the icon, the default color is ColorNeutral140 (#191d2f).
<> <p>Please select your platform.</p> <Radio id="ios" name="platform" value="ios" label="IOS" prefixIcon="PlatformIosFilled" /> <br /> <Radio id="android" name="platform" value="android" label="Android" suffixIcon="PlatformAndroidFilled" colorIcon="ColorPositive90" /> <br /> <Radio id="window" name="platform" value="window" label="Window" prefixIcon="PlatformWindowsFilled" disabled /> </>
Label Info Tooltip
You can add more information for label by adding labelIconTooltip
.
The tooltip content
can either be pure text or any rich content wrapped in a React component. The tooltip position
is used to define the positioning of the tooltip
When the tooltip content
is not provided, the label icon will be not shown.
<> <p>Please select your platform.</p> <Radio id="ios" name="platform" value="ios" label="IOS" prefixIcon="PlatformIosFilled" labelIconTooltip={{ content: 'IOS', position: 'right' }} /> <br /> <Radio id="android" name="platform" value="android" label="Android" suffixIcon="PlatformAndroidFilled" colorIcon="ColorPositive90" labelIconTooltip={{ content: 'Android', position: 'right' }} /> <br /> <Radio id="window" name="platform" value="window" label="Window" prefixIcon="PlatformWindowsFilled" disabled /> </>
Ref
You can access to the input native element using ref
.
function refTest(){ const radioRef = React.createRef(); const handleChange = () => { radioRef.current.style.backgroundColor = 'orange'; } return ( <> <Radio id="radio-ref" ref={radioRef} onChange={handleChange} label="Select me!" /> </> ) }
Required
In case of group radio buttons, you only need to add required
to one item.
<> <Radio name="group" label="Label 1" required /> <Radio name="group" label="Label 2" /> <Radio name="group" label="Label 3" /> </>
Props
Name | Type | Default |
---|---|---|
name * Native HTML attribute: Link |
| — |
value * Native HTML attribute: Link |
| — |
disabled Native HTML attribute: Link |
| — |
css Add custom styles to this component. Use with caution. Learn more here: Link |
| — |
inputFieldCss |
| — |
label The label for the radio |
| — |
aria-label Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link |
| — |
aria-labelledby Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link |
| — |
id Native HTML attribute: Link |
| — |
checked Native HTML callback: Link |
| — |
required Native HTML attribute: Link |
| — |
readOnly Native HTML attribute: Link |
| — |
onChange Native HTML callback: Link |
| — |
helperText HelperText for radio |
| — |
tabIndex Tab index |
| — |
labelIconTooltip The label info tooltip icon |
| — |
prefixIcon The prefix icon | "AddValue" | "Adjust" | "AIAgent" | "AppGrid" | "ArrowCircleLeft" | "ArrowCircleRight" | "ArrowDown"... | — |
suffixIcon The suffix icon | "AddValue" | "Adjust" | "AIAgent" | "AppGrid" | "ArrowCircleLeft" | "ArrowCircleRight" | "ArrowDown"... | — |
colorIcon The color of icon |
| — |
ref |
| — |
key |
| — |
data-{foo} Data attributes can be used by testing libraries to retrieve components or assert their existence |
| — |
* - the prop is required. |