Radio Button Group
Radio Button Group is a set of related, mutually exclusive options where only one can be selected at a time.
const RadioButtonGroupExample = () => {return (<RadioButtonGroup attached name="foo" legend="Choose a day" helpText="The message will be sent on the day you choose"><RadioButton value="m">Mon</RadioButton><RadioButton value="t" defaultChecked>Tues</RadioButton><RadioButton value="w">Wed</RadioButton><RadioButton value="th">Thu</RadioButton><RadioButton value="f">Fri</RadioButton></RadioButtonGroup>)}render(<RadioButtonGroupExample />)
A Radio Button Group is a set of 2–6 mutually exclusive radio buttons. It is often used as a way to swap between different views of the same data (e.g., swapping between different chart types for a data set).
Be thoughtful when using Radio Button Groups in forms. It can be difficult for users to discern which option is “selected” with only 2 options, while having too many options can be overwhelming. We recommend no more than 6 options. Radio Button Groups used in forms should have a label.
Tabs are used to layer related pieces of information together and display one layer at a time. Use Tabs to alternate between views within the same context. Use Radio Button Groups to toggle between different functionality in a single view. Tabs replace the entire view based on the selected tab. Radio Buttons update the data within the view.
Radio Groups are form elements that allow customers to select only one option from a list of text at a time. Radio Groups are easily scannable and work well within a larger form because they visually compete less with primary page actions.
Radio Button Groups are functionally the same as Radio Groups since only one option can be selected at a time. However, the Radio Button Group contains buttons while Radio Groups contain Radios. This distinction makes Radio Button Groups more visually prominent, so they may be ideal for a more graphical element. They can also be great options when selecting between simple things, like days of the week, modes of contact (e.g., phone, sms, email), etc.
A Radio Button Group is the same as a Radio Group to assistive technology.
- If the Radio Button only has an icon, the icon needs a label.
- The Radio Button Group needs a legend, which labels what the set of Radio Buttons does.
Use the text variant with short labels, no more than 3 words per label.
const RadioButtonGroupExample = () => {return (<RadioButtonGroup attached name="foo" legend="Choose a day" helpText="The message will be sent on the day you choose"><RadioButton value="m">Mon</RadioButton><RadioButton value="t" defaultChecked>Tues</RadioButton><RadioButton value="w">Wed</RadioButton><RadioButton value="th">Thu</RadioButton><RadioButton value="f">Fri</RadioButton></RadioButtonGroup>)}render(<RadioButtonGroupExample />)
Use the text and icon variant when icons are not easily recognizable (like product-specific icons) and a text label would help with understanding. If an icon has a chance of not being completely understood at a glance, pair it with a text label.
const RadioButtonGroupExample = () => {return (<RadioButtonGroup attached name="foo" legend="Choose a product" helpText="The product you choose will be used for your new role"><RadioButton value="phone"><CallIcon decorative={false} title="phone icon"/>Phone</RadioButton><RadioButton value="text"><SMSCapableIcon decorative={false} title="text icon"/>Text</RadioButton><RadioButton value="email"><EmailIcon decorative={false} title="email icon"/>Email</RadioButton></RadioButtonGroup>)}render(<RadioButtonGroupExample />)
Display an error message below the radio button group. For additional guidance on how to compose error messages, refer to the error state pattern.
const RadioButtonGroupExample = () => {return (<RadioButtonGroupattachedname="foo"legend="What is your preferred programming language?"errorText="Select a programming language."helpText="Select the language with which you are most familiar."><RadioButton value="js" hasError>JavaScript</RadioButton><RadioButton value="py" hasError>Python</RadioButton><RadioButton value="c" hasError>C++</RadioButton></RadioButtonGroup>)}render(<RadioButtonGroupExample />)
const RadioButtonGroupExample = () => {return (<RadioButtonGroup attached name="foo" legend="Choose a letter" helpText="Don't get it wrong!"><RadioButton value="a">A</RadioButton><RadioButton value="b">B</RadioButton><RadioButton value="c" disabled>C</RadioButton></RadioButtonGroup>)}render(<RadioButtonGroupExample />)
Radio Button Group labels should be 1-3 words to prevent the group from becoming too large. Use sentence case for each option.
Consider context and the user goal to determine the order of items. For example, days of the week have an obvious order, while asking users to select a programming language might be listed in order of anticipated popularity.
When possible, automatically select a default option.
Do
Use Radio Button Group when options are mutually exclusive and only one option is valid.
Don't
Don’t use Radio Button Groups if you need to select multiple options.
Do
Group related buttons in a Radio Button Group (e.g., types of graphs).
Don't
Don’t group buttons together that are not related to each other.
Do
Pair icon-only variants with text for better context.
Don't
Don’t use the icon-only variant if the icons are not easily recognizable.
Do
Use Radio Button Group to let users select one option from a list.
Don't
Don’t use Radio Button Groups for actions, such as save, edit, or delete. Use single Buttons or a Button Group instead.
yarn add @twilio-paste/radio-button-group - or - yarn add @twilio-paste/core
import {RadioButtonGroup, RadioButton} from '@twilio-paste/core/radio-button-group';
const Component = () => (
<RadioButtonGroup attached>
<RadioButton>One</RadioButton>
<RadioButton>Two</RadioButton>
<RadioButton>Three</RadioButton>
</RadioButtonGroup>
);
All the valid HTML attributes for input[type="radio]
are supported including the following props:
Prop | Type | Description | Default |
---|---|---|---|
children | React.ReactElement[] | RadioButton | |
name | string | Name for the Radio Button Group | null |
attached? | boolean | If the group of buttons are visually attached | false |
legend | string | Label text for the Radio Button Group | null |
helpText? | string | Help text for the Radio Button Group | null |
id? | string | ID for the Radio Button Group | null |
value? | string | Value for the Radio Button Group | null |
disabled? | boolean | Make the Radio Button Group disabled | false |
onChange? | (event: React.MouseEvent<HTMLElement>) | Pass a function for the onChange handler | null |
errorText? | string | Error text for the Radio Button Group | null |
element? | string | Overrides the default element name to apply unique styles with the Customization Provider | 'RADIO_BUTTON_GROUP' |
i18nRequiredLabel? | string | Overrides the default string marking the group as required | '(required)' |
All the valid HTML attributes for div
are supported including the following props:
Prop | Type | Description | Default |
---|---|---|---|
children | React.ReactElement[] | Contents of the Radio Button | |
hasError? | boolean | Adds an error state to the Radio Button | false |
defaultChecked? | boolean | Sets the Radio Button as the default checked option | false |
checked? | boolean | Sets the Radio Button as checked | false |
id? | string | ID for the Radio Button | null |
value? | string | Value for the Radio Button | null |
disabled? | boolean | Make the Radio Button disabled | false |
name | string | Name for the Radio Button Group | null |
element? | string | Overrides the default element name to apply unique styles with the Customization Provider | 'RADIO_BUTTON' |
Changelog
733709127
#3395 Thanks @SiTaggart! - Modified the compile target of our JavaScript bundles fromnode
tobrowser
to minimize the risk of clashing with RequireJS. This is marked as a major out of an abundance of caution. You shouldn't need to do anything but we wanted you to be aware of the change on the off chance it has unintended consequences
- Updated dependencies [
733709127
]:- @twilio-paste/uid-library@2.0.0
- @twilio-paste/color-contrast-utils@5.0.0
- @twilio-paste/anchor@12.0.0
- @twilio-paste/button@14.0.0
- @twilio-paste/help-text@13.0.0
- @twilio-paste/inline-control-group@13.0.0
- @twilio-paste/label@13.0.0
- @twilio-paste/screen-reader-only@13.0.0
- @twilio-paste/spinner@14.0.0
- @twilio-paste/flex@8.0.0
- @twilio-paste/media-object@10.0.0
- @twilio-paste/stack@8.0.0
- @twilio-paste/box@10.0.0
- @twilio-paste/sibling-box@9.0.0
- @twilio-paste/text@10.0.0
- @twilio-paste/customization@8.0.0
- @twilio-paste/design-tokens@10.0.0
- @twilio-paste/icons@12.0.0
- @twilio-paste/animation-library@2.0.0
- @twilio-paste/styling-library@3.0.0
- @twilio-paste/style-props@9.0.0
- @twilio-paste/theme@11.0.0
- @twilio-paste/types@6.0.0
4d1f7c65e
#3360 Thanks @SiTaggart! - Improved types where Paste extends the base HTML element that a component is based on, so that the existing blocked styling properties are not exposed as valid properties for the component via Typescript. This leads to less confusion around what is supported by a Paste component.Existing blocked component properties include:
className
style
color
3ab2bb6f4
#3114 Thanks @SiTaggart! - ### Breaking changeWe have moved
@types/react
and@types/react-dom
to peer dependencies of the library. This should allow for greater control and backwards compatibility with older versions of React as Paste is no longer bundling the type libraries.Your application likely has both of these as dependencies anyway, but it is now up to you to manage that version number.
Action needed
Ensure
@types/react
and@types/react-dom
are installed as dependencies of your application.
6730aac19
#3112 Thanks @nkrantz! - [Radio button group] Update styles to align with new Paste Twilio theme. Fix vertical spacing and border zIndex bugs.
3ab2bb6f4
#3114 Thanks @SiTaggart! - [Checkbox, Radio Group, Radio Button Group] improved backwards compat with React 17 typesUpdated dependencies [
6730aac19
,1d75f223e
,3ab2bb6f4
,50cde4668
,bce889344
,3ab2bb6f4
,3ab2bb6f4
,3ab2bb6f4
,3ab2bb6f4
]:- @twilio-paste/button@13.0.0
- @twilio-paste/icons@11.0.0
- @twilio-paste/anchor@11.0.0
- @twilio-paste/theme@10.0.0
- @twilio-paste/box@9.0.0
- @twilio-paste/sibling-box@8.0.0
- @twilio-paste/text@9.0.0
- @twilio-paste/inline-control-group@12.0.0
- @twilio-paste/help-text@12.0.0
- @twilio-paste/label@12.0.0
- @twilio-paste/screen-reader-only@12.0.0
- @twilio-paste/spinner@13.0.0
- @twilio-paste/flex@7.0.0
- @twilio-paste/media-object@9.0.0
- @twilio-paste/stack@7.0.0
- @twilio-paste/customization@7.0.0
- @twilio-paste/style-props@8.0.0
- @twilio-paste/types@5.0.0
d97098846
#3020 Thanks @SiTaggart! - This major version included listing all the missing peer dependencies for each Paste package.If you are using a package from Paste in isolation from Core, when upgrading to this latest version, be sure to correctly install all the missing peer dependencies.
- Updated dependencies [
154b02c06
,dbd9bf992
,3c89fd83d
,d97098846
,154b02c06
,0acdf3486
,ef094db4a
,0acdf3486
]:- @twilio-paste/anchor@10.0.0
- @twilio-paste/design-tokens@9.0.0
- @twilio-paste/button@12.0.0
- @twilio-paste/help-text@11.0.0
- @twilio-paste/inline-control-group@11.0.0
- @twilio-paste/label@11.0.0
- @twilio-paste/screen-reader-only@11.0.0
- @twilio-paste/spinner@12.0.0
- @twilio-paste/flex@6.0.0
- @twilio-paste/media-object@8.0.0
- @twilio-paste/stack@6.0.0
- @twilio-paste/box@8.0.0
- @twilio-paste/sibling-box@7.0.0
- @twilio-paste/text@8.0.0
- @twilio-paste/customization@6.0.0
- @twilio-paste/icons@10.0.0
- @twilio-paste/animation-library@1.0.0
- @twilio-paste/styling-library@2.0.0
- @twilio-paste/uid-library@1.0.0
- @twilio-paste/style-props@7.0.0
- @twilio-paste/theme@9.0.0
- @twilio-paste/types@4.0.0
- @twilio-paste/color-contrast-utils@4.0.0
a4c9e70b0
#2763 Thanks @shleewhite! - Update ESLint rules, which changed some formatting.
edca0f7c8
#2757 Thanks @SiTaggart! - [Button, radio-button-group, codemods] Correct the ToggleButtonStyles export for use in Radio Button Group
d49514a27
#2746 Thanks @jb-twilio! - [RadioButtonGroup]: add new package