Checkboxes allow the user to select one or more items from a set.
EzCheckbox supports outlined (default), filled (for darker backgrounds), and filled-inverse variants.
To mark the checkbox as checked by default, use the defaultChecked prop.
To add a label to a checkbox, use EzFormControlLabel and provide the EzCheckbox 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 EzIcons to labelIcons in EzFormControlLabel.
EzCheckbox 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.
A checkbox input has only one of two states: checked or unchecked. However, visually, a checkbox can also have an indeterminate state by using the indeterminate property on EzCheckbox.
EzCheckbox components can be grouped using form controls (see below).
To define the gap between checkbox labels, use the optional gap prop of type number on EzFormGroup.
8px scaling factor, so a gap of x (of type number) is equal to x * 8px.0 and rows is 2.row prop on EzFormGroup.helperText prop on EzFormControlLabel.You can also control the checkbox with the checked prop on EzFormControlLabel and onChange on EzCheckbox.
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 checkboxes, use EzCheckbox 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 checkboxes
id - should match the ariaLabel prop of EzFormGroupEzFormGroup - used to group checkboxes
ariaLabel - should match the id prop of EzFormLabelgap - the gap between form labels (defaults to 0 for columns and 2 for rows)row - lays out the checkboxes horizontallylabelWidth - the defined width of each super checkbox button in a form grouptheme - a defined theme object with optional keys color and variant for super checkbox buttonsEzFormControlLabel - used to provide a label for a checkbox
control - the required control element (<EzCheckbox />)disabled - if true, the component is disabledhelperText - the helper text contenticon - the icon for the checkbox when using a super checkboxlabel - the label for the checkboxlabelIcons - an optional array of EzIcons to display after the labelvalue - the value of the form control labelFor larger, more visual checkbox buttons, provide an icon (<EzIcon />) along with an optional label to EzFormControlLabel.
labelWidth of type number to EzFormGroup. 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 EzFormGroup.
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 (filled-inverse is not supported - use custom defined values)checked and value properties to EzFormControlLabel as well as onChange to EzCheckbox.A checkbox can be made disabled by adding the optional disabled prop on either EzCheckbox (if standalone) or EzFormControlLabel (if in a group).
Supported styles should be used, but if you need to overwrite styles for the checkbox, form label, or form control label, you can do so using provided class names:
EzCheckbox, EzCheckbox-outlined, EzCheckbox-filled, EzCheckbox-filled-inverse, EzCheckbox-checked, EzCheckbox-unchecked, EzCheckbox-indeterminate, EzCheckbox-icon, EzCheckbox-disabled, EzCheckbox-inputEzFormGroupEzFormLabelEzFormControlLabel, EzFormControlLabel-label, EzFormControlLabel-helperTextEzSuperFormControlLabel, EzSuperFormControlLabel-checkbox, EzSuperFormControlLabel-checked, EzSuperFormControlLabel-label,EzSuperFormControlLabel-icon, EzSuperFormControlLabel-textSee WAI-ARIA accessibility guidelines for checkboxes.
All checkbox form controls should have corresponding labels using ariaLabel (hidden) or EzFormControlLabel.
Checkboxes should also have a name property, which is used to set or return the value of the named attribute of the checkbox field.
| Name | Type | Default | Description |
|---|---|---|---|
ariaLabel | string | checkbox | The aria-label of the checkbox element. |
checked | boolean | false | If true, the component is checked. |
color | EzThemeColors | primary | The color of the component. Supports theme palette properties and colors. |
defaultChecked | boolean | false | The default checked state for uncontrolled components. |
disabled | boolean | false | If true, the component is disabled. |
name | string | The name of the checkbox input. | |
onBlur | func | Callback fired when the state is blurred for controlled components. | |
onChange | func | Callback fired when the state is changed for controlled components. | |
onFocus | func | Callback fired when the state is focused for controlled components. | |
size | small | medium | large | medium | The size of the component. |
value | any | The value of the controlled component. | |
variant | outlined | filled | filled-inverse | outlined | The variant of the component. |