Checkbox
Checkbox is an input field representing a binary choice. Checkbox Group is a group of related binary choices.
new tab
<vaadin-checkbox-group
label="Export data"
.value="${this.value}"
@value-changed="${(event: CheckboxGroupValueChangedEvent) => {
this.value = event.detail.value;
}}"
theme="vertical"
>
<vaadin-checkbox value="0" label="Order ID"></vaadin-checkbox>
<vaadin-checkbox value="1" label="Product name"></vaadin-checkbox>
<vaadin-checkbox value="2" label="Customer"></vaadin-checkbox>
<vaadin-checkbox value="3" label="Status"></vaadin-checkbox>
</vaadin-checkbox-group>
Use Checkbox Group to group related items. Individual checkboxes should be used for options that aren’t related to each other in any way.
States
Disabled
Disable a field to mark it as currently unavailable. Disabled state is used for fields that aren’t editable and don’t need to be readable. Disabled elements can’t be focused and may be inaccessible to assistive technologies like screen readers.
Disabling can be preferable to hiding an element to prevent changes in layout when the element’s visibility changes, and to make users aware of its existence even when currently unavailable.
new tab
<vaadin-checkbox-group label="Departments" theme="vertical" disabled>
<vaadin-checkbox value="engineering" label="Engineering"></vaadin-checkbox>
<vaadin-checkbox value="human-resources" label="Human Resources"></vaadin-checkbox>
<vaadin-checkbox value="marketing" label="Marketing"></vaadin-checkbox>
<vaadin-checkbox value="operations" label="Operations"></vaadin-checkbox>
<vaadin-checkbox value="sales" label="Sales"></vaadin-checkbox>
</vaadin-checkbox-group>
Note
|
Read-only state
Checkbox doesn’t support read-only state.
|
Indeterminate
The indeterminate state can be used for a parent checkbox to show that there is a mix of checked and unchecked child items in a list, and to change the state of all child items at once.
new tab
<vaadin-checkbox
label="Notify users"
.checked="${selectedIds.length === items.length}"
.indeterminate="${selectedIds.length > 0 && selectedIds.length < items.length}"
@change="${(e: Event) => {
this.selectedIds = (e.target as HTMLInputElement).checked
? this.items.map((person) => String(person.id))
: [];
}}"
></vaadin-checkbox>
<vaadin-checkbox-group
label="Users to notify"
theme="vertical"
.value="${this.selectedIds}"
@value-changed="${(event: CheckboxGroupValueChangedEvent) => {
this.selectedIds = event.detail.value;
}}"
>
${items.map(
(person) => html`
<vaadin-checkbox
.value="${String(person.id)}"
label="${person.firstName} ${person.lastName}"
></vaadin-checkbox>
`
)}
</vaadin-checkbox-group>
Orientation
The component’s default orientation is horizontal but vertical orientation is recommended whenever possible as it’s easier for the user to scan a vertical list of options:
new tab
<vaadin-checkbox-group label="Working days" theme="vertical">
<vaadin-checkbox value="mon" label="Monday"></vaadin-checkbox>
<vaadin-checkbox value="tue" label="Tuesday"></vaadin-checkbox>
<vaadin-checkbox value="wed" label="Wednesday"></vaadin-checkbox>
<vaadin-checkbox value="thu" label="Thursday"></vaadin-checkbox>
<vaadin-checkbox value="fri" label="Friday"></vaadin-checkbox>
<vaadin-checkbox value="sat" label="Saturday"></vaadin-checkbox>
<vaadin-checkbox value="sun" label="Sunday"></vaadin-checkbox>
</vaadin-checkbox-group>
In cases where vertical space needs to be conserved, horizontal orientation can be used, but no more than 3 options are recommended:
new tab
<vaadin-checkbox-group label="Permissions">
<vaadin-checkbox value="read" label="Read"></vaadin-checkbox>
<vaadin-checkbox value="edit" label="Edit"></vaadin-checkbox>
<vaadin-checkbox value="delete" label="Delete"></vaadin-checkbox>
</vaadin-checkbox-group>
Best Practices
Labeling
Aim for short and descriptive labels using positive wording. Avoid negations.
new tab
@customElement('checkbox-labeling')
export class Example extends LitElement {
protected override createRenderRoot() {
const root = super.createRenderRoot();
// Apply custom theme (only supported if your app uses one)
applyTheme(root);
return root;
}
protected override render() {
return html`<vaadin-checkbox label="Yes, I agree"></vaadin-checkbox>`;
}
}
It’s important to provide labels for Checkbox Groups to clearly distinguish adjacent groups.
new tab
<vaadin-vertical-layout>
<vaadin-checkbox-group label="Manufacturer" theme="vertical">
<vaadin-checkbox value="0" label="Akuchi"></vaadin-checkbox>
<vaadin-checkbox value="1" label="Broek"></vaadin-checkbox>
<vaadin-checkbox value="2" label="Wulf"></vaadin-checkbox>
</vaadin-checkbox-group>
<vaadin-checkbox-group label="Status" theme="vertical">
<vaadin-checkbox value="0" label="In progress"></vaadin-checkbox>
<vaadin-checkbox value="1" label="Done"></vaadin-checkbox>
<vaadin-checkbox value="2" label="Cancelled"></vaadin-checkbox>
</vaadin-checkbox-group>
</vaadin-vertical-layout>
Related Components
Component | Usage recommendations |
---|---|
A field for selecting an item from a list of options which are presented in an overlay. Recommended when there is insufficient space for a Radio Button Group. | |
A filterable, lazy loading alternative to Select, recommended for ten or more items. | |
Scrollable list of options. Supports single and multi-select. | |
Corresponding component for mutually exclusive options, or “single-select”. |
F86F2BE5-1BDA-4E79-BD9E-6CE12742450B