Controlled checkbox with a label and optional helper/error text. Wraps Checkbox inside a Headless UI Switch group.
Use @uxf/ui/checkbox-input for a labeled checkbox that you control yourself (you own value / onChange).
@uxf/form form: use @uxf/form/checkbox-input instead — it registers the field with react-hook-form, derives the invalid state from validation, and renders the validation message. Reach for the ui component only for a standalone, controlled checkbox outside a form.Checkbox.CheckboxList.import { CheckboxInput } from "@uxf/ui/checkbox-input";
import { useState } from "react";
function Example() {
const [checked, setChecked] = useState(false);
const onChange = (value: boolean | undefined) => setChecked(value ?? false);
return <CheckboxInput label="I agree" name="agree" onChange={onChange} value={checked} />;
}
Extends FormControlProps<boolean | undefined> (value, onChange, name, onBlur, onFocus, isDisabled, isFocused, isReadOnly, isInvalid, isRequired).
| Prop | Type | Default | Description |
|---|---|---|---|
value |
boolean | undefined |
— | Required. Checked state. |
onChange |
(value: boolean | undefined, event?, ...args) => void |
— | Required. Called with the toggled value. |
name |
string |
— | Required. Field name. |
label |
ReactNode |
— | Required. Label content. |
helperText |
ReactNode |
— | Text shown under the label (used for the error message). |
hiddenLabel |
boolean |
false |
Visually hides the label (kept for screen readers). |
indeterminate |
boolean |
false |
Shows the indeterminate (minus) icon. |
size |
CheckboxSize |
"default" |
Checkbox size (default, lg). |
isDisabled |
boolean |
false |
Non-interactive state. |
isReadOnly |
boolean |
false |
Prevents value changes. |
isInvalid |
boolean |
false |
Error state (links helperText to the control via an error id). |
isRequired |
boolean |
false |
Marks the field required. |
isFocused |
boolean |
false |
Forces the focus indicator. |
onBlur, onFocus |
FocusEventHandler |
— | Focus handlers. |
id |
string |
— | Element id (an id is generated with useId when omitted). |
className |
string |
— | Extra class names on the wrapper. |
style |
CSSProperties |
— | Inline styles on the wrapper. |
Size accepts default and lg, forwarded to the underlying Checkbox. The wrapper reflects isDisabled, isReadOnly, isInvalid and isRequired as state classes.
This component does not validate on its own — pass isInvalid and helperText yourself, or use the @uxf/form/checkbox-input twin, which fills them from the form state.
Import the component stylesheet once in your global CSS. It renders a Checkbox, so that stylesheet is required too:
@import url("@uxf/ui/css/checkbox-input.css");
@import url("@uxf/ui/css/checkbox.css");
Also requires the global @uxf/ui token layer, set up once per app — see @uxf/ui setup.