Checkbox
Tick an option.
Checkbox
Usage
import { Checkbox } from "@bedform/ui/checkbox";
import { useState } from "react";
export function UpdatesCheckbox() {
const [checked, setChecked] = useState(false);
return (
<Checkbox
checked={checked}
name="updates"
value="yes"
onChange={(event) => {
setChecked(event.currentTarget.checked);
}}
>
Receive updates
</Checkbox>
);
}Checkbox renders a native checkbox inside a label, and its children become the label text.
Colors
<Checkbox color="primary" defaultChecked>Primary</Checkbox>
<Checkbox color="secondary" defaultChecked>Secondary</Checkbox>
<Checkbox color="destructive" defaultChecked>Destructive</Checkbox>
<Checkbox color="dungeons" defaultChecked>Dungeons</Checkbox>
<Checkbox color="legends" defaultChecked>Legends</Checkbox>
<Checkbox color="realms" defaultChecked>Realms</Checkbox>
<Checkbox color="gold" defaultChecked>Gold</Checkbox>States
<Checkbox defaultChecked>Enabled</Checkbox>
<Checkbox disabled>Unavailable</Checkbox>
<Checkbox required>Required agreement</Checkbox>Forms
Checked values are included in FormData. Reset restores the initial defaultChecked state.
<form>
<Checkbox name="terms" value="accepted" required>
Accept the terms
</Checkbox>
<Button type="submit">Continue</Button>
<Button type="reset" color="secondary">
Reset
</Button>
</form>Events
The native checkbox dispatches input and change events when its value changes, so onChange and onInput work as they do on any input.
API
Checkbox accepts every attribute of a native checkbox input, such as checked, defaultChecked, disabled, name, required and value. Its ref points to the input, so native methods such as checkValidity() and reportValidity() remain available.
| Prop | Type | Default |
|---|---|---|
children | ReactNode | — |
color | "primary" | "secondary" | "destructive" | "dungeons" | "legends" | "realms" | "gold" | "primary" |
className | string | — |
labelClassName | string | — |
className applies to the input and labelClassName to the surrounding label.
CSS variables
| Variable | Purpose |
|---|---|
--ore-checkbox-unit | Base size unit |
--ore-checkbox-background | Unchecked background |
--ore-checkbox-highlight | Unchecked highlight |
--ore-checkbox-border | Border color |
--ore-checkbox-indicator | Checkmark color |
--ore-checkbox-active-background | Checked background |
--ore-checkbox-active-background-hover | Checked hover background |
--ore-checkbox-active-background-pressed | Checked pressed background |
--ore-checkbox-active-highlight | Checked highlight |
--ore-checkbox-active-highlight-hover | Checked hover highlight |
--ore-checkbox-active-highlight-pressed | Checked pressed highlight |
Accessibility
The native input provides checkbox semantics, label activation, Space key behavior, form participation, validation, and reset behavior without JavaScript.