<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HGSQD2L" height="0" width="0" style="display:none;visibility:hidden" title="GTM"></iframe>

Checkbox

Checkboxes can be used to turn an option "On" or "Off". SWAN checkbox provides the same functionality as a native <input type="checkbox"> enhanced with styling.

Use Checkbox...

  • To select more than one option.
  • If there is an indeterminate state to express when only a portion of the option group is selected.
  • To apply a setting that needs to be confirmed and reviewed by the user before they are submitted.
  • Typically inside a Selection Set skin="simple-column", as this provides a preset label and the correct spacing.

Don't use Checkbox...

  • To select one option from a list of options. Use Radio Button instead.
  • To prompt users to choose between two mutually exclusive options that always has a default value, like “on” or “off”. Use Toggle Switch instead.

Default

The default Checkbox has three states.

Unchecked

The preview has been updated.

Checked

The preview has been updated.

Indeterminate

  • Use indeterminate for a parent checkbox to represent a mix of sub-options that are checked and unchecked.
  • As a result, the parent checkbox cannot definitively be either 'checked' or 'unchecked'. This state renders a UI visual that masks the real value of the checkbox. The actual state of the checkbox is still either checked or unchecked.

The preview has been updated.

Checkbox group

Refer to the Selection Set skin=”simple-column” guidelines.

Favorite

Use skin="favorite" to display the Checkbox as a heart shape.

The preview has been updated.

Use instant to make the checkbox animate instantly, in cases where having the animation would be distracting.

The preview has been updated.

Accessibility

  • Add aria-required="true" to the input if a checkbox is a required field before the user can submit the page.
  • If not used inside a Selection Set, and if there is more than one checkbox in that group of choices, place either inside:
    • A <fieldset> (refer to Fieldset), or
    • An element with the attribute role="group". This wrapper element must have an aria-labelledby attribute whose value is the id of the element that acts as a title for the group — or if the group does not have a visible title, an aria-label attribute whose value is a descriptive title of the group. The value of aria-label must be localized, as some browsers will read it to the user.

Checkbox in a Selection Set vs Checkbox on its own

  • Checkboxes are typically used inside a component, like a Selection Set skin="simple-column", as this provides a preset label and the correct spacing.
  • A skin="favorite" checkbox may be used on its own because a label is not needed.

Props

Checkbox
This component is implemented using the <input /> as the root element. You can utilize the native attributes supported by <input /> tag. The ref is directly assigned to the root element, allowing you to access and manipulate it as needed.
See core props for additional props that can be applied to this component.
proptyperequireddescriptiondefault
skin"standard" | "favorite" | nullfalse
The visual style of the Checkbox. One of: "standard", "favourite".
standard
indeterminateboolean | nullfalse
An indeterminate checkbox means that its state is unclear. Typically, this is used when the checkbox has some sub-options under it.
null
instantboolean | nullfalse
If set to true, the checkbox will animate instantly.
false

Related

Was this page useful?

Thanks for your feedback!

Feel free to include your name if you wish to have a follow up conversation.


Published: Jan 7, 2022Last updated: Oct 17, 2024