Bedform UIControls

Checkbox

Tick an option.

Checkbox

*
*
boolean
*
boolean
*
string
*
boolean

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.

PropTypeDefault
childrenReactNode—
color"primary" | "secondary" | "destructive" | "dungeons" | "legends" | "realms" | "gold""primary"
classNamestring—
labelClassNamestring—

className applies to the input and labelClassName to the surrounding label.

CSS variables

VariablePurpose
--ore-checkbox-unitBase size unit
--ore-checkbox-backgroundUnchecked background
--ore-checkbox-highlightUnchecked highlight
--ore-checkbox-borderBorder color
--ore-checkbox-indicatorCheckmark color
--ore-checkbox-active-backgroundChecked background
--ore-checkbox-active-background-hoverChecked hover background
--ore-checkbox-active-background-pressedChecked pressed background
--ore-checkbox-active-highlightChecked highlight
--ore-checkbox-active-highlight-hoverChecked hover highlight
--ore-checkbox-active-highlight-pressedChecked pressed highlight

Accessibility

The native input provides checkbox semantics, label activation, Space key behavior, form participation, validation, and reset behavior without JavaScript.

On this page