Checkbox
Checkboxes allow users to choose one or more items from a list of options, providing a convenient way to make selections. They typically appear in forms.
<sl-form-field label="Subjects">
<sl-checkbox-group value='["0","2"]'>
<sl-checkbox value="0">Mathematics</sl-checkbox>
<sl-checkbox value="1">Geography</sl-checkbox>
<sl-checkbox value="2">Physics</sl-checkbox>
<sl-checkbox value="3" disabled>History</sl-checkbox>
</sl-checkbox-group>
</sl-form-field>
When to use
The following guidance describes when to use the Checkbox component.
When not to use
The following guidance describes when not to use the Checkbox component.
Anatomy
Item | Name | Description | Optional |
---|---|---|---|
1 | Field Label | The group label, positioned at the top of a checkbox group, provides a clear and concise description of the category or context for the choices contained within the group. It serves as a visual and informational cue that helps users understand the purpose of the options and facilitates more straightforward decision-making in the user interface. More information about group labels you can find in the Accessibility tab. | No |
2 | Checkbox input (unchecked) | An unchecked checkbox input is like a blank canvas. It represents an option or choice that is currently unselected, waiting for the user to make a decision and activate it. | No |
3 | Icon | The icon in a checkbox is a visual confirmation of user selection. | No |
4 | Label | A checkbox label is a brief, descriptive text next to the checkbox element. | Yes |
5 | Helper Text & Hint | The help text for a checkbox group is a informative component, it provides users with guidance and clarifications related to the available options. It assists users in making informed decisions by offering context, explanations, or additional details about the purpose or implications of the choices within the group. More information about help text you can find in the Accessibility tab. | Yes |
6 | Checkboxes | The checkbox group is designed with a minimum requirement of two options and allows a maximum of five selections. When the list of options exceeds this maximum limit, it's advisable to consider alternative design elements like a dropdown menu or combobox. These options provide a more user-friendly way to navigate and select from a larger set of choices, ensuring a streamlined and efficient user experience. | No |
Sizing
Status
The checkbox input facilitates multiple statuses, including unchecked, checked, and indeterminate. By default, a set of checkboxes the options are initially unchecked.
Variants
The default, valid, and invalid checkboxes play a pivotal role in offering users essential feedback on their interactions and guiding them toward necessary actions. These variants serve as visual indicators, providing users with clear cues about the status of their selections.
Figma Options
With these options, you can tweak the appearance of the checkbox in Figma. They are available in the Design Panel so you can compose the checkbox to exactly fit the user experience need for the use case you are working on.
Item | Options | Description |
---|---|---|
Size | 'md' (Default), 'lg' | The checkbox and the label element come in two sizes: medium (default) and large, providing flexibility to align with your design requirements. |
Variant | 'default', 'invalid', 'valid' | This variants are provide to give feedback to the user about the interaction o the necessity of another action more. |
States | 'idle', 'hover', 'active', 'disabled' | Checkboxes interactive states to replicate the real behavior into your UI. |
Status | 'Checked', 'Unchecked' | To determinate between selected and unselect version. |
Indeterminate | 'on', 'off' | To turn the indeterminate state on or off. |
Label | 'on', 'off' | To turn to label on or off (label is turned on by default) |
Label text | 'input text' | To insert the text of the label. |
Focus ring | 'on', 'off' | Turn the focus ring option to show the focus state of the checkbox. |
Behavior
Label overflow wrap
When a label is too long for the available horizontal space, it wraps to form another line, with the text aligned to the top.
Clickable area
The checkbox has a clickable area around both the checkbox and label for more space to press. We've left a bit of space on the left side to ensure smooth alignment and avoid any unexpected layout issues.
Focusable area
Both the checkbox input and label are interactive elements, allowing users to interact with them. However, when it comes to focusing, whether through keyboard navigation or voice commands, the visible focus state is only visible on the checkbox itself.
Validation
If an issue arises after submitting a form, the help text will switch to an 'invalid' state. This serves as a valuable guide for users, clearly explaining the necessary actions to resolve any problems.
Default checked
Set the initial state of the checkbox according to your preferences. You can choose whether it starts as checked or unchecked by default, providing you with control over its initial behavior in your interface.
Indeterminate State
Useful in scenarios where checkboxes are nested, we've incorporated an indeterminate state. Users can't set the indeterminate state by clicking on it, but it can be programmatically set to this state.