Checkbox
Allow users to select multiple options from a set.
Allow users to select multiple options from a set.
npm install @vrembem/checkbox@use "@vrembem/checkbox";Checkbox uses design token CSS variables in a reference and fallback pattern. Variables are referenced in the component's styles but are not directly defined; instead, they are provided with sensible fallbacks.
| Variable | Fallback |
|---|---|
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
There are no variables that match your search.
Checkbox form controls are composed using the <input type="checkbox"> element along with the .checkbox class.
<input class="checkbox" type="checkbox" />// Get checkboxes with "mixed" status
const checkboxes = document.querySelectorAll(
"input[type='checkbox'][aria-checked='mixed']"
);
// Apply the indeterminate state
checkboxes.forEach((checkbox) => checkbox.indeterminate = true);Indeterminate checkboxes need to be set in JavaScript though styling is provided by Vrembem for the indeterminate states (see example above). Review MDN documentation for more details.
For checkboxes with labels, wrap the checkbox element along with the text label using the <label> element.
<label>
<input class="checkbox" type="checkbox" />
<span>Checkbox with a label</span>
</label>Adding the boolean disabled attribute to the input element will provide visual indication that the checkbox is not available for use.
<input class="checkbox" type="checkbox" disabled />Adding the is-invalid class or aria-invalid="true" attribute to the checkbox component will provide visual indication that the form-control value is invalid. Invalid state is also triggered by the native :user-invalid state.
<input class="checkbox is-invalid" type="checkbox" />