Radio buttons allow a user to select one option from a set.
EzField
select list which uses less space.EzRadio supports outlined
(default) and filled
(for darker backgrounds) variants.
To add a label to a radio button, use EzFormControlLabel
and provide the EzRadio
to its control
prop along with the label
.
You can optionally append a set of icons to the label by passing in an array of EzIcon
s to labelIcons
in EzFormControlLabel
.
EzRadio supports theme palette properties (primary
, secondary
, error
, warning
, info
, alert
, neutral
, and success
) as well as all supported theme colors (ex. common.red100
). Colors should have high enough contrast for accessibility.
If you want to specify a size, use the size
property. We currently support small
, medium
(default), and large
.
EzRadio components can be grouped using form controls (see below).
To define the gap between radio labels, use the optional gap
prop of type number
on EzRadioGroup
.
8px
scaling factor, so a gap of x
(of type number
) is equal to x * 8px
.0
and rows is 2
.row
prop on EzRadioGroup
.helperText
prop on EzFormControlLabel
.You can also control the radio with the value
and onChange
props on EzRadioGroup
.
Additional content can also be displayed depending on the selection.
To display an error state in a checkbox group, pass an error
boolean property to EzFormControl
. Be sure to include an error alert or message to indicate what the error is.
To provide proper keyboard accessibility when using grouped radio buttons, use EzRadio
with the following components and their props:
EzFormControl
- used to provide context and ensure a consistent state
error
- if true
, the label is displayed in an error statefullWidth
- if true
, the component will take up the full width of its containerEzFormLabel
- used to provide a label for a group of radio buttons
id
- should match the ariaLabel
prop of EzRadioGroup
EzRadioGroup
- used to group radio buttons
ariaLabel
- should match the id
prop of EzFormLabel
defaultValue
- sets the default value if not controlledgap
- the gap between radio labels (defaults to 0 for columns and 2 for rows)labelWidth
- the defined width of each super radio button in a radio groupname
- used to reference the value of the controlonChange
- if controlled, the callback fired when the radio button is selectedrow
- lays out the buttons horizontallytheme
- a defined theme object with optional keys color
and variant
for super radio buttonsvalue
- if controlled, the value of the selected radio buttonEzFormControlLabel
- used to provide a label for a radio button
control
- the required control element (<EzRadio />
)disabled
- if true
, the component is disabledhelperText
- the helper text contenticon
- the icon for the radio button when using a super radio buttonlabel
- the label for the radio buttonlabelIcons
- an optional array of EzIcon
s to display after the labelvalue
- the value of the form control labelFor larger, more visual radio buttons, provide an icon
(<EzIcon />
) along with an optional label
to EzFormControlLabel
.
labelWidth
of type number
to EzRadioGroup
. Labels will wrap if needed, but should not be more than 2 lines.To define a theme for each button in a group, pass a theme
property to EzRadioGroup
.
color
accepts either a color theme property (ex. color: 'primary'
), or a custom defined values object (see example below)variant
accepts either filled
(default) or outlined
A radio button can be made disabled by adding the optional disabled
prop on either EzRadio
(if standalone) or EzFormControlLabel
(if in a group).
Supported styles should be used, but if you need to overwrite styles for the radio, form label, form control label, or super form control label, you can do so using provided class names:
EzRadio
, EzRadio-outlined
, EzRadio-filled
, EzRadio-checked
, EzRadioIcon-checked
, EzRadioIcon-checked-dot
, EzRadio-disabled
, EzRadio-input
, EzRadioIcon-checked
, EzRadioIcon-unchecked
EzRadioGroup
EzFormLabel
EzFormControlLabel
, EzFormControlLabel-label
, EzFormControlLabel-helperText
EzSuperFormControlLabel
, EzSuperFormControlLabel-radio
, EzSuperFormControlLabel-checked
, EzSuperFormControlLabel-label
, EzSuperFormControlLabel-icon
, EzSuperFormControlLabel-text
See WAI-ARIA accessibility guidelines for radio buttons.
All radio button form controls should have corresponding labels using ariaLabel
(hidden) or EzFormControlLabel
.
If a label isn't used (for example when using an icon-only super radio button), be sure to add an ariaLabel
directly to EzRadio
.
Name | Type | Default | Description |
---|---|---|---|
ariaLabel | string | radio-button | The aria-label of the radio element. |
checked | boolean | false | If true, the component is checked. |
color | EzThemeColors | primary | The color of the component. Supports theme palette properties and colors. |
disabled | boolean | false | If true, the component is disabled. |
name | string | Name attribute of the input element. | |
onChange | func | Callback fired when the state is changed for controlled components. | |
size | small | medium | large | medium | The size of the component. |
value | any | The value of the controlled component. | |
variant | outlined | filled | outlined | The variant of the component. |