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.
Last modified on January 23, 2026