Checkbox Group
View as MarkdownA group of checkboxes for selecting multiple values.
Features
Permalink to heading "Features"- Selects several values at once
- Optional limit on the selection with
maxSelectedValues - Full keyboard navigation support
- Syncs with native inputs for form submission
- Works with the Field component
<primitives:checkboxGroup.root>
<primitives:checkboxGroup.label />
<primitives:checkbox.root>
<primitives:checkbox.control>
<primitives:checkbox.indicator />
</primitives:checkbox.control>
<primitives:checkbox.label />
<primitives:checkbox.hiddenInput />
</primitives:checkbox.root>
</primitives:checkboxGroup.root>
Installation
Permalink to heading "Installation"typo3 ui:add checkboxGroup
Please copy the files manually from GitHub into your project.
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"Default checked
Permalink to heading "Default checked"Pass the values to preselect as a list in defaultValue. The notification preferences start with email and push checked.
Disabled items
Permalink to heading "Disabled items"Set disabled on a single checkbox.root to lock that option while the others stay interactive.
Disabled group
Permalink to heading "Disabled group"Set disabled on checkboxGroup.root to lock every option at once.
Maximum selections
Permalink to heading "Maximum selections"Set maxSelectedValues to cap the selection. Pick two colors in the demo and the remaining one is disabled until you uncheck another.
Select all
Permalink to heading "Select all"A checkbox above the group checks or clears every option, and shows the indeterminate state while only some are checked. The entry file tab shows how the two are wired.
API Reference
Permalink to heading "API Reference"The following tables cover the available props of the Fluid Primitives.
checkboxGroup.root
Permalink to heading "checkboxGroup.root"Provides shared state for a group of related checkboxes. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
defaultValue | string[]The initial value of the checkbox group. Use when you don't need to control the value of the checkbox group. Inherited from a surrounding field when available. | No | - |
name | stringThe name of the input fields in the checkbox group. Useful for form submission. Inherited from a surrounding field when available. | No | - |
form | stringThe form id the checkbox group belongs to. | No | - |
disabled | booleanIf true, the checkbox group is disabled. Inherited from a surrounding field when available. | No | - |
readOnly | booleanIf true, the checkbox group is read-only. Inherited from a surrounding field when available. | No | - |
required | booleanIf true, the checkbox group is required. Inherited from a surrounding field when available. | No | - |
invalid | booleanIf true, the checkbox group is invalid. Inherited from a surrounding field when available. | No | - |
maxSelectedValues | integerThe maximum number of selected values. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
rootId | stringThe root ID of the component, used for hydration and identification. | No | - |
ids | arrayThe IDs of of the component parts for composition. | No | [] |
autoMount | booleanWhether the client initializes the component on its own. Set it to false to mount it yourself with `mount()` | No | true |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
checkboxGroup.label
Permalink to heading "checkboxGroup.label"Labels the checkbox group. Renders a <span> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-disabled | Present when disabled |
data-readonly | Present when read-only |
data-invalid | Present when invalid |
Machine options
Permalink to heading "Machine options"| Name | Description | Default |
|---|---|---|
id | stringThe unique identifier of the checkbox group. | - |
ids | Record<string, string> | undefinedThe ids of the elements in the checkbox group. Useful for composition. | - |
defaultValue | string[] | undefinedThe initial value of the checkbox group (uncontrolled) | - |
value | string[] | undefinedThe controlled value of the checkbox group | - |
name | string | undefinedThe name of the input fields in the checkbox group (for form submission) | - |
form | string | undefinedThe form id the checkbox group belongs to | - |
disabled | boolean | undefinedIf true, the checkbox group is disabled | - |
readOnly | boolean | undefinedIf true, the checkbox group is read-only | - |
required | boolean | undefinedIf true, the checkbox group is required | - |
invalid | boolean | undefinedIf true, the checkbox group is invalid | - |
maxSelectedValues | number | undefinedThe maximum number of selected values | - |
onValueChange | ((details: { value: string[] }) => void) | undefinedCalled when the value changes | - |
Machine JavaScript API
Permalink to heading "Machine JavaScript API"| Name | Type | Description |
|---|---|---|
value | string[] | The current value of the checkbox group |
name | string | undefined | The name for form submission |
disabled | boolean | Whether the checkbox group is disabled |
readOnly | boolean | Whether the checkbox group is read-only |
invalid | boolean | Whether the checkbox group is invalid |
isChecked | (value: string) => boolean | Check if a value is selected |
setValue | (value: string[]) => void | Set the entire value array |
addValue | (value: string) => void | Add a value to the selection |
removeValue | (value: string) => void | Remove a value from the selection |
toggleValue | (value: string) => void | Toggle a value |
getItemProps | (props: CheckboxGroupItemProps) => CheckboxGroupItemState | Get props to merge into a checkbox item |