Thumbprint logo

Components

Checkbox

Boxes for checking and unchecking multiple values in forms

Migrating from v1

CheckboxV2 is built on React Aria and styled with Thumbprint v2 semantic tokens. It keeps the v1 Checkbox prop names (isChecked, hasError, onChange, accessibilityLabel, checkboxVerticalAlign, labelPadding) so most call sites can migrate by swapping the import. The only removed prop is the deprecated dataTest (use dataTestId).

Basic checkbox

Checkboxes can be checked, unchecked, or in an indeterminate state.

The isChecked prop determines if a checkbox is checked.

function CheckboxExample() {
    const [isChecked, setIsChecked] = React.useState(undefined);
    return (
        <CheckboxV2 isChecked={isChecked} onChange={setIsChecked}>
            Send me promotional emails
        </CheckboxV2>
    );
}

Multiple checkboxes

Checkboxes are block-level and include built-in vertical spacing, so consecutive checkboxes stack with the Figma “Checkbox / List” 8px rhythm without any extra wrapper.

function CheckboxExample() {
    const [isMorningChecked, setIsMorningChecked] = React.useState(true);
    const [isAfternoonChecked, setIsAfternoonChecked] = React.useState(true);
    const [isEveningChecked, setIsEveningChecked] = React.useState(true);

    return (
        <div>
            <CheckboxV2
                id="morning"
                isChecked={isMorningChecked}
                name="example-full"
                onChange={setIsMorningChecked}
            >
                Morning
            </CheckboxV2>
            <CheckboxV2
                id="afternoon"
                isChecked={isAfternoonChecked}
                name="example-full"
                onChange={setIsAfternoonChecked}
            >
                Afternoon
            </CheckboxV2>
            <CheckboxV2
                id="evening"
                isChecked={isEveningChecked}
                name="example-full"
                onChange={setIsEveningChecked}
            >
                Evening
            </CheckboxV2>
        </div>
    );
}

Indeterminate checkboxes

Indeterminate checkboxes are used when not all items in a field are selected.

function CheckboxExample() {
    const [isChecked, setIsChecked] = React.useState(undefined);
    return (
        <CheckboxV2
            isIndeterminate={isChecked === undefined}
            isChecked={isChecked}
            onChange={setIsChecked}
        >
            Select all cities
        </CheckboxV2>
    );
}

Disabled checkboxes

The isDisabled prop visually and functionally disables the checkbox. It also visually disables the related label.

<React.Fragment>
    <CheckboxV2 isDisabled isChecked onChange={() => {}}>
        Morning
    </CheckboxV2>
    <CheckboxV2 isDisabled isChecked onChange={() => {}}>
        Afternoon
    </CheckboxV2>
    <CheckboxV2 isDisabled onChange={() => {}}>
        Evening
    </CheckboxV2>
</React.Fragment>

Checkbox with an error

The hasError prop can be used to visually represent an error. It should be used alongside an error message that helps users advance through the form.

function CheckboxExample() {
    const [isChecked, setIsChecked] = React.useState(undefined);
    return (
        <CheckboxV2 isChecked={isChecked} hasError onChange={setIsChecked}>
            I accept the Terms of Service
        </CheckboxV2>
    );
}

Display type

standard (the default) renders the inline, borderless layout that covers existing v1 use cases. control wraps the checkbox and label in a padded, bordered card; its border becomes brand-colored when the checkbox is selected or indeterminate.

function CheckboxExample() {
    const [isChecked, setIsChecked] = React.useState(undefined);
    return (
        <CheckboxV2 type="control" isChecked={isChecked} onChange={setIsChecked}>
            Send me promotional emails
        </CheckboxV2>
    );
}

Custom label padding

The labelPadding prop expands the click/touch target by applying a CSS padding string to the label, mirroring the v1 prop. It is most useful with the control type, since it overrides the bordered card’s padding.

function CheckboxExample() {
    const [isChecked, setIsChecked] = React.useState(undefined);
    return (
        <CheckboxV2 labelPadding="16px 8px" isChecked={isChecked} onChange={setIsChecked}>
            Send me promotional emails
        </CheckboxV2>
    );
}

Checkbox with a description

The description prop renders secondary text beneath the label, and the label is emphasized. The checkbox still follows checkboxVerticalAlign (use checkboxVerticalAlign="top" to align it with the first line).

function CheckboxExample() {
    const [isChecked, setIsChecked] = React.useState(undefined);
    return (
        <CheckboxV2
            isChecked={isChecked}
            onChange={setIsChecked}
            description="We send at most one email per week."
        >
            Send me promotional emails
        </CheckboxV2>
    );
}

Multi-column content

It’s possible to provide complex UIs to the children prop. Clicking on the content will select the related checkbox.

function CheckboxExample() {
    const [isChecked, setIsChecked] = React.useState(undefined);
    return (
        <CheckboxV2 isChecked={isChecked} onChange={setIsChecked} checkboxVerticalAlign="top">
            <div className="flex">
                <div className="flex-none">
                    <UserAvatar imageUrl="https://randomuser.me/api/portraits/women/63.jpg" />
                </div>
                <div className="pl4 flex items-center" style={{ flex: '1 0 0%' }}>
                    <div>
                        <span className="b">Austin Entertainment LLC.</span>
                        <p>DJs, photo booths, and photography for all of your event needs.</p>
                    </div>
                    <div className="b ml-auto">$120/hr</div>
                </div>
            </div>
        </CheckboxV2>
    );
}

Props

Checkbox

  • onChange
    required

    Function that runs when a checkbox value changes. It receives the new boolean value, the provided id, and the underlying event as such: props.onChange(event.target.checked, props.id, event).

    Type
    ( value: boolean, id: string | undefined, event: React.ChangeEvent<HTMLInputElement>, ) => void
  • isDisabled

    Disables the input and the label.

    Type
    boolean
    Default
    false
  • isChecked

    Determines if the checkbox is checked.

    Type
    boolean
    Default
    false
  • hasError

    Makes the radio and text color red.

    Type
    boolean
    Default
    false
  • children

    Text or elements that appear within the label. If children is not provided, the developer must use the Radio's id prop to associate it with a custom <label> element.

    Type
    React.ReactNode
  • id

    The id is added to the checkbox as an HTML attribute and passed to the onChange function.

    Type
    string
  • isRequired

    Adds the required HTML attribute.

    Type
    boolean
    Default
    false
  • name

    Checkboxes on a page with the same name will be grouped together when sent to the server. The browser will only send the value of checkboxes that are checked.

    Type
    string
  • labelPadding

    Determine that padding that gets applied to the label. This can be used to increase the label's click target. The value supplied should be a string with a unit such as 8px or 8px 16px.

    Type
    string
    Default
    '14px 0'
  • onKeyDown

    Function that is called when the user presses a key while focused on the Checkbox.

    Type
    (event: React.KeyboardEvent<HTMLInputElement>) => void
    Default
    (): void => {}
  • isIndeterminate

    Shows a horizontal line to represent an indeterminate input.

    Type
    boolean
    Default
    false
  • dataTestId

    A selector hook into the React component for use in automated testing environments. It is applied internally to the <input /> element.

    Type
    string
  • dataTest
    deprecated

    A selector hook into the React component for use in automated testing environments. It is applied internally to the <input /> element.

    Note:

    Deprecated in favor of the dataTestId prop

    Type
    string
  • checkboxVerticalAlign

    Determines how the checkbox input will be vertically aligned relative to props.children.

    Type
    'top' | 'center'
    Default
    'center'
  • value

    Determines the value that will be submitted if the checkbox is checked. The default value is 'on'.

    Type
    string | string[] | number
  • accessibilityLabel

    Accessible label for the checkbox input. Only needed if non-textual children are provided (e.g., images, emojis). Not necessary if textual children are provided.

    Type
    string