Skip to main content

Checkbox Group

View as Markdown

A group of checkboxes for selecting multiple values.

Select options:
<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>
typo3 ui:add checkboxGroup

Read more about installing Components and Primitives.

Pass the values to preselect as a list in defaultValue. The notification preferences start with email and push checked.

Notification preferences:

Set disabled on a single checkbox.root to lock that option while the others stay interactive.

Select plans:

Set disabled on checkboxGroup.root to lock every option at once.

Select features:

Set maxSelectedValues to cap the selection. Pick two colors in the demo and the remaining one is disabled until you uncheck another.

Pick up to 2 colors:

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.

The following tables cover the available props of the Fluid Primitives.

Provides shared state for a group of related checkboxes. Renders a <div> element.

NameDescriptionRequiredDefault
defaultValuestring[]
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
-
namestring
The name of the input fields in the checkbox group. Useful for form submission. Inherited from a surrounding field when available.
No
-
formstring
The form id the checkbox group belongs to.
No
-
disabledboolean
If true, the checkbox group is disabled. Inherited from a surrounding field when available.
No
-
readOnlyboolean
If true, the checkbox group is read-only. Inherited from a surrounding field when available.
No
-
requiredboolean
If true, the checkbox group is required. Inherited from a surrounding field when available.
No
-
invalidboolean
If true, the checkbox group is invalid. Inherited from a surrounding field when available.
No
-
maxSelectedValuesinteger
The maximum number of selected values.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Labels the checkbox group. Renders a <span> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid
NameDescriptionDefault
idstring
The unique identifier of the checkbox group.
-
idsRecord<string, string> | undefined
The ids of the elements in the checkbox group. Useful for composition.
-
defaultValuestring[] | undefined
The initial value of the checkbox group (uncontrolled)
-
valuestring[] | undefined
The controlled value of the checkbox group
-
namestring | undefined
The name of the input fields in the checkbox group (for form submission)
-
formstring | undefined
The form id the checkbox group belongs to
-
disabledboolean | undefined
If true, the checkbox group is disabled
-
readOnlyboolean | undefined
If true, the checkbox group is read-only
-
requiredboolean | undefined
If true, the checkbox group is required
-
invalidboolean | undefined
If true, the checkbox group is invalid
-
maxSelectedValuesnumber | undefined
The maximum number of selected values
-
onValueChange((details: { value: string[] }) => void) | undefined
Called when the value changes
-
NameTypeDescription
valuestring[]The current value of the checkbox group
namestring | undefinedThe name for form submission
disabledbooleanWhether the checkbox group is disabled
readOnlybooleanWhether the checkbox group is read-only
invalidbooleanWhether the checkbox group is invalid
isChecked(value: string) => booleanCheck if a value is selected
setValue(value: string[]) => voidSet the entire value array
addValue(value: string) => voidAdd a value to the selection
removeValue(value: string) => voidRemove a value from the selection
toggleValue(value: string) => voidToggle a value
getItemProps(props: CheckboxGroupItemProps) => CheckboxGroupItemStateGet props to merge into a checkbox item