Checkbox
Boolean toggle with label.
Examples
Default
Demo.tsxtsx
import { Checkbox } from '@var-ui/react';
<Checkbox>Accept terms</Checkbox>Props
Accessibility
Built on React Aria Components where applicable.
Boolean toggle with label.
Boolean toggle with label.
import { Checkbox } from '@var-ui/react';
<Checkbox>Accept terms</Checkbox>Built on React Aria Components where applicable.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Label rendered beside the checkbox control. |
| Prop | Type | Default | Description |
|---|---|---|---|
aria-controls | string | undefined | — | Identifies the element (or elements) whose contents or presence are controlled by the current element. |
aria-describedby | string | undefined | — | Identifies the element (or elements) that describes the object. |
aria-details | string | undefined | — | Identifies the element (or elements) that provide a detailed, extended description for the object. |
aria-errormessage | string | undefined | — | Identifies the element that provides an error message for the object. |
aria-label | string | undefined | — | Defines a string value that labels the current element. |
aria-labelledby | string | undefined | — | Identifies the element (or elements) that labels the current element. |
autoFocus | boolean | undefined | — | Whether the element should receive focus on render. |
className | ClassNameOrFunction<CheckboxRenderProps> | undefined | 'react-aria-Checkbox' | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
dir | string | undefined | — | — |
excludeFromTabOrder | boolean | undefined | — | Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available. |
form | string | undefined | — | The `<form>` element to associate the input with. The value of this attribute must be the id of a `<form>` in the same document. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input#form). |
hidden | boolean | undefined | — | — |
id | string | undefined | — | The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). |
inert | boolean | undefined | — | — |
inputRef | RefObject<HTMLInputElement | null> | undefined | — | A ref for the HTML input element. |
isDisabled | boolean | undefined | — | Whether the input is disabled. |
isIndeterminate | boolean | undefined | — | Indeterminism is presentational only. The indeterminate visual representation remains regardless of user interaction. |
isInvalid | boolean | undefined | — | Whether the input value is invalid. |
isReadOnly | boolean | undefined | — | Whether the input can be selected but not changed by the user. |
isRequired | boolean | undefined | — | Whether user input is required on the input before form submission. |
lang | string | undefined | — | — |
name | string | undefined | — | The name of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname). |
onAnimationEnd | AnimationEventHandler<HTMLLabelElement> | undefined | — | — |
onAnimationEndCapture | AnimationEventHandler<HTMLLabelElement> | undefined | — | — |
onAnimationIteration | AnimationEventHandler<HTMLLabelElement> | undefined | — | — |
onAnimationIterationCapture | AnimationEventHandler<HTMLLabelElement> | undefined | — | — |
onAnimationStart | AnimationEventHandler<HTMLLabelElement> | undefined | — | — |
onAnimationStartCapture | AnimationEventHandler<HTMLLabelElement> | undefined | — | — |
onAuxClick | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onAuxClickCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onBlur | ((e: FocusEvent<Element, Element>) => void) | undefined | — | Handler that is called when the element loses focus. |
onClick | ((e: MouseEvent<FocusableElement, MouseEvent>) => void) | undefined | — | **Not recommended – use `onPress` instead.** `onClick` is an alias for `onPress` provided for compatibility with other libraries. `onPress` provides additional event details for non-mouse interactions. |
onClickCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onContextMenu | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onContextMenuCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onDoubleClick | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onDoubleClickCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onFocus | ((e: FocusEvent<Element, Element>) => void) | undefined | — | Handler that is called when the element receives focus. |
onFocusChange | ((isFocused: boolean) => void) | undefined | — | Handler that is called when the element's focus status changes. |
onGotPointerCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onGotPointerCaptureCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onHoverChange | ((isHovering: boolean) => void) | undefined | — | Handler that is called when the hover state changes. |
onHoverEnd | ((e: HoverEvent) => void) | undefined | — | Handler that is called when a hover interaction ends. |
onHoverStart | ((e: HoverEvent) => void) | undefined | — | Handler that is called when a hover interaction starts. |
onKeyDown | ((e: KeyboardEvent) => void) | undefined | — | Handler that is called when a key is pressed. |
onKeyUp | ((e: KeyboardEvent) => void) | undefined | — | Handler that is called when a key is released. |
onLostPointerCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onLostPointerCaptureCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseDown | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseDownCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseEnter | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseLeave | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseMove | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseMoveCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseOut | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseOutCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseOver | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseOverCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseUp | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onMouseUpCapture | MouseEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerCancel | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerCancelCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerDown | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerDownCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerEnter | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerLeave | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerMove | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerMoveCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerOut | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerOutCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerOver | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerOverCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerUp | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPointerUpCapture | PointerEventHandler<HTMLLabelElement> | undefined | — | — |
onPress | ((e: PressEvent) => void) | undefined | — | Handler that is called when the press is released over the target. |
onPressChange | ((isPressed: boolean) => void) | undefined | — | Handler that is called when the press state changes. |
onPressEnd | ((e: PressEvent) => void) | undefined | — | Handler that is called when a press interaction ends, either over the target or when the pointer leaves the target. |
onPressStart | ((e: PressEvent) => void) | undefined | — | Handler that is called when a press interaction starts. |
onPressUp | ((e: PressEvent) => void) | undefined | — | Handler that is called when a press is released over the target, regardless of whether it started on the target or not. |
onScroll | UIEventHandler<HTMLLabelElement> | undefined | — | — |
onScrollCapture | UIEventHandler<HTMLLabelElement> | undefined | — | — |
onTouchCancel | TouchEventHandler<HTMLLabelElement> | undefined | — | — |
onTouchCancelCapture | TouchEventHandler<HTMLLabelElement> | undefined | — | — |
onTouchEnd | TouchEventHandler<HTMLLabelElement> | undefined | — | — |
onTouchEndCapture | TouchEventHandler<HTMLLabelElement> | undefined | — | — |
onTouchMove | TouchEventHandler<HTMLLabelElement> | undefined | — | — |
onTouchMoveCapture | TouchEventHandler<HTMLLabelElement> | undefined | — | — |
onTouchStart | TouchEventHandler<HTMLLabelElement> | undefined | — | — |
onTouchStartCapture | TouchEventHandler<HTMLLabelElement> | undefined | — | — |
onTransitionCancel | TransitionEventHandler<HTMLLabelElement> | undefined | — | — |
onTransitionCancelCapture | TransitionEventHandler<HTMLLabelElement> | undefined | — | — |
onTransitionEnd | TransitionEventHandler<HTMLLabelElement> | undefined | — | — |
onTransitionEndCapture | TransitionEventHandler<HTMLLabelElement> | undefined | — | — |
onTransitionRun | TransitionEventHandler<HTMLLabelElement> | undefined | — | — |
onTransitionRunCapture | TransitionEventHandler<HTMLLabelElement> | undefined | — | — |
onTransitionStart | TransitionEventHandler<HTMLLabelElement> | undefined | — | — |
onTransitionStartCapture | TransitionEventHandler<HTMLLabelElement> | undefined | — | — |
onWheel | WheelEventHandler<HTMLLabelElement> | undefined | — | — |
onWheelCapture | WheelEventHandler<HTMLLabelElement> | undefined | — | — |
render | DOMRenderFunction<"label", CheckboxRenderProps> | undefined | — | Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements: - You must render the expected element type (e.g. if `<button>` is expected, you cannot render an `<a>`). - Only a single root DOM element can be rendered (no fragments). - You must pass through props and ref to the underlying DOM element, merging with your own prop as appropriate. |
slot | string | null | undefined | — | A slot name for the component. Slots allow the component to receive props from a parent component. An explicit `null` value indicates that the local props completely override all props received from a parent. |
style | StyleOrFunction<CheckboxRenderProps> | undefined | — | The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the element. A function may be provided to compute the style based on component state. |
translate | "yes" | "no" | undefined | — | — |
validate | ((value: boolean) => true | ValidationError | null | undefined) | undefined | — | A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if `validationBehavior="native"`. For realtime validation, use the `isInvalid` prop instead. |
validationBehavior | "native" | "aria" | undefined | 'native' | Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA. |
| Prop | Type | Default | Description |
|---|---|---|---|
defaultSelected | boolean | undefined | — | Whether the element should be selected (uncontrolled). |
isSelected | boolean | undefined | — | Whether the element should be selected (controlled). |
onChange | ((isSelected: boolean) => void) | undefined | — | Handler that is called when the element's selection state changes. |
value | string | undefined | — | The value of the input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefvalue). |
Theme this component via createDesignTheme({ components: { checkbox: … } }).
See Customize for the full override API.
Public classes and data attributes from @var-ui/core checkbox().
| Name | Example | Description |
|---|---|---|
class | var-ui-checkbox | Root / part class name |
| Name | Example | Description |
|---|---|---|
class | var-ui-checkbox__box | Root / part class name |
| Name | Example | Description |
|---|---|---|
class | var-ui-checkbox__label | Root / part class name |
| Name | Example | Description |
|---|---|---|
class | var-ui-checkbox__group | Root / part class name |
| Name | Example | Description |
|---|---|---|
class | var-ui-checkbox__groupLabel | Root / part class name |
Apply via `recipeProps(recipe(…))` or copy the class / data attributes onto your markup.