<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.

Info:

SWAN checkbox provides the same functionality as a native input type="checkbox" enhanced with styling.

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.

Info:

In the React API, you can achieve the indeterminate state by using the indeterminate prop.

Info:

In the Vanilla API, there is no declarative syntax for indeterminate checkboxes because HTML does not provide one. Instead, use JavaScript to set the checkbox to indeterminate. Refer to MDN for more details.

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.

Info:

To provide a label or labelling text, add an associated <label> tag (which can be visually hidden), or localized text in an aria-label attribute.

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: Sep 3, 2024