Skip to main content

Autocomplete

Autocomplete combines a text input with a dropdown suggestions panel. As the user types, the list of suggestions is filtered and displayed below the input.

Import

import { Autocomplete, AutocompleteItem } from '@ui-kitten/components';

Basic Usage

import React, { useState } from 'react';
import { Layout, Autocomplete, AutocompleteItem } from '@ui-kitten/components';

const allOptions = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry'];

const AutocompleteExample = () => {
const [value, setValue] = useState('');

const filteredOptions = allOptions.filter(
(item) => item.toLowerCase().includes(value.toLowerCase()),
);

const onSelect = (index) => {
setValue(filteredOptions[index]);
};

return (
<Layout style={{ flex: 1, padding: 16 }}>
<Autocomplete
placeholder="Search fruits"
value={value}
onChangeText={setValue}
onSelect={onSelect}
>
{filteredOptions.map((title, index) => (
<AutocompleteItem key={index} title={title} />
))}
</Autocomplete>
</Layout>
);
};

Props

Autocomplete

PropertyTypeDefaultDescription
valuestringundefinedCurrent text value of the input.
onChangeText(text: string) => void-Called when the input text changes.
onSelect(index: number) => void-Called when a suggestion item is selected.
placeholderstringundefinedPlaceholder text displayed when the input is empty.
labelReactText | (props) => ReactElementundefinedLabel displayed above the input.
captionReactText | (props) => ReactElementundefinedCaption displayed below the input.
childrenAutocompleteItem[]-Suggestion items.

AutocompleteItem

PropertyTypeDefaultDescription
titleReactText | (props) => ReactElement-Item title text or render function.
accessoryLeft(props) => ReactElementundefinedRender function for the left accessory.
accessoryRight(props) => ReactElementundefinedRender function for the right accessory.

Autocomplete also accepts all standard Input props.

Storybook

Live examples coming soon via Storybook.