Skip to main content

Common Examples

import { Checkbox } from "@servicetitan/anvil2";

function ExampleComponent() {
  return (
    <Checkbox.Group
      direction="column"
      legend="Preferred methods of communication"
    >
      <Checkbox label="Email" defaultChecked />
      <Checkbox label="Phone" />
      <Checkbox label="Text" />
    </Checkbox.Group>
  );
}

Basic checkbox inputs

The Checkbox component accepts many of the same props as an HTML input with type="checkbox", such as name, value, checked, and defaultChecked.

Controlling checkbox state

Use the checked and onClick props to manually control the state of a checkbox.

Indeterminate checkboxes

The indeterminate prop should be used to represent a checkbox that has checkbox children which some, but not all are checked.

React Accessibility

  • The Checkbox component’s label prop allows for any ReactElement to be passed in, but the label should always be populated with some text content that is screen-reader accessible.
For more guidance on form field labels and context, see input field context association best practices.

Markdown in legends

The Checkbox.Group legend prop supports inline markdown: bold (**text**), italic (*text*), bold and italic (***text***), highlight (==text==), and code (`text`).

Hide the legend

Use hideLabel on Checkbox.Group to visually hide the legend. The legend string is kept as a screen-reader-only <legend> element so the group remains accessible — any inline markdown is stripped to plain text.
Last modified on April 14, 2026