Skip to main content

Select: React

Select gives users the ability to select a single item from a list of 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 { Select } from '@mediahuis/chameleon-react';

export default function Example() {
return (
<Select>
<option value="1">Example 1</option>
<option value="2">Example 2</option>
</Select>
);
}

Properties

PropertyTypeDefaultRequiredDescription
actionReactNode-NoContents displayed within the ActionLabel.
childrenReactNode-NoThe content displayed within the Select component.
classNameString-NoAllows extending the class names of the component.
disabledBoolean-NoSpecifies whether the component is disabled or not, same as the HTML attribute.
errorBoolean-NoDetermines whether the select is visually displayed with an error state. This adds necessary accessibility tags.
iconLeftSVGType-NoThe icon displayed on the left side of the select.
idString-YesThe unique HTML id attribute that also affects the associated label and message ids for accessibility reasons.
labelReactNode-YesContents displayed within the PrimaryLabel.
labelHiddenBoolean-NoDetermines whether the label is visually hidden (while still required for accessibility).
messageString-NoContents displayed beneath the label.
nameString-NoName attribute of the HTML element.
onBlurFocusEventHandler-NoFunction fired when the Select loses focus.
onChangeChangeEventHandler-NoNative change event, triggered when the Select value changes. Validation can be done using `event.target.value`.
onClickMouseEventHandler-NoThe event handler that is triggered when the Select is clicked.
onFocusFocusEventHandler-NoThe event handler that is triggered when the Select receives focus.
optionalLabelString-NoContents displayed within the OptionalLabel.
placeholderString-NoThe placeholder text displayed as the first option, which is disabled.
requiredBoolean-NoSpecifies whether the Select is required (sets the native select required attribute).
successBoolean-NoDetermines whether the Select displays a success state.
valueString-NoThe current value of the Select.

iconLeft

The iconLeft property lets you choose an icon from the icon package to be displayed on the left. The complete list of possible icons can be found in the Icons documentation.

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.