• /
  • Log in
  • Free account

Checkbox

When a user chooses one or more options provided

The checkbox state can be controlled through the checked and indeterminate property. If neither of those is provided the checkbox will manage its own state.

You can listen to the checkbox state changes through the onChange prop.

Usage

import { Checkbox } from 'nr1'

Examples

Basic

ReferenceError: Checkbox is not defined

Controlled component

Props

checkedboolean

If true, the checkbox is checked.

If defined, it turns the component into a controlled component.

classNamestring

Appends class names to the component.

Should be used only for positioning and spacing purposes.

defaultCheckedboolean

If true, the initial state of the checkbox is checked.

Useful when you don't want to use a controlled component.

disabledboolean

If true, the checkbox is not available for interaction.

indeterminateboolean

If true, the checkbox is in an indeterminate state.

If both the checked and indeterminate prop are provided then the indeterminate prop will prevail.

infostring

Additional information can be displayed in an info tooltip next to the Label.

labelstring

Text to display as label.

onChangefunction

Callback fired any time the selected state of the checkbox changes.

function (
event: MouseEvent //

The event source of the callback. You can access the new value with event.target.checked.

) => undefined
spacingTypeenum[]

Spacing property. Spacing is defined as a tuple of zero to four values, which follow the same conventions as CSS properties like margin or padding. To omit a value, use SPACING_TYPE.OMIT.

<Array of
<One of
Checkbox.SPACING_TYPE.EXTRA_LARGE,
Checkbox.SPACING_TYPE.LARGE,
Checkbox.SPACING_TYPE.MEDIUM,
Checkbox.SPACING_TYPE.NONE,
Checkbox.SPACING_TYPE.OMIT,
Checkbox.SPACING_TYPE.SMALL,
>
>
styleobject

Inline style for custom styling.

Should be used only for positioning and spacing purposes.

testIdstring

Adds a data-test-id.

Used to target the component in unit and e2e testing.

Methods

Checkbox.render

function () => undefined
Create issueEdit page
Copyright © 2021 New Relic Inc.