Components

Checkbox(React)

Boxes for checking and unchecking multiple values in forms.

Version:9.3.0 View sourceChangelogReport issue
Install:yarn add @thumbtack/thumbprint-react
Import:import { Checkbox } from '@thumbtack/thumbprint-react';

Basic checkbox

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

The isChecked prop determines if a checkbox is checked.

Multiple checkboxes

This an example of how to use many Checkbox components at once.

Indeterminate checkboxes

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

Disabled checkboxes

The isDisabled prop visually and functionally disabled the radio button. It also visually disables the related label.

Checkbox with an error

The hasError prop can be used to visually represent an error.

This prop only changes the checkbox’s color. It should be used alongside an error message that helps users advance through the form.

Multi-column content

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

This example puts the label content within children. It’s also possible to not provide children as undefined and use a custom label instead. In that case, you must use Checkbox’s id prop.

Checkbox input by default is vertically center-aligned with children. If children prop spans over multiple lines and you want it to align at the top, it is possible to provide checkboxVerticalAlign prop as top.

Using classes

These example use React Hooks, but if you want to use the old class-based components, you can do that.

Props

Checkbox

  • isDisabled

    Disables the input and the label.

    Type
    bool
    Default
    false
  • isChecked

    Determines if the checkbox is checked.

    Type
    bool
    Default
    false
  • hasError

    Makes the radio and text color red.

    Type
    bool
    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
    node
    Default
    null
  • id

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

    Type
    string
    Default
    null
  • 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
    Default
    null
  • 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'
  • onChange
    required

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

    Type
    func
  • isIndeterminate

    Shows a horizontal line to represent an indeterminate input.

    Type
    bool
    Default
    false
  • dataTest

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

    Type
    string
    Default
    undefined
  • checkboxVerticalAlign

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

    Type
    oneOf([
      'top',
      'center',
    ])
    Default
    'center'