useCheckboxGroup

Provides the behavior and accessibility implementation for a checkbox group component. Checkbox groups allow users to select multiple items from a list of options.

Favorite sports
Example
CheckboxGroup.tsx
CheckboxGroup.css
Checkbox.css
import {CheckboxGroup, Checkbox} from './CheckboxGroup';

<CheckboxGroup label="Favorite sports">
  <Checkbox value="soccer" isDisabled>Soccer</Checkbox>
  <Checkbox value="baseball">Baseball</Checkbox>
  <Checkbox value="basketball">Basketball</Checkbox>
</CheckboxGroup>

API

Shows a checkbox group component with labels pointing to its parts, including the checkbox group label, and group element containing three checkboxes with input and label elements.ShoppingMusicTravelInterestsInputCheckbox group labelGroupCheckbox label
<CheckboxGroup>
  <Label />
  <CheckboxField />
  <Text slot="description" />
  <FieldError />
</CheckboxGroup>
useCheckboxGroupState(props: ): useCheckboxGroup(props: , state: ): useCheckboxGroupItem( props: , state: , inputRef: <HTMLInputElementnull> ):

CheckboxGroupState

Properties

NameType
isDisabledboolean

Whether the checkbox group is disabled.

isReadOnlyboolean

Whether the checkbox group is read only.

realtimeValidation

Realtime validation results, updated as the user edits the value.

displayValidation

Currently displayed validation results, updated when the user commits their changes.

valuereadonly string[]

Current selected values.

defaultValuereadonly string[]

Default selected values.

Methods

isSelected(value: string): boolean
Returns whether the given value is selected.
setValue(value: string[]): void
Sets the selected values.
addValue(value: string): void
Adds a value to the set of selected values.
removeValue(value: string): void
Removes a value from the set of selected values.
toggleValue(value: string): void
Toggles a value in the set of selected values.
setInvalid(value: string, validation: ): void
Sets whether one of the checkboxes is invalid.
updateValidation(result: ): void
Updates the current validation result. Not displayed to the user until commitValidation is called.
resetValidation(): void
Resets the displayed validation state to valid when the user resets the form.
commitValidation(): void
Commits the realtime validation so it is displayed to the user.

AriaCheckboxGroupProps

NameType
isDisabledboolean

Whether the input is disabled.

isReadOnlyboolean

Whether the input can be selected but not changed by the user.

valuestring[]

The current value (controlled).

defaultValuestring[]

The default value (uncontrolled).

onChange(value: T) => void

Handler that is called when the value changes.

CheckboxGroupAria

NameType
groupPropsDOMAttributes

Props for the checkbox group wrapper element.

labelPropsDOMAttributes

Props for the checkbox group's visible label (if any).

descriptionPropsDOMAttributes

Props for the checkbox group description element, if any.

errorMessagePropsDOMAttributes

Props for the checkbox group error message element, if any.

validationDetailsValidityState

The native validation details for the input.

AriaCheckboxGroupItemProps

NameType
isIndeterminateboolean

Indeterminism is presentational only. The indeterminate visual representation remains regardless of user interaction.

childrenReactNode

The label for the element.

isDisabledboolean

Whether the input is disabled.

isReadOnlyboolean

Whether the input can be selected but not changed by the user.

onChange(isSelected: boolean) => void

Handler that is called when the element's selection state changes.