Default
Disabled
Error
Radio buttons let a user choose one option from a group of mutually exclusive, related options.
Default
Disabled
Error
<mat-radio-button>
provides the same functionality as a native <input type="radio">
enhanced with Material Design styling and animations.
Note that this component may require additional styling.
Radio buttons are an out-of-the-box functionality.
You simply need to select the radio box option from the toolbox on the right.
The styles for the radio buttons should automatically be applied along with the styles for their error states.
The Mendix toolkit can be found here.
Use the codes below to add this component to your project. Download the latest version of the library to easily implement our full range of components.
Execute the following command to install this component.
Import the following into your app.module.ts file.
<cpc-ds-radio-button *ngFor="let country of countries; let i=index" formArrayName="selectedCountries" id="country_radio_{{i}}" name="country_radio" [text]="country.name" [value]="country.value" [disabled]="(i === 3) ? true : false" (change)="onCheckboxChange($event)">
</cpc-ds-radio-button>
Name | Type | Default | Description |
---|---|---|---|
id | string | radio-button-id |
Set the radio button id |
name | string | radio-button-name |
Set the name of radio button |
text | string | Radio button text here |
Set the radio button text |
value | string | Radio button value |
Set the value of radio button |
checked | boolean |
Set the checked state of radio button |
|
disabled | boolean |
Set the disabled state of radio button |
Import the following into your theme or page.
Import the following into your theme or page.
<script src="[JS-PLACE-HOLDER]"></script>
<div role="radiogroup" aria-labelledby="radio-names"> <p class="radio" id="radio-names">Select a radio:</p> <div class="checkbox-container"> <input class="by-keyboard" checked id="one" name="radio" type="radio"> <label for="one">A quick brown fox jumps over a lazy dog. A quick brown fox jumps over a lazy dog.</label> </div> <div class="checkbox-container"> <input class="by-keyboard" id="two" name="radio" type="radio"> <label for="two">Radio button item 2</label> </div> <div class="checkbox-container"> <input class="by-keyboard" id="three" name="radio" type="radio"> <label for="three">Radio button item 3</label> </div> <div aria-disabled="true" class="checkbox-container disabled"> <input class="by-keyboard" disabled id="dis" name="radio" type="radio"> <label for="dis">Radio disabled</label> </div> </div>
<div role="radiogroup" aria-labelledby="radio-disabled-names"> <p class="radio" id="radio-disabled-names">Disabled radio:</p> <div aria-disabled="true" class="checkbox-container disabled"> <input disabled class="by-keyboard" id="dis" name="radio2" type="radio" checked="checked"> <label for="dis">Radio button item 1</label> </div> <div aria-disabled="true" class="checkbox-container disabled"> <input disabled class="by-keyboard" id="dis2" name="radio2" type="radio"> <label for="dis2">Radio button item 1</label> </div> </div>
Radio buttons allow users to choose one option from a group of related options.
These choices are mutually exclusive, meaning that the user can’t select more than one option.
If you’d like to allow users to select more than one option, use checkboxes.
Radio buttons are ideal for allowing users to select from a range of available options quickly and conveniently.
Users can only select one radio button. If they pick another, the previously selected button is automatically deselected.
Using keyboards and assistive technologies, users navigate to a radio button group with tab and select an option with arrow keys.
Groups of radio buttons can also have a default state with one preselected option.
If radio button copy is long and likely to wrap on smaller screens, make sure the copy wraps under the first letter of copy, not the radio button. When copy wraps, vertically align buttons with the first line of copy.
Using a mouse, radio buttons activate when a user clicks the icon or its label.
Using a keyboard or assistive technology, users can tab to the radio button grouping and use arrow keys to navigate selections.
Ensure there is enough vertical spacing between radio buttons to prevent selection errors.
Use the HTML tags <div role=”radiogroup”>
to wrap the radio button groups. These tags help assistive technologies interpret your groupings in a way users can easily navigate.
Use headers to title radio button groupings.
When there is an error message, place it under the last radio button item.
Radio buttons should be clearly labelled to avoid any confusion when users pick an option. Write clear, concise and comprehensive labels in sentence case. Explain exactly what will happen if a selection leads to a specific action or change.
Guidelines | Examples | |
---|---|---|
Recommended length | Use as needed to complete the thought but try to keep it to one line | |
Line wrap | Avoid | |
Phrasing | Short phrases that explain each option | |
Case | Sentence case | |
Make sure all choices are distinct and don’t overlap any of the options on your list.
Consider the context of the choices when determining order. You can order radio buttons according to relevance (most likely to be selected to least likely) or scale. Other examples include going from cheapest to most expensive, simplest to most complicated, or most recent to oldest.
The radio button component can have following ARIA properties:
When testing a radio button, the tester must ensure: