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.
package com.vaadin.demo.component.checkbox;
import com.vaadin.flow.component.checkbox.CheckboxGroup;
import com.vaadin.flow.component.checkbox.CheckboxGroupVariant;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.Route;
@Route("checkbox-disabled")
public class CheckboxDisabled extends Div {
public CheckboxDisabled() {
// tag::snippet[]
CheckboxGroup<String> disabledCheckGroup = new CheckboxGroup<>();
disabledCheckGroup.setLabel("Departments");
disabledCheckGroup.setItems("Engineering", "Human Resources",
"Marketing", "Operations", "Sales");
disabledCheckGroup.addThemeVariants(CheckboxGroupVariant.LUMO_VERTICAL);
disabledCheckGroup.setEnabled(false);
add(disabledCheckGroup);
// end::snippet[]
}
}
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.
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:
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.