To add the Radio
component to your app:
1 2import { Radio } from '@forge/react';
A radio input allows users to select only one option from a number of choices. Radio is generally displayed in a radio group.
Name | Type | Required | Description |
---|---|---|---|
isChecked | boolean | No | Set the field as checked. |
isDisabled | boolean | No | Makes a Radio field unselectable when true. Overridden by isDisabled prop of RadioGroup . |
isInvalid | boolean | No | Marks this as an invalid field. |
isRequired | boolean | No | Marks this as a required field. |
label | string | No | The label value for the input. |
onChange | (e: ChangeEvent) => void | No | An event handler, passed into the props of each Radio Component instantiated within RadioGroup . |
value | string | No | Field value. |
The default way to present a single option from a list.
In most situations where you want to present a list of mutually exclusive options, you will want to use a RadioGroup.
1 2const RadioDefaultExample = () => { return ( <Radio name="radio-default" value="radio" label="Default radio" /> ); };
Use isDisabled
to disable a radio option.
1 2const RadioDisabledExample = () => { return ( <Radio name="radio-disabled" value="radio" label="Disabled radio" isDisabled={true} /> ); };
Use isInvalid
for situations where the selected field is invalid or incorrect. Remember to provide useful validation messages to help people understand how to proceed.
1 2import { Radio, ErrorMessage } from "@forge/react"; const RadioInvalidExample = () => { return ( <Radio name="radio-invalid" value="radio" label="Invalid radio" isInvalid isChecked /> <ErrorMessage>This field is invalid</ErrorMessage> ); };
When using the Radio
component, we recommend keeping the following accessibility considerations in mind:
Rate this page: