A component that provides shared state for a series of checkboxes. The CheckboxGroup component extends Base UI's CheckboxGroup. It stacks the checkboxes vertically with a fixed gap.
Here is the component implementation code that you can copy to your project:
// https://devie-ui.com/components/checkbox-group
// https://base-ui.com/react/components/checkbox-group
import { CheckboxGroup as BaseCheckboxGroup } from "@base-ui/react/checkbox-group";
import clsx from "clsx";
import styles from "./CheckboxGroup.module.scss";
function CheckboxGroup({ className, ...props }: CheckboxGroup.Props) {
return (
<BaseCheckboxGroup className={clsx(styles.root, className)} {...props} />
);
}
namespace CheckboxGroup {
export type Props = Omit<BaseCheckboxGroup.Props, "className"> & {
className?: string;
};
export type State = BaseCheckboxGroup.State;
export type ChangeEventDetails = BaseCheckboxGroup.ChangeEventDetails;
}
export default CheckboxGroup;Use value and onValueChange to control the group state. Give each Checkbox.Root a unique value.
Set parent on a Checkbox.Root to check or uncheck every checkbox in the group. Pass allValues to the group so the parent turns indeterminate when only some are checked.