Checkbox.GroupProvider Component
Dennis GĂśring
đ Summary
Expose the
useCheckboxGroup
hook and the <Checkbox.GroupProvider>
component to allow manual creation and contextual provisioning of a checkbox group â consistent with how other primitives (like useDialog + DialogProvider) operate in Ark UI.đ Context
Ark UI internally uses a state machine to manage checkbox groups, but this is currently only accessible via the CheckboxGroup component props. Other components in the library (e.g., Dialog, Tabs, Combobox) already expose their state machines and providers, making them more flexible and composable.
Letâs bring checkbox groups up to that level of power.
đŻ Motivation
⢠Enable advanced use cases: âSelect Allâ, validation, deeply nested group logic, etc.
⢠Improve integration with state management/form libraries.
⢠Avoid awkward prop drilling for deeply nested checkboxes or helper components.
⢠Align with the compositional API used elsewhere in Ark UI.
â
Proposed API
import { useCheckboxGroup, Checkbox } from '@ark-ui/react'
const group = useCheckboxGroup({
name: 'fruits',
value: selectedValues,
onChange: setSelectedValues,
})
return (
<Checkbox.GroupProvider value={group}>
<Checkbox.Root value="apple">
<Checkbox.Label>Apple</Checkbox.Label>
<Checkbox.Control />
</Checkbox.Root>
<Checkbox.Root value="banana">
<Checkbox.Label>Banana</Checkbox.Label>
<Checkbox.Control />
</Checkbox.Root>
<SelectAllCheckbox />
</Checkbox.GroupProvider>
)
And an example helper component:
function SelectAllCheckbox() {
const group = useCheckboxGroupContext() // if exposed
const allValues = ['apple', 'banana']
const isAllSelected = allValues.every(val => group.value.includes(val))
return (
<button
onClick={() =>
group.setValue(isAllSelected ? [] : allValues)
}
>
{isAllSelected ? 'Uncheck All' : 'Check All'}
</button>
)
}
đ Implementation Notes
â˘
useCheckboxGroup()
should return the full state machine API.â˘
<Checkbox.GroupProvider value={...} />
will inject context to all nested <Checkbox.Root>
components.⢠Optional: expose useCheckboxGroupContext() for downstream access.
â
Benefits
⢠Encourages composable, decoupled checkbox UIs.
⢠Unlocks advanced checkbox group logic.
⢠Matches existing patterns in Ark UI (Dialog, Tabs, Menu, etc.).
⢠Fully backward-compatible with current CheckboxGroup prop-based usage.