ClayAutocomplete component

Usage no npm install needed!

<script type="module">
  import clayuiAutocomplete from 'https://cdn.skypack.dev/@clayui/autocomplete';


title: 'Autocomplete' description: 'An autocomplete text field is an input that offers the user text suggestions while they type.' lexiconDefinition: 'https://liferay.design/lexicon/core-components/forms/text-input-variations/' packageNpm: '@clayui/autocomplete'

import { AutocompleteWithLoadingState, AutocompleteWithDataProvider, } from '$packages/clay-autocomplete/docs/index';


Autocomplete provides the necessary components for you to compose with the other components, by itself it does not do much, you need to use the <ClayDropDown /> along with <Autocomplete.DropDown /> and <Autocomplete.Item /> to create the suggestions.

        <ClayAutocomplete.Item match="cl" value="clay" />

If you already have the raw data, it is becomes simpler to create an autocomplete but it is important that you create a filter for your data according to the value entered in the input element.

        onChange={(event) => setValue(event.target.value)}
    <ClayAutocomplete.DropDown active={showDropDown}>
            {resourceFiltered.map((item) => (
                <ClayAutocomplete.Item key={item} match={value} value={item} />

Loading state

<ClayAutocomplete.LoadingIndicator /> is used for providing feedback that data is loading in the suggestion box, it communicates with <ClayAutocomplete.Input /> so that the markup can adjust.

Warning Add this when your suggestion data is coming from a data provider.

Data from outside

For cases where you do not have all the data in the client and need to pass the value for the filter to the backend, use the <ClayDataProvider /> component or useResource hook for this.