Skip Navigation
Magma

Indeterminate Checkbox

The IndeterminateCheckbox component is similar to the Checkbox component, except that instead of accepting a boolean checked value, it takes the status prop, with three possible statuses: indeterminate, checked and unchecked. The default status is unchecked.

Basic Usage

The status is used to represent the state of a group of checkboxes that goes underneath it.

  • checked means all of the checkboxes in the group are checked.
  • indeterminate means that some, but not all, checkboxes in the group are checked.
  • unchecked means that none of the checkboxes in the group are checked.

The indeterminate status cannot be changed by direct user action, it can only be changed by updating the prop.

import React from 'react';
import {
Checkbox,
FormGroup,
IndeterminateCheckbox,
IndeterminateCheckboxStatus,
magma,
} from 'react-magma-dom';
export function Example() {
const [checkedItems, setCheckedItems] = React.useState<Array<boolean>>([
true,
false,
]);
const status: IndeterminateCheckboxStatus = checkedItems.every(Boolean)
? IndeterminateCheckboxStatus.checked
: checkedItems.some(Boolean)
? IndeterminateCheckboxStatus.indeterminate
: IndeterminateCheckboxStatus.unchecked;
function handleUpdateIndeterminateChecked(
event: React.ChangeEvent<HTMLInputElement>
) {
setCheckedItems([event.target.checked, event.target.checked]);
}
function handleUpdateRedChecked(event: React.ChangeEvent<HTMLInputElement>) {
setCheckedItems([event.target.checked, checkedItems[1]]);
}
function handleUpdateBlueChecked(event: React.ChangeEvent<HTMLInputElement>) {
setCheckedItems([checkedItems[0], event.target.checked]);
}
return (
<FormGroup labelText="Categories">
<IndeterminateCheckbox
onChange={handleUpdateIndeterminateChecked}
status={status}
labelText="Colors"
/>
<div style={{ marginLeft: magma.spaceScale.spacing08 }}>
<Checkbox
checked={checkedItems[0]}
onChange={handleUpdateRedChecked}
labelText="Red"
/>
<Checkbox
checked={checkedItems[1]}
onChange={handleUpdateBlueChecked}
labelText="Blue"
/>
</div>
</FormGroup>
);
}

Inverse

import React from 'react';
import {
IndeterminateCheckbox,
IndeterminateCheckboxStatus,
Card,
CardBody,
magma,
} from 'react-magma-dom';
export function Example() {
return (
<Card background={magma.colors.neutral1100} isInverse>
<CardBody>
<IndeterminateCheckbox
status={IndeterminateCheckboxStatus.indeterminate}
labelText="Colors"
isInverse
/>
</CardBody>
</Card>
);
}

Indeterminate Checkbox Props

Any other props supplied will be provided to the Checkbox Component, except for the checked prop.

ariaLabel

Description

Text for aria-label attribute for the checkbox.

Type

string

Default

-


color

Description

Hex code for the background color

Type

string

Default

#007085 (theme.colors.cyan700)


containerStyle

Description

Style properties for the component container element

Type

CSSProperties

Default

-


defaultChecked

Description

If true, checkbox is checked on first render

Type

boolean

Default

-


disabled

Description

If true, element is disabled

Type

boolean

Default

false


errorMessage

Description

Content of the error message for an individual checkbox. If a value is provided, the input will be styled as an error state and the error message will display.

Type

ReactNode

Default

-


hasError

Type

boolean

Default

-


inputStyle

Description

Style properties for the checkbox element

Type

CSSProperties

Default

-


isInverse

Description

If true, the component will have inverse styling to better appear on a dark background

Type

boolean

Default

false


isTextVisuallyHidden

Description

If true, label text will be hidden visually, but will still be read by assistive technology

Type

boolean

Default

false


labelStyle

Description

Style properties for the label element

Type

CSSProperties

Default

-


labelText

Required

Description

Content of label; can be node or string

Type

ReactNode

Default

-


onChange

Description

Action that fires when selected value of the checkbox changes

Type

function

Default

-


status

Required

Description

Status of the indeterminate, three-state checkbox, which includes an indeterminate (e.g. mixed) option.

Type

enum, one of:
IndeterminateCheckboxStatus.checked
IndeterminateCheckboxStatus.indeterminate
IndeterminateCheckboxStatus.unchecked

Default

IndeterminateCheckboxStatus.unchecked


textPosition

Description

Whether the label appears to the left or the right of the checkbox

Type

enum, one of:
CheckboxTextPosition.left
CheckboxTextPosition.right

Default

CheckboxTextPosition.right


On this page

Deploys by Netlify