@crustack/checkbox
Build performant & accessible Checkbox components.
Features
- Works with native
<form> - Full keyboard navigation.
- Can be controlled or uncontrolled.
- Indeterminate support (requires "use client")
Installation
Basic Example
You don’t need to worry about handling the positioning or accessibility of the elements. Just focus on styling them as needed.
:::caution
To take full advantage of the "peer" selector, ensure the order of the elements remains unchanged.
:::
With inderterminate
API Reference
👉 defineCheckbox
DefineCheckboxOptions
| Prop | Type | Default |
|---|---|---|
cursorStyle? | string | false | 'pointer' |
hitboxPadding? | string | number | 0 |
👉 checkbox.Root
The top-level element, which accepts the same props as a standard <div>.
Sizing this element will automatically size all child elements.
👉 checkbox.HiddenInput
The visually hidden input element, which accepts the same props as a standard <input>.
Styling is handled automatically, so you don’t need to apply any additional styles.
👉 checkbox.Box
The visual part of the checkbox, which accepts the same props as a standard <div>.
For proper styling, it should be the next sibling of the HiddenInput.
Its size is inherited from the Root element.
👉 checkbox.Icon
The container for the icon of the checkbox, which accepts the same props as a standard <div>.
It automatically centers its child within the Box element.
👉 checkbox.useIndeterminate
A utility hook for managing the indeterminate state of the checkbox.
Arguments
| Prop | Type | Default |
|---|---|---|
(1) checked? | boolean | "indeterminate" | - |
Returns
| Prop | Type | Default |
|---|---|---|
checked? | boolean | - |
ref? | React.RefObject<HTMLInputElement | null> | - |