Checkbox Checkboxes are a form control that can be turned on or off.

The use of checkboxes indicate that several related options are available, and that more than one of them may be simultaneously selected.

Table of contents

Standard usage
Ternary / Indeterminate

Usage guidelines

When to use
  • Use a checkbox when there are multiple related options to choose from, and several of them may be selected.
  • If there is only one option, use a switch instead.

Checkboxes should not be used for binary selection.

Switches should be used for binary selection instead.

How to use
  • When placing multiple checkboxes near one another, stack them vertically rather than horizontally.
  • Checkbox components require both a native <input type="checkbox"> and a <label> child element in order to work.
  • When there are many options available and it is likely that someone might want to select all or almost all of them, consider using the ternary variation in order to speed up the workflow. This variation lets one checkbox toggle many related checkboxes at the same time.
Accessibility
  • The keyboard support enjoyed by native checkbox elements will still work for Resonance checkboxes; they can still be tabbed through, and the spacebar will still toggle them.


Attributes

An asterisk next to a value denotes that it is the default value for that attribute. Unless noted otherwise, attributes should be added to the component element directly. Boolean attributes work based on their presence or absence from the component.

<res-component booleanAttribute stringAttribute="parameter">    
  <child-element></child-element>
</res-component>
AttributeTypeDescription
checkedbooleanSet initial state to checked
disabledbooleanSet initial state to disabled
indeterminatebooleanSet initial state to indeterminate
ternarybooleanSet as a ternary leader
leaderstringSet as a ternary follower, stores id of ternary leader

API

NameTypeDataDescription
checkedpropertybooleanGet/set checked state
disabledpropertybooleanGet/set disabled state
indeterminatepropertybooleanGet/set indeterminate state
ternarypropertybooleanGet/set ternary leader state
leaderpropertystringGet/set ternary follower state
setupTernaryFollowersmethod---Connects a ternary leader to its ternary followers

Notes

Required DOM

Without these, the component will throw an error on render.

  • <label> - Label element
  • <input type="checkbox"> - Checkbox element

History

VersionNote
0.13.0Add support for ternary res-checkboxes.
0.12.0Apply new spacing scale. Add min-width to the checkbox so that it doesn't get shrunk when the component is too narrow.
0.11.10Focus the label selector so it doesn't get applied inconsistently.
0.11.2Prevent duplicate elements from being created
0.11.0Tweaks to accommodate new icon set.
0.10.0Color update
0.7.0Web component refactor
0.5.0Total refactor! Component requires a label and input, but does everything else for you. Label can go on either side of checkbox too.
0.3.0Thinner border
0.2.0Cleaner markup. Uses res-icon for checkmark.
0.1.0Initial build to spec.