Autocomplete

An Autocomplete component is a UI element that combines a text input with a dropdown list of suggestions, allowing users to quickly find and select from a set of options. It provides real-time filtering as users type, enhancing the search and selection experience.

Demo

Select a framework...

Selected: None

Usage

import { useState } from 'react';
import { NAutocomplete } from '@nayan-ui/react';
const items = [
{ id: 'react', label: 'React' },
{ id: 'vue', label: 'Vue' },
{ id: 'angular', label: 'Angular' },
{ id: 'svelte', label: 'Svelte' }
];
const Autocomplete = () => {
const [selected, setSelected] = useState(null);
return (
<NAutocomplete
items={items}
placeholder="Select a framework..."
selectedKey={selected}
onSelectionChange={setSelected}
/>
);
};
export default Autocomplete;

Attributes

NameTypeDefaultDetails
itemsNAutocompleteItem[]RequiredList of items with id and label.
placeholderstring'Search...'Placeholder text.
selectedKeystringOptionalCurrently selected item key.
onSelectionChange(key: string | null) => voidOptionalCallback when selection changes.
onClear() => voidOptionalCallback when input is cleared.
variant'primary' | 'secondary''primary'Visual variant.
isDisabledbooleanfalseDisables the autocomplete.
isInvalidbooleanfalseMarks as invalid.
fullWidthbooleanfalseFull width mode.
classNamestring' 'Additional CSS classes.