useCheckboxGroupState
Provides state management for a checkbox group component. Provides a name for the group, and manages selection and focus state.
install | yarn add react-stately |
---|---|
version | 3.30.1 |
usage | import {useCheckboxGroupState} from 'react-stately' |
API#
useCheckboxGroupState(
(props:
)):
Interface#
Properties
Name | Type | Description |
value | readonly string[] | Current selected values. |
isDisabled | boolean | Whether the checkbox group is disabled. |
isReadOnly | boolean | Whether the checkbox group is read only. |
isInvalid | boolean | Whether the checkbox group is invalid. |
isRequired | boolean | Whether the checkboxes in the group are required. This changes to false once at least one item is selected. |
realtimeValidation |
| Realtime validation results, updated as the user edits the value. |
displayValidation |
| Currently displayed validation results, updated when the user commits their changes. |
Methods
Method | Description |
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. |