Components
Boxes for checking and unchecking multiple values in forms.
| Version: | 14.18.2 •View source•Changelog•Report issue | |
|---|---|---|
| Install: | yarn add @thumbtack/thumbprint-react | |
| Import: | import { Checkbox } from '@thumbtack/thumbprint-react'; | |
Checkboxes can be checked, unchecked, or in an indeterminate state.
The isChecked prop determines if a checkbox is checked.
This an example of how to use many Checkbox components at once.
Indeterminate checkboxes are used when not all items in a field are selected.
The isDisabled prop visually and functionally disabled the radio button. It also visually disables the related label.
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.
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.
These example use React Hooks, but if you want to use the old class-based components, you can do that.
onChangeFunction 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).
(
value: boolean,
id: string | undefined,
event: React.ChangeEvent<HTMLInputElement>,
) => voidisDisabledDisables the input and the label.
booleanfalseisCheckedDetermines if the checkbox is checked.
booleanfalsehasErrorMakes the radio and text color red.
booleanfalsechildrenText 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.
React.ReactNodeidThe id is added to the checkbox as an HTML attribute and passed to the onChange
function.
stringisRequiredAdds the required HTML attribute.
booleanfalsenameCheckboxes 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.
stringlabelPaddingDetermine 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.
string'14px 0'onKeyDownFunction that is called when the user presses a key while focused on the Checkbox.
(event: React.KeyboardEvent<HTMLInputElement>) => void(): void => {}isIndeterminateShows a horizontal line to represent an indeterminate input.
booleanfalsedataTestIdA selector hook into the React component for use in automated testing environments. It is
applied internally to the <input /> element.
stringdataTestA 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
stringcheckboxVerticalAlignDetermines how the checkbox input will be vertically aligned relative to props.children.
This prop can be one of the following 2 types:
'top''center''center'valueDetermines the value that will be submitted if the checkbox is checked. The default value is
'on'.
This prop can be one of the following 3 types:
stringstring[]number