Skip to main content

Checkbox: React

A Checkbox is an input control for making selections.

Installation

Before you can start using the @mediahuis/chameleon-react component, you’ll need to install it, for more information check: Getting started for developers.

With that done, you’re now ready to implement the component in your application.

import { Checkbox } from '@mediahuis/chameleon-react';

export default function Example() {
return <Checkbox label="Example" id="example" />;
}

Properties

PropertyTypeDefaultRequiredDescription
actionReactNode-NoThe contents displayed within the ActionLabel.
checkedBoolean-NoSets the native checkbox checked state.
classNameString-NoAllows extending the class names of the Checkbox component.
disabledBoolean-NoSets the native HTML disabled attribute.
errorBoolean-NoVisually displays the Checkbox with an error state. It also adds the necessary accessibility tags.
idString-YesSets the native HTML id attribute. It will also affect the label-id and the message-id for accessibility reasons.
labelReactNode-NoThe contents displayed within the PrimaryLabel.
labelHiddenBoolean-NoVisually hides the label. Note that the label is still required for accessibility.
labelPlacement'left' | 'right'-NoSets the placement of the label.
labelPropsGenericComponentPropsWithoutAs-NoObject containing additional props passed to the label component.
labelIdString`${id}-label`NoThe unique HTML id attribute. It is used for associating the label and the radio components for accessibility.
messageReactNode-NoThe contents displayed beneath the label.
onChangeFunction-NoThe native change event. It validates on `event.target.checked`.
optionalLabelString-NoThe contents displayed within the OptionalLabel.
requiredBoolean-NoSets the native input required attribute.
valueString-NoThe native input value.
inputPropsGenericComponentPropsWithoutAs-NoObject containing additional props passed to the input component.

required

Chameleon form inputs are required by default, with the required attribute automatically set. To mark a field as optional, pass the optionalLabel prop to remove the required attribute.