Skip to main content

AutoComplete: React

AutoCompletes are input fields where a user is suggested several options, based on the input they provide.

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

export default function Example() {
return <AutoComplete suggestions={['One', 'Two', 'Three']} />;
}

Properties

PropertyTypeDefaultRequiredDescription
accessibilityLabelClearButtonString'clear selection'NoIs used to set an accessibility friendly label for the clear button, allowing screen readers to read it aloud. This label will not be visually shown.
actionReactNode-NoThe contents displayed within the ActionLabel.
autoCompleteString'off'NoModifies the HTML `autocomplete` attribute.
classNameString-NoExtend the CSS class names of the component.
disabledBoolean-NoIndicates whether the input is disabled or not.
errorBoolean-NoDetermines whether the component should be visually displayed with an error state. When set to `true`, the necessary accessibility tags and styles for error state will be added.
forceSelectionBoolean-NoForces the user to make a selection.
iconLeftSVGType-NoThe left icon of the input.
idString-YesThe ID of the input for accessibility purposes. Additionally, an ID will be added to the wrapper element with the prefix 'autocomplete-'.
labelString-YesThe label used in the input.
labelHiddenBoolean-NoDetermines whether the label should be visually hidden, while still being required for accessibility purposes.
loadingBoolean-NoThe loading state of the AutoComplete component. It is typically used in combination with async data fetching.
markMatchesBooleantrueNoMarks the matched query in suggestions
messageString-NoThe message used beneath the input.
nameString-NoThe name of the input.
onBlurFocusEventHandler-NoThis event is triggered when the input loses focus, such as when the user presses the Tab key.
onChangeFunction-YesEvent is triggered when the value of the input changes.
onFocusFocusEventHandler-NoThis event is triggered when the input receives focus.
onInputChangeFunction-NoThis event is triggered by the AutoComplete component every time suggestions need to be updated. It can be used for async operations.
onSelectFunction-NoThis event is triggered when the user selects an item, regardless of the previously selected item. It is called with the selected item and the new state of downshift.
optionalLabelString-NoThe contents displayed within the OptionalLabel.
placeholderString-NoThe placeholder text used in the input.
placement'bottom' | 'top''bottom'NoDetermines the position of the suggestions relative to the input element.
readOnlyBoolean-NoIndicates whether the input is in a read-only state.
successBoolean-NoIndicates whether the AutoComplete has been successfully filled in.
suggestionsUnknown-YesAn array of suggestions for the AutoComplete component.
typeString'text'NoThe type of the input.
valueString-NoThe current value of the native input element.
defaultValueString-NoThe current value of the native input element.

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.