Radio groups are used when a user has a single choice to make from two or more options. The user can only choose one radio selection at a time.
Radio groups should:
Include at least two or more options
Allow users to select only one option
Include at most 6 options (use your discretion here if you need more; if there's a chance in the future that it might be more than 6, use a Select component drop-down) If there is help text that the user needs to know before making selection, use checkbox/radio.
List options in a rational order that makes logical sense
Avoid nesting radio buttons with other radio buttons
If an option is strongly recommended, add "(Recommended)" to the label. Be sure to add to the label, not the help text
See Default Pre-Selected State to determine if you should have a default selection
Use the same name attribute on all radio buttons in the group. This ensures that if there is more than one group in the form, each one stays associated with its own group
If a radio group is “Optional”, users won't be able to unselect a selected radio. If you need to give users a way to unselect, consider adding a clear button or using another type of form field.
Use a Select Component if there is a chance additional options over 6 will be added in the future.
By default, we don't have a pre-selected state. It's at the discretion of Paste consumers to set a default selected option. If there is a pre-selected state, be sure to make the first option the default option. Please review this article to determine if you should default a selection: https://www.nngroup.com/articles/radio-buttons-default-selection/.
Don't have a default selection if:
A default value would incorrectly imply that the user doesn't need to make a selection when they actually need to make a choice.
You are collecting unbiased data. Defaulting to an option biases or alters the experience in an undesired way and your data will be skewed
There is no acceptable default option for safety, security, or legal reasons and therefore the user must make an explicit choice. (show display error)
You can provide additional information about the group with the use of help text. Help text can appear after the group label but before the first option. Use the group label to explain the purpose of the group, not how to make the selection. Assume that users know how to use radio buttons. For example, don't say "Select one of the following choices".
constNetworkRadioGroup=()=>{
const[value, setValue]= React.useState('lowest');
return(
<RadioGroup
name="network"
value={value}
legend="Choose Network Access Profile"
helpText="Network Access Profile specifies what networks your SIM's would connect to and how you will be billed."
Options are placed next to each other, in logical order, with appropriate spacing. If people can easily compare shorter options from left to right, use this alignment
Do not run onto two lines
If the label is longer than 3 words/20 characters, consider using a vertically stacked version. If the content is too long, please use vertical stacking
1a7bb349#974 Thanks @SiTaggart! - [RadioGroup] Added optional value string prop which this component needs and is no longer on the extended InlineControlGroup interface.
8992af4b#1251 Thanks @richbachman! - Removed required from the id and value props, so RadioGroup can be used as an uncontrolled component. This allows RadioGroup to be used with libraries like React-Hook-Form.
a12acb61#1158 Thanks @richbachman! - Pinned all twilio-paste package versions in order to keep them in sync with core when they are updated by changesets.