Skip to main content

Choice: React

A visual alternative to radio buttons and checkboxes. They allow a selection of single or multiple options from a set of predefined options.

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 { Choice } from '@mediahuis/chameleon-react';

export default function Example() {
return (
<Choice
value="1"
name="choice"
title="Choose 1"
onChange={e => {
console.log(e.target.value);
}}
/>
);
}

Properties

PropertyTypeDefaultRequiredDescription
checkedBoolean-NoDetermines whether the choice is checked or not.
childrenReactNode-NoThe contents displayed within the choice when it's selected.
classNameString-NoAllows extending the class names of the Choice component.
disabledBoolean-NoVisually and functionally disables the choice.
errorBoolean-NoVisually displays the choice with an error state.
idString-YesSets the ID given to the input and adds the `htmlFor` attribute to the label.
imageAltString-NoThe alt text of the image.
imageSrcString-NoThe source of the image.
infoReactNode-NoThe informational text.
labelPropsGenericComponentPropsWithoutAs-NoIs an object containing additional props passed to the label component.
messageReactNode-NoThe message text.
nameString-YesThe native input name.
onChangeChangeEventHandler-NoThe event handler function triggered when the value of the choice changes. It returns the native `onChange` event.
titleString-YesThe title text.
type'radio' | 'checkbox' | 'switch''radio'NoThe native input type.
valueString-YesThe native input value.