Autocomplete
An input that suggests options as you type.
import { Autocomplete } from 'base-ui-solid/autocomplete';
import styles from './index.module.css';
export default function ExampleAutocomplete() {
return (
<Autocomplete.Root items={tags}>
<label class={styles.Label}>
Search tags
<Autocomplete.Input placeholder="e.g. feature" class={styles.Input} />
</label>
<Autocomplete.Portal>
<Autocomplete.Positioner class={styles.Positioner} sideOffset={4}>
<Autocomplete.Popup class={styles.Popup}>
<Autocomplete.Empty>
<div class={styles.Empty}>No tags found.</div>
</Autocomplete.Empty>
<Autocomplete.List class={styles.List}>
{(tag: Tag) => (
<Autocomplete.Item class={styles.Item} value={tag}>
{tag.value}
</Autocomplete.Item>
)}
</Autocomplete.List>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>
);
}
interface Tag {
id: string;
value: string;
}
const tags: Tag[] = [
{ id: 't1', value: 'feature' },
{ id: 't2', value: 'fix' },
{ id: 't3', value: 'bug' },
{ id: 't4', value: 'docs' },
{ id: 't5', value: 'internal' },
{ id: 't6', value: 'mobile' },
{ id: 'c-accordion', value: 'component: accordion' },
{ id: 'c-alert-dialog', value: 'component: alert dialog' },
{ id: 'c-autocomplete', value: 'component: autocomplete' },
{ id: 'c-avatar', value: 'component: avatar' },
{ id: 'c-checkbox', value: 'component: checkbox' },
{ id: 'c-checkbox-group', value: 'component: checkbox group' },
{ id: 'c-collapsible', value: 'component: collapsible' },
{ id: 'c-combobox', value: 'component: combobox' },
{ id: 'c-context-menu', value: 'component: context menu' },
{ id: 'c-dialog', value: 'component: dialog' },
{ id: 'c-field', value: 'component: field' },
{ id: 'c-fieldset', value: 'component: fieldset' },
{ id: 'c-filterable-menu', value: 'component: filterable menu' },
{ id: 'c-form', value: 'component: form' },
{ id: 'c-input', value: 'component: input' },
{ id: 'c-menu', value: 'component: menu' },
{ id: 'c-menubar', value: 'component: menubar' },
{ id: 'c-meter', value: 'component: meter' },
{ id: 'c-navigation-menu', value: 'component: navigation menu' },
{ id: 'c-number-field', value: 'component: number field' },
{ id: 'c-popover', value: 'component: popover' },
{ id: 'c-preview-card', value: 'component: preview card' },
{ id: 'c-progress', value: 'component: progress' },
{ id: 'c-radio', value: 'component: radio' },
{ id: 'c-scroll-area', value: 'component: scroll area' },
{ id: 'c-select', value: 'component: select' },
{ id: 'c-separator', value: 'component: separator' },
{ id: 'c-slider', value: 'component: slider' },
{ id: 'c-switch', value: 'component: switch' },
{ id: 'c-tabs', value: 'component: tabs' },
{ id: 'c-toast', value: 'component: toast' },
{ id: 'c-toggle', value: 'component: toggle' },
{ id: 'c-toggle-group', value: 'component: toggle group' },
{ id: 'c-toolbar', value: 'component: toolbar' },
{ id: 'c-tooltip', value: 'component: tooltip' },
];
Usage guidelines
- Avoid when selection state is needed: Use Combobox instead of Autocomplete if the selection should be remembered and the input value cannot be custom. Unlike Combobox, Autocomplete’s input can contain free-form text, as its suggestions only optionally autocomplete the text.
- Can be used for filterable command pickers: The input can be used as a filter for command items that perform an action when clicked when rendered inside the popup.
- Form controls must have an accessible name: It can be created using a
<label>element or theFieldcomponent. See the forms guide. - Closing animations: The popup stays rendered until its closing animation finishes. See JavaScript animations for animating it with Motion and for manual control.
Anatomy
Import the components and place them together:
import { Autocomplete } from 'base-ui-solid/autocomplete';
<Autocomplete.Root>
<Autocomplete.InputGroup>
<Autocomplete.Input />
<Autocomplete.Trigger />
<Autocomplete.Icon />
<Autocomplete.Clear />
<Autocomplete.Value />
</Autocomplete.InputGroup>
<Autocomplete.Portal>
<Autocomplete.Backdrop />
<Autocomplete.Positioner>
<Autocomplete.Popup>
<Autocomplete.Arrow />
<Autocomplete.Status />
<Autocomplete.Empty />
<Autocomplete.List>
<Autocomplete.Row>
<Autocomplete.Item />
</Autocomplete.Row>
<Autocomplete.Separator />
<Autocomplete.Group>
<Autocomplete.GroupLabel />
</Autocomplete.Group>
<Autocomplete.Collection />
</Autocomplete.List>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>;
Item values
Each <Autocomplete.Item> takes a value prop identifying it. Pass the item being rendered, so that props like itemToStringValue receive it.
Examples
Async search
Load items asynchronously while typing and render custom status content.
import { createSignal, createMemo } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Autocomplete } from 'base-ui-solid/autocomplete';
import styles from './index.module.css';
export default function ExampleAsyncAutocomplete() {
const [searchValue, setSearchValue] = createSignal('');
const [searchResults, setSearchResults] = createSignal<Movie[]>([]);
const [error, setError] = createSignal<string | null>(null);
const [isPending, setPending] = createSignal(false);
let pendingCount = 0;
async function startTransition(work: () => unknown) {
pendingCount += 1;
setPending(true);
try {
await work();
} finally {
pendingCount -= 1;
setPending(pendingCount > 0);
}
}
const { contains } = Autocomplete.useFilter();
const abortControllerRef = { current: null } as { current: AbortController | null };
function getStatus(): JSX.Element | null {
if (isPending()) {
return (
<>
<span class={styles.Spinner} aria-hidden="true" />
Searching…
</>
);
}
if (error()) {
return error();
}
if (searchValue() === '') {
return null;
}
if (searchResults().length === 0) {
return `Movie or year "${searchValue()}" does not exist in the Top 100 IMDb movies`;
}
return `${searchResults().length} result${searchResults().length === 1 ? '' : 's'} found`;
}
const status = createMemo(getStatus);
return (
<Autocomplete.Root
items={searchResults()}
value={searchValue()}
onValueChange={(nextSearchValue) => {
setSearchValue(nextSearchValue);
const controller = new AbortController();
abortControllerRef.current?.abort();
abortControllerRef.current = controller;
if (nextSearchValue === '') {
setSearchResults([]);
setError(null);
return;
}
startTransition(async () => {
setError(null);
const result = await searchMovies(nextSearchValue, contains);
if (controller.signal.aborted) {
return;
}
startTransition(() => {
setSearchResults(result.movies);
setError(result.error);
});
});
}}
itemToStringValue={(item) => item.title}
filter={null}
>
<label class={styles.Label}>
Search movies by name or year
<Autocomplete.Input placeholder="e.g. Pulp Fiction or 1994" class={styles.Input} />
</label>
<Autocomplete.Portal hidden={!status()}>
<Autocomplete.Positioner class={styles.Positioner} sideOffset={4} align="start">
<Autocomplete.Popup class={styles.Popup} aria-busy={isPending() ? 'true' : undefined}>
<div class={styles.Viewport}>
<Autocomplete.Status>
{status() && <div class={styles.Status}>{status()}</div>}
</Autocomplete.Status>
<Autocomplete.List>
{(movie: Movie) => (
<Autocomplete.Item class={styles.Item} value={movie}>
<span class={styles.MovieItem}>
<span class={styles.MovieName}>{movie.title}</span>
<span class={styles.MovieYear}>{movie.year}</span>
</span>
</Autocomplete.Item>
)}
</Autocomplete.List>
</div>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>
);
}
async function searchMovies(
query: string,
filter: (item: string, query: string) => boolean,
): Promise<{ movies: Movie[]; error: string | null }> {
// Simulate network delay
await new Promise((resolve) => {
setTimeout(resolve, Math.random() * 500 + 100);
});
// Simulate occasional network errors (1% chance)
if (Math.random() < 0.01 || query === 'will_error') {
return {
movies: [],
error: 'Failed to fetch movies. Please try again.',
};
}
const movies = top100Movies.filter(
(movie) => filter(movie.title, query) || filter(movie.year.toString(), query),
);
return {
movies,
error: null,
};
}
interface Movie {
id: string;
title: string;
year: number;
}
const top100Movies: Movie[] = [
{ id: '1', title: 'The Shawshank Redemption', year: 1994 },
{ id: '2', title: 'The Godfather', year: 1972 },
{ id: '3', title: 'The Dark Knight', year: 2008 },
{ id: '4', title: 'The Godfather Part II', year: 1974 },
{ id: '5', title: '12 Angry Men', year: 1957 },
{ id: '6', title: 'The Lord of the Rings: The Return of the King', year: 2003 },
{ id: '7', title: "Schindler's List", year: 1993 },
{ id: '8', title: 'Pulp Fiction', year: 1994 },
{ id: '9', title: 'The Lord of the Rings: The Fellowship of the Ring', year: 2001 },
{ id: '10', title: 'The Good, the Bad and the Ugly', year: 1966 },
{ id: '11', title: 'Forrest Gump', year: 1994 },
{ id: '12', title: 'The Lord of the Rings: The Two Towers', year: 2002 },
{ id: '13', title: 'Fight Club', year: 1999 },
{ id: '14', title: 'Inception', year: 2010 },
{ id: '15', title: 'Star Wars: Episode V – The Empire Strikes Back', year: 1980 },
{ id: '16', title: 'The Matrix', year: 1999 },
{ id: '17', title: 'Goodfellas', year: 1990 },
{ id: '18', title: 'Interstellar', year: 2014 },
{ id: '19', title: "One Flew Over the Cuckoo's Nest", year: 1975 },
{ id: '20', title: 'Se7en', year: 1995 },
{ id: '21', title: "It's a Wonderful Life", year: 1946 },
{ id: '22', title: 'The Silence of the Lambs', year: 1991 },
{ id: '23', title: 'Seven Samurai', year: 1954 },
{ id: '24', title: 'Saving Private Ryan', year: 1998 },
{ id: '25', title: 'City of God', year: 2002 },
{ id: '26', title: 'Life Is Beautiful', year: 1997 },
{ id: '27', title: 'The Green Mile', year: 1999 },
{ id: '28', title: 'Star Wars: Episode IV – A New Hope', year: 1977 },
{ id: '29', title: 'Terminator 2: Judgment Day', year: 1991 },
{ id: '30', title: 'Back to the Future', year: 1985 },
{ id: '31', title: 'Spirited Away', year: 2001 },
{ id: '32', title: 'The Pianist', year: 2002 },
{ id: '33', title: 'Psycho', year: 1960 },
{ id: '34', title: 'Parasite', year: 2019 },
{ id: '35', title: 'Gladiator', year: 2000 },
{ id: '36', title: 'Léon: The Professional', year: 1994 },
{ id: '37', title: 'American History X', year: 1998 },
{ id: '38', title: 'The Departed', year: 2006 },
{ id: '39', title: 'Whiplash', year: 2014 },
{ id: '40', title: 'The Prestige', year: 2006 },
{ id: '41', title: 'Grave of the Fireflies', year: 1988 },
{ id: '42', title: 'The Usual Suspects', year: 1995 },
{ id: '43', title: 'Casablanca', year: 1942 },
{ id: '44', title: 'Harakiri', year: 1962 },
{ id: '45', title: 'The Lion King', year: 1994 },
{ id: '46', title: 'The Intouchables', year: 2011 },
{ id: '47', title: 'Modern Times', year: 1936 },
{ id: '48', title: 'The Lives of Others', year: 2006 },
{ id: '49', title: 'Once Upon a Time in the West', year: 1968 },
{ id: '50', title: 'Rear Window', year: 1954 },
{ id: '51', title: 'Alien', year: 1979 },
{ id: '52', title: 'City Lights', year: 1931 },
{ id: '53', title: 'The Shining', year: 1980 },
{ id: '54', title: 'Cinema Paradiso', year: 1988 },
{ id: '55', title: 'Avengers: Infinity War', year: 2018 },
{ id: '56', title: 'Paths of Glory', year: 1957 },
{ id: '57', title: 'Django Unchained', year: 2012 },
{ id: '58', title: 'WALL·E', year: 2008 },
{ id: '59', title: 'Sunset Boulevard', year: 1950 },
{ id: '60', title: 'The Great Dictator', year: 1940 },
{ id: '61', title: 'The Dark Knight Rises', year: 2012 },
{ id: '62', title: 'Princess Mononoke', year: 1997 },
{ id: '63', title: 'Witness for the Prosecution', year: 1957 },
{ id: '64', title: 'Oldboy', year: 2003 },
{ id: '65', title: 'Aliens', year: 1986 },
{ id: '66', title: 'Once Upon a Time in America', year: 1984 },
{ id: '67', title: 'Coco', year: 2017 },
{ id: '68', title: 'Your Name.', year: 2016 },
{ id: '69', title: 'American Beauty', year: 1999 },
{ id: '70', title: 'Braveheart', year: 1995 },
{ id: '71', title: 'Das Boot', year: 1981 },
{ id: '72', title: '3 Idiots', year: 2009 },
{ id: '73', title: 'Toy Story', year: 1995 },
{ id: '74', title: 'Inglourious Basterds', year: 2009 },
{ id: '75', title: 'High and Low', year: 1963 },
{ id: '76', title: 'Amadeus', year: 1984 },
{ id: '77', title: 'Good Will Hunting', year: 1997 },
{ id: '78', title: 'Star Wars: Episode VI – Return of the Jedi', year: 1983 },
{ id: '79', title: 'The Hunt', year: 2012 },
{ id: '80', title: 'Capharnaüm', year: 2018 },
{ id: '81', title: 'Reservoir Dogs', year: 1992 },
{ id: '82', title: 'Eternal Sunshine of the Spotless Mind', year: 2004 },
{ id: '83', title: 'Requiem for a Dream', year: 2000 },
{ id: '84', title: 'Come and See', year: 1985 },
{ id: '85', title: 'Ikiru', year: 1952 },
{ id: '86', title: 'Vertigo', year: 1958 },
{ id: '87', title: 'Lawrence of Arabia', year: 1962 },
{ id: '88', title: 'Citizen Kane', year: 1941 },
{ id: '89', title: 'Memento', year: 2000 },
{ id: '90', title: 'North by Northwest', year: 1959 },
{ id: '91', title: 'Star Wars: Episode III – Revenge of the Sith', year: 2005 },
{ id: '92', title: '2001: A Space Odyssey', year: 1968 },
{ id: '93', title: 'Amélie', year: 2001 },
{ id: '94', title: "Singin' in the Rain", year: 1952 },
{ id: '95', title: 'Apocalypse Now', year: 1979 },
{ id: '96', title: 'Taxi Driver', year: 1976 },
{ id: '97', title: 'Downfall', year: 2004 },
{ id: '98', title: 'The Wolf of Wall Street', year: 2013 },
{ id: '99', title: 'A Clockwork Orange', year: 1971 },
{ id: '100', title: 'Double Indemnity', year: 1944 },
];
Inline autocomplete
Autofill the input with the highlighted item while navigating with arrow keys using the mode prop. Accepts aria-autocomplete values list, both, inline, or none.
import { Autocomplete } from 'base-ui-solid/autocomplete';
import styles from './index.module.css';
export default function ExampleAutocompleteInline() {
return (
<Autocomplete.Root items={tags} mode="both">
<label class={styles.Label}>
Search tags
<Autocomplete.Input placeholder="e.g. feature" class={styles.Input} />
</label>
<Autocomplete.Portal>
<Autocomplete.Positioner class={styles.Positioner} sideOffset={4}>
<Autocomplete.Popup class={styles.Popup}>
<Autocomplete.List class={styles.List}>
{(tag: Tag) => (
<Autocomplete.Item class={styles.Item} value={tag}>
{tag.value}
</Autocomplete.Item>
)}
</Autocomplete.List>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>
);
}
interface Tag {
id: string;
value: string;
}
const tags: Tag[] = [
{ id: 't1', value: 'feature' },
{ id: 't2', value: 'fix' },
{ id: 't3', value: 'bug' },
{ id: 't4', value: 'docs' },
{ id: 't5', value: 'internal' },
{ id: 't6', value: 'mobile' },
{ id: 'c-accordion', value: 'component: accordion' },
{ id: 'c-alert-dialog', value: 'component: alert dialog' },
{ id: 'c-autocomplete', value: 'component: autocomplete' },
{ id: 'c-avatar', value: 'component: avatar' },
{ id: 'c-checkbox', value: 'component: checkbox' },
{ id: 'c-checkbox-group', value: 'component: checkbox group' },
{ id: 'c-collapsible', value: 'component: collapsible' },
{ id: 'c-combobox', value: 'component: combobox' },
{ id: 'c-context-menu', value: 'component: context menu' },
{ id: 'c-dialog', value: 'component: dialog' },
{ id: 'c-field', value: 'component: field' },
{ id: 'c-fieldset', value: 'component: fieldset' },
{ id: 'c-filterable-menu', value: 'component: filterable menu' },
{ id: 'c-form', value: 'component: form' },
{ id: 'c-input', value: 'component: input' },
{ id: 'c-menu', value: 'component: menu' },
{ id: 'c-menubar', value: 'component: menubar' },
{ id: 'c-meter', value: 'component: meter' },
{ id: 'c-navigation-menu', value: 'component: navigation menu' },
{ id: 'c-number-field', value: 'component: number field' },
{ id: 'c-popover', value: 'component: popover' },
{ id: 'c-preview-card', value: 'component: preview card' },
{ id: 'c-progress', value: 'component: progress' },
{ id: 'c-radio', value: 'component: radio' },
{ id: 'c-scroll-area', value: 'component: scroll area' },
{ id: 'c-select', value: 'component: select' },
{ id: 'c-separator', value: 'component: separator' },
{ id: 'c-slider', value: 'component: slider' },
{ id: 'c-switch', value: 'component: switch' },
{ id: 'c-tabs', value: 'component: tabs' },
{ id: 'c-toast', value: 'component: toast' },
{ id: 'c-toggle', value: 'component: toggle' },
{ id: 'c-toggle-group', value: 'component: toggle group' },
{ id: 'c-toolbar', value: 'component: toolbar' },
{ id: 'c-tooltip', value: 'component: tooltip' },
];
Grouped
Organize related options with <Autocomplete.Group> and <Autocomplete.GroupLabel> to add section headings inside the popup.
Groups are represented by an array of objects with an items property, which itself is an array of individual items for each group. An extra property, such as value, can be provided for the heading text when rendering the group label.
interface ProduceGroupItem {
value: string;
items: string[];
}
const groups: ProduceGroupItem[] = [
{
value: 'Fruits',
items: ['Apple', 'Banana', 'Orange'],
},
{
value: 'Vegetables',
items: ['Carrot', 'Lettuce', 'Spinach'],
},
];
import { Autocomplete } from 'base-ui-solid/autocomplete';
import styles from './index.module.css';
export default function ExampleGroupAutocomplete() {
return (
<Autocomplete.Root items={groupedTags}>
<label class={styles.Label}>
Select a tag
<Autocomplete.Input placeholder="e.g. feature" class={styles.Input} />
</label>
<Autocomplete.Portal>
<Autocomplete.Positioner class={styles.Positioner} sideOffset={4}>
<Autocomplete.Popup class={styles.Popup}>
<Autocomplete.Empty>
<div class={styles.Empty}>No tags found.</div>
</Autocomplete.Empty>
<Autocomplete.List class={styles.List}>
{(group: TagGroup) => (
<Autocomplete.Group items={group.items} class={styles.Group}>
<Autocomplete.GroupLabel class={styles.GroupLabel}>
{group.value}
</Autocomplete.GroupLabel>
<Autocomplete.Collection>
{(tag: Tag) => (
<Autocomplete.Item class={styles.Item} value={tag}>
{tag.label}
</Autocomplete.Item>
)}
</Autocomplete.Collection>
</Autocomplete.Group>
)}
</Autocomplete.List>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>
);
}
interface Tag {
id: string;
label: string;
group: 'Type' | 'Component';
}
interface TagGroup {
value: string;
items: Tag[];
}
const tagsData: Tag[] = [
{ id: 't1', label: 'feature', group: 'Type' },
{ id: 't2', label: 'fix', group: 'Type' },
{ id: 't3', label: 'bug', group: 'Type' },
{ id: 't4', label: 'docs', group: 'Type' },
{ id: 't5', label: 'internal', group: 'Type' },
{ id: 't6', label: 'mobile', group: 'Type' },
{ id: 'c-accordion', label: 'component: accordion', group: 'Component' },
{ id: 'c-alert-dialog', label: 'component: alert dialog', group: 'Component' },
{ id: 'c-autocomplete', label: 'component: autocomplete', group: 'Component' },
{ id: 'c-avatar', label: 'component: avatar', group: 'Component' },
{ id: 'c-checkbox', label: 'component: checkbox', group: 'Component' },
{ id: 'c-checkbox-group', label: 'component: checkbox group', group: 'Component' },
{ id: 'c-collapsible', label: 'component: collapsible', group: 'Component' },
{ id: 'c-combobox', label: 'component: combobox', group: 'Component' },
{ id: 'c-context-menu', label: 'component: context menu', group: 'Component' },
{ id: 'c-dialog', label: 'component: dialog', group: 'Component' },
{ id: 'c-field', label: 'component: field', group: 'Component' },
{ id: 'c-fieldset', label: 'component: fieldset', group: 'Component' },
{ id: 'c-filterable-menu', label: 'component: filterable menu', group: 'Component' },
{ id: 'c-form', label: 'component: form', group: 'Component' },
{ id: 'c-input', label: 'component: input', group: 'Component' },
{ id: 'c-menu', label: 'component: menu', group: 'Component' },
{ id: 'c-menubar', label: 'component: menubar', group: 'Component' },
{ id: 'c-meter', label: 'component: meter', group: 'Component' },
{ id: 'c-navigation-menu', label: 'component: navigation menu', group: 'Component' },
{ id: 'c-number-field', label: 'component: number field', group: 'Component' },
{ id: 'c-popover', label: 'component: popover', group: 'Component' },
{ id: 'c-preview-card', label: 'component: preview card', group: 'Component' },
{ id: 'c-progress', label: 'component: progress', group: 'Component' },
{ id: 'c-radio', label: 'component: radio', group: 'Component' },
{ id: 'c-scroll-area', label: 'component: scroll area', group: 'Component' },
{ id: 'c-select', label: 'component: select', group: 'Component' },
{ id: 'c-separator', label: 'component: separator', group: 'Component' },
{ id: 'c-slider', label: 'component: slider', group: 'Component' },
{ id: 'c-switch', label: 'component: switch', group: 'Component' },
{ id: 'c-tabs', label: 'component: tabs', group: 'Component' },
{ id: 'c-toast', label: 'component: toast', group: 'Component' },
{ id: 'c-toggle', label: 'component: toggle', group: 'Component' },
{ id: 'c-toggle-group', label: 'component: toggle group', group: 'Component' },
{ id: 'c-toolbar', label: 'component: toolbar', group: 'Component' },
{ id: 'c-tooltip', label: 'component: tooltip', group: 'Component' },
];
function groupTags(tags: Tag[]): TagGroup[] {
const groups: { [key: string]: Tag[] } = {};
tags.forEach((t) => {
(groups[t.group] ??= []).push(t);
});
const order = ['Type', 'Component'];
return order.map((value) => ({ value, items: groups[value] ?? [] }));
}
const groupedTags: TagGroup[] = groupTags(tagsData);
Fuzzy matching
Use fuzzy matching to find relevant results even when the query doesn’t exactly match the item text.
import type { JSX } from '@solidjs/web';
import { Autocomplete } from 'base-ui-solid/autocomplete';
import { matchSorter } from 'match-sorter';
import styles from './index.module.css';
export default function ExampleFuzzyMatchingAutocomplete() {
return (
<Autocomplete.Root
items={fuzzyItems}
filter={fuzzyFilter}
itemToStringValue={(item) => item.title}
>
<label class={styles.Label}>
Fuzzy search documentation
<Autocomplete.Input placeholder="e.g. React" class={styles.Input} />
</label>
<Autocomplete.Portal>
<Autocomplete.Positioner class={styles.Positioner} sideOffset={4}>
<Autocomplete.Popup class={styles.Popup}>
<Autocomplete.Empty>
<div class={styles.Empty}>No results found for "{<Autocomplete.Value />}"</div>
</Autocomplete.Empty>
<Autocomplete.List class={styles.List}>
{(item: FuzzyItem) => (
<Autocomplete.Item value={item} class={styles.Item}>
<Autocomplete.Value>
{(value) => (
<span class={styles.ItemContent}>
<span class={styles.ItemHeader}>
<span class={styles.ItemTitle}>{highlightText(item.title, value)}</span>
</span>
<span class={styles.ItemDescription}>
{highlightText(item.description, value)}
</span>
</span>
)}
</Autocomplete.Value>
</Autocomplete.Item>
)}
</Autocomplete.List>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>
);
}
function highlightText(text: string, query: string): JSX.Element {
const trimmed = query.trim();
if (!trimmed) {
return text;
}
const limited = trimmed.slice(0, 100);
const escaped = limited.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const regex = new RegExp(`(${escaped})`, 'gi');
return text.split(regex).map((part, _idx) => (regex.test(part) ? <mark>{part}</mark> : part));
}
function fuzzyFilter(item: FuzzyItem, query: string): boolean {
if (!query) {
return true;
}
const results = matchSorter([item], query, {
keys: [
'title',
'description',
'category',
{ key: 'title', threshold: matchSorter.rankings.CONTAINS },
{ key: 'description', threshold: matchSorter.rankings.WORD_STARTS_WITH },
],
});
return results.length > 0;
}
interface FuzzyItem {
title: string;
description: string;
category: string;
}
const fuzzyItems: FuzzyItem[] = [
{
title: 'React Hooks Guide',
description: 'Learn how to use React Hooks like useState, useEffect, and custom hooks',
category: 'React',
},
{
title: 'JavaScript Array Methods',
description: 'Master array methods like map, filter, reduce, and forEach in JavaScript',
category: 'JavaScript',
},
{
title: 'CSS Flexbox Layout',
description: 'Complete guide to CSS Flexbox for responsive web design',
category: 'CSS',
},
{
title: 'TypeScript Interfaces',
description: 'Understanding TypeScript interfaces and type definitions',
category: 'TypeScript',
},
{
title: 'React Performance Optimization',
description: 'Tips and techniques for optimizing React application performance',
category: 'React',
},
{
title: 'HTML Semantic Elements',
description: 'Using semantic HTML elements for better accessibility and SEO',
category: 'HTML',
},
{
title: 'Node.js Express Server',
description: 'Building RESTful APIs with Node.js and Express framework',
category: 'Node.js',
},
{
title: 'Vue Composition API',
description: 'Modern Vue.js development using the Composition API',
category: 'Vue.js',
},
{
title: 'Angular Components',
description: 'Creating reusable Angular components with TypeScript',
category: 'Angular',
},
{
title: 'Python Django Framework',
description: 'Web development with Python Django framework',
category: 'Python',
},
{
title: 'CSS Grid Layout',
description: 'Advanced CSS Grid techniques for complex layouts',
category: 'CSS',
},
{
title: 'React Testing Library',
description: 'Testing React components with React Testing Library',
category: 'React',
},
{
title: 'MongoDB Queries',
description: 'Advanced MongoDB queries and aggregation pipelines',
category: 'Database',
},
{
title: 'Webpack Configuration',
description: 'Optimizing webpack configuration for production builds',
category: 'Build Tools',
},
{
title: 'SASS/SCSS Guide',
description: 'Writing maintainable CSS with SASS and SCSS',
category: 'CSS',
},
];
Limit results
Limit the number of visible items using the limit prop and guide users to refine their query using <Autocomplete.Status>.
import { createSignal, createMemo } from 'solid-js';
import { Autocomplete } from 'base-ui-solid/autocomplete';
import styles from './index.module.css';
const limit = 8;
export default function ExampleAutocompleteLimit() {
const [value, setValue] = createSignal('');
const { contains } = Autocomplete.useFilter({ sensitivity: 'base' });
const totalMatches = createMemo(() => {
const trimmed = value().trim();
if (!trimmed) {
return tags.length;
}
return tags.filter((t) => contains(t.value, trimmed)).length;
});
const moreCount = createMemo(() => Math.max(0, totalMatches() - limit));
return (
<Autocomplete.Root items={tags} value={value()} onValueChange={setValue} limit={limit}>
<label class={styles.Label}>
Limit results to 8
<Autocomplete.Input placeholder="e.g. component" class={styles.Input} />
</label>
<Autocomplete.Portal>
<Autocomplete.Positioner class={styles.Positioner} sideOffset={4}>
<Autocomplete.Popup class={styles.Popup}>
<Autocomplete.Empty>
<div class={styles.Empty}>No results found for "{value()}"</div>
</Autocomplete.Empty>
<Autocomplete.List>
{(tag: Tag) => (
<Autocomplete.Item class={styles.Item} value={tag}>
{tag.value}
</Autocomplete.Item>
)}
</Autocomplete.List>
<Autocomplete.Status>
{moreCount() > 0 ? (
<div class={styles.Status}>
{`Hiding ${moreCount()} results (type a more specific query to narrow results)`}
</div>
) : null}
</Autocomplete.Status>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>
);
}
interface Tag {
id: string;
value: string;
}
// Larger dataset to make the limit visible.
const tags: Tag[] = [
{ id: 't1', value: 'feature' },
{ id: 't2', value: 'fix' },
{ id: 't3', value: 'bug' },
{ id: 't4', value: 'docs' },
{ id: 't5', value: 'internal' },
{ id: 't6', value: 'mobile' },
{ id: 't7', value: 'frontend' },
{ id: 't8', value: 'backend' },
{ id: 't9', value: 'performance' },
{ id: 't10', value: 'accessibility' },
{ id: 't11', value: 'design' },
{ id: 't12', value: 'research' },
{ id: 't13', value: 'testing' },
{ id: 't14', value: 'infrastructure' },
{ id: 't15', value: 'documentation' },
{ id: 'c-accordion', value: 'component: accordion' },
{ id: 'c-alert-dialog', value: 'component: alert dialog' },
{ id: 'c-autocomplete', value: 'component: autocomplete' },
{ id: 'c-avatar', value: 'component: avatar' },
{ id: 'c-checkbox', value: 'component: checkbox' },
{ id: 'c-checkbox-group', value: 'component: checkbox group' },
{ id: 'c-collapsible', value: 'component: collapsible' },
{ id: 'c-combobox', value: 'component: combobox' },
{ id: 'c-context-menu', value: 'component: context menu' },
{ id: 'c-dialog', value: 'component: dialog' },
{ id: 'c-field', value: 'component: field' },
{ id: 'c-fieldset', value: 'component: fieldset' },
{ id: 'c-filterable-menu', value: 'component: filterable menu' },
{ id: 'c-form', value: 'component: form' },
{ id: 'c-input', value: 'component: input' },
{ id: 'c-menu', value: 'component: menu' },
{ id: 'c-menubar', value: 'component: menubar' },
{ id: 'c-meter', value: 'component: meter' },
{ id: 'c-navigation-menu', value: 'component: navigation menu' },
{ id: 'c-number-field', value: 'component: number field' },
{ id: 'c-popover', value: 'component: popover' },
{ id: 'c-preview-card', value: 'component: preview card' },
{ id: 'c-progress', value: 'component: progress' },
{ id: 'c-radio', value: 'component: radio' },
{ id: 'c-scroll-area', value: 'component: scroll area' },
{ id: 'c-select', value: 'component: select' },
{ id: 'c-separator', value: 'component: separator' },
{ id: 'c-slider', value: 'component: slider' },
{ id: 'c-switch', value: 'component: switch' },
{ id: 'c-tabs', value: 'component: tabs' },
{ id: 'c-toast', value: 'component: toast' },
{ id: 'c-toggle', value: 'component: toggle' },
{ id: 'c-toggle-group', value: 'component: toggle group' },
{ id: 'c-toolbar', value: 'component: toolbar' },
{ id: 'c-tooltip', value: 'component: tooltip' },
];
Auto highlight
The first matching item can be automatically highlighted as the user types by specifying the autoHighlight prop on <Autocomplete.Root>. Set the prop’s value to "always" if the highlight should always be present, such as when the list is rendered inline within a dialog.
The prop can be combined with the keepHighlight and highlightItemOnHover props to configure how the highlight behaves during mouse interactions.
import { Autocomplete } from 'base-ui-solid/autocomplete';
import styles from './index.module.css';
export default function ExampleAutocompleteAutoHighlight() {
return (
<Autocomplete.Root items={tags} autoHighlight>
<label class={styles.Label}>
Auto highlight on type
<Autocomplete.Input placeholder="e.g. feature" class={styles.Input} />
</label>
<Autocomplete.Portal>
<Autocomplete.Positioner class={styles.Positioner} sideOffset={4}>
<Autocomplete.Popup class={styles.Popup}>
<Autocomplete.Empty>
<div class={styles.Empty}>No tags found.</div>
</Autocomplete.Empty>
<Autocomplete.List class={styles.List}>
{(tag: Tag) => (
<Autocomplete.Item class={styles.Item} value={tag}>
{tag.value}
</Autocomplete.Item>
)}
</Autocomplete.List>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>
);
}
interface Tag {
id: string;
value: string;
}
const tags: Tag[] = [
{ id: 't1', value: 'feature' },
{ id: 't2', value: 'fix' },
{ id: 't3', value: 'bug' },
{ id: 't4', value: 'docs' },
{ id: 't5', value: 'internal' },
{ id: 't6', value: 'mobile' },
{ id: 'c-accordion', value: 'component: accordion' },
{ id: 'c-alert-dialog', value: 'component: alert dialog' },
{ id: 'c-autocomplete', value: 'component: autocomplete' },
{ id: 'c-avatar', value: 'component: avatar' },
{ id: 'c-checkbox', value: 'component: checkbox' },
{ id: 'c-checkbox-group', value: 'component: checkbox group' },
{ id: 'c-collapsible', value: 'component: collapsible' },
{ id: 'c-combobox', value: 'component: combobox' },
{ id: 'c-context-menu', value: 'component: context menu' },
{ id: 'c-dialog', value: 'component: dialog' },
{ id: 'c-field', value: 'component: field' },
{ id: 'c-fieldset', value: 'component: fieldset' },
{ id: 'c-filterable-menu', value: 'component: filterable menu' },
{ id: 'c-form', value: 'component: form' },
{ id: 'c-input', value: 'component: input' },
{ id: 'c-menu', value: 'component: menu' },
{ id: 'c-menubar', value: 'component: menubar' },
{ id: 'c-meter', value: 'component: meter' },
{ id: 'c-navigation-menu', value: 'component: navigation menu' },
{ id: 'c-number-field', value: 'component: number field' },
{ id: 'c-popover', value: 'component: popover' },
{ id: 'c-preview-card', value: 'component: preview card' },
{ id: 'c-progress', value: 'component: progress' },
{ id: 'c-radio', value: 'component: radio' },
{ id: 'c-scroll-area', value: 'component: scroll area' },
{ id: 'c-select', value: 'component: select' },
{ id: 'c-separator', value: 'component: separator' },
{ id: 'c-slider', value: 'component: slider' },
{ id: 'c-switch', value: 'component: switch' },
{ id: 'c-tabs', value: 'component: tabs' },
{ id: 'c-toast', value: 'component: toast' },
{ id: 'c-toggle', value: 'component: toggle' },
{ id: 'c-toggle-group', value: 'component: toggle group' },
{ id: 'c-toolbar', value: 'component: toolbar' },
{ id: 'c-tooltip', value: 'component: tooltip' },
];
Command palette
Use the autocomplete input to filter a list of command items that perform an action when clicked.
import { createSignal, createUniqueId } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Dialog } from 'base-ui-solid/dialog';
import { Autocomplete } from 'base-ui-solid/autocomplete';
import { ScrollArea } from 'base-ui-solid/scroll-area';
import styles from './index.module.css';
export default function ExampleAutocompleteCommandPalette() {
const [open, setOpen] = createSignal(false);
const shortcutsDescriptionId = createUniqueId();
function handleItemClick() {
setOpen(false);
}
return (
<Dialog.Root open={open()} onOpenChange={setOpen}>
<Dialog.Trigger class={styles.Button}>Open command palette</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Backdrop class={styles.Backdrop} />
<Dialog.Viewport class={styles.Viewport}>
<Dialog.Popup class={styles.Popup} aria-label="Command palette">
<Autocomplete.Root
open
inline
items={groupedItems}
autoHighlight="always"
keepHighlight
>
<Autocomplete.InputGroup class={styles.InputGroup}>
<MagnifyingGlassIcon class={styles.InputIcon} aria-hidden="true" />
<Autocomplete.Input
class={styles.Input}
aria-label="Search commands"
aria-describedby={shortcutsDescriptionId}
placeholder="Search for apps and commands…"
/>
</Autocomplete.InputGroup>
<Dialog.Close class={styles.VisuallyHidden}>Close command palette</Dialog.Close>
<ScrollArea.Root class={styles.ListArea}>
<ScrollArea.Viewport class={styles.ListViewport}>
<ScrollArea.Content class={styles.ListContent}>
<Autocomplete.Empty>
<div class={styles.Empty}>No results found.</div>
</Autocomplete.Empty>
<Autocomplete.List class={styles.List}>
{(group: Group) => (
<Autocomplete.Group items={group.items} class={styles.Group}>
<Autocomplete.GroupLabel class={styles.GroupLabel}>
{group.value}
</Autocomplete.GroupLabel>
<Autocomplete.Collection>
{(item: Item) => (
<Autocomplete.Item
value={item}
class={styles.Item}
onClick={handleItemClick}
>
<span class={styles.ItemLabel}>{item.label}</span>
<span class={styles.ItemType}>
{group.value === 'Suggestions' ? 'Application' : 'Command'}
</span>
</Autocomplete.Item>
)}
</Autocomplete.Collection>
</Autocomplete.Group>
)}
</Autocomplete.List>
</ScrollArea.Content>
</ScrollArea.Viewport>
<ScrollArea.Scrollbar class={styles.Scrollbar}>
<ScrollArea.Thumb class={styles.ScrollbarThumb} />
</ScrollArea.Scrollbar>
</ScrollArea.Root>
<div class={styles.Footer}>
<span id={shortcutsDescriptionId} class={styles.VisuallyHidden}>
Use Enter to activate the highlighted item.
</span>
<div class={styles.FooterLeft}>
<span>Activate</span>
<kbd class={styles.Kbd}>Enter</kbd>
</div>
</div>
</Autocomplete.Root>
</Dialog.Popup>
</Dialog.Viewport>
</Dialog.Portal>
</Dialog.Root>
);
}
function MagnifyingGlassIcon(props: JSX.IntrinsicElements['svg']) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
stroke-linecap="square"
stroke-linejoin="round"
{...props}
style={
typeof props.style === 'string'
? `display: block; ${props.style}`
: { display: 'block', ...(typeof props.style === 'object' ? props.style : {}) }
}
>
<path d="m11 11 3.5 3.5" />
<circle cx="7" cy="7" r="5.5" />
</svg>
);
}
interface Item {
value: string;
label: string;
}
interface Group {
value: string;
items: Item[];
}
const suggestions: Item[] = [
{ value: 'linear', label: 'Linear' },
{ value: 'figma', label: 'Figma' },
{ value: 'slack', label: 'Slack' },
{ value: 'youtube', label: 'YouTube' },
{ value: 'raycast', label: 'Raycast' },
{ value: 'notion', label: 'Notion' },
{ value: 'github', label: 'GitHub' },
{ value: 'jira', label: 'Jira' },
{ value: 'calendar', label: 'Google Calendar' },
{ value: 'chrome', label: 'Google Chrome' },
{ value: 'mail', label: 'Apple Mail' },
{ value: 'terminal', label: 'Terminal' },
];
const commands: Item[] = [
{ value: 'clipboard-history', label: 'Clipboard History' },
{ value: 'import-extension', label: 'Import Extension' },
{ value: 'create-snippet', label: 'Create Snippet' },
{ value: 'system-preferences', label: 'System Preferences' },
{ value: 'window-management', label: 'Window Management' },
{ value: 'toggle-dark-mode', label: 'Toggle Dark Mode' },
{ value: 'new-window', label: 'New Window' },
{ value: 'new-tab', label: 'New Tab' },
{ value: 'search-docs', label: 'Search Documentation' },
{ value: 'capture-screen', label: 'Capture Screenshot' },
{ value: 'close-sidebar', label: 'Toggle Sidebar' },
{ value: 'toggle-terminal', label: 'Toggle Integrated Terminal' },
{ value: 'run-script', label: 'Run Script' },
];
const groupedItems: Group[] = [
{ value: 'Suggestions', items: suggestions },
{ value: 'Commands', items: commands },
];
Custom keyboard shortcuts
Use actionsRef.highlightItem() to navigate the open list with custom keyboard shortcuts. This example binds Ctrl+N to the next item and Ctrl+P to the previous item.
Navigate with Ctrl+N and Ctrl+P.
import { Autocomplete } from 'base-ui-solid/autocomplete';
import styles from './index.module.css';
export default function ExampleAutocompleteKeyboardShortcuts() {
const actionsRef = { current: null } as { current: Autocomplete.Root.Actions | null };
function handleKeyDown(event: KeyboardEvent) {
if (!event.ctrlKey || event.altKey || event.metaKey) {
return;
}
// Lower-cased so the shortcuts still work with Caps Lock on or Shift held.
const target = shortcuts[event.key.toLowerCase()];
if (!target) {
return;
}
event.preventDefault();
actionsRef.current?.highlightItem(target);
}
return (
<Autocomplete.Root items={commands} actionsRef={actionsRef}>
<div class={styles.Field}>
<label class={styles.Label}>
Search commands
<Autocomplete.Input
placeholder="e.g. commit"
class={styles.Input}
onKeyDown={handleKeyDown}
/>
</label>
<p class={styles.Hint}>Navigate with Ctrl+N and Ctrl+P.</p>
</div>
<Autocomplete.Portal>
<Autocomplete.Positioner class={styles.Positioner} sideOffset={4}>
<Autocomplete.Popup class={styles.Popup}>
<Autocomplete.Empty>
<div class={styles.Empty}>No commands found.</div>
</Autocomplete.Empty>
<Autocomplete.List class={styles.List}>
{(command: string) => (
<Autocomplete.Item class={styles.Item} value={command}>
{command}
</Autocomplete.Item>
)}
</Autocomplete.List>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>
);
}
const shortcuts: Record<string, Autocomplete.Root.HighlightItemTarget> = {
n: 'next',
p: 'previous',
};
const commands = [
'Commit changes',
'Create branch',
'Discard changes',
'Fetch origin',
'Open pull request',
'Pull changes',
'Push changes',
'Stash changes',
'Switch branch',
'View history',
];
Navigation wraps between the first and last items unless loopFocus is disabled. Unlike arrow-key navigation, these shortcuts do not return the highlight to the input.
Grid layout
Display items in a grid layout, wrapping each row in <Autocomplete.Row> components.
import { createSignal, For } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Autocomplete } from 'base-ui-solid/autocomplete';
import styles from './index.module.css';
export default function ExampleEmojiPicker() {
const [pickerOpen, setPickerOpen] = createSignal(false);
const [textValue, setTextValue] = createSignal('');
const [searchValue, setSearchValue] = createSignal('');
const textInputRef = { current: null } as { current: HTMLInputElement | null };
function handleInsertEmoji(value: string | null) {
if (!value || !textInputRef.current) {
return;
}
const emoji = value;
const start = textInputRef.current.selectionStart ?? textInputRef.current.value.length ?? 0;
const end = textInputRef.current.selectionEnd ?? textInputRef.current.value.length ?? 0;
setTextValue((prev) => prev.slice(0, start) + emoji + prev.slice(end));
setPickerOpen(false);
const input = textInputRef.current;
if (input) {
input.focus();
const caretPos = start + emoji.length;
input.setSelectionRange(caretPos, caretPos);
}
}
return (
<div class={styles.Container}>
<div class={styles.InputGroup}>
<input
ref={(element) => {
textInputRef.current = element;
}}
type="text"
aria-label="Message"
class={styles.TextInput}
placeholder="iMessage"
value={textValue()}
onInput={(event) => setTextValue(event.target.value)}
/>
<Autocomplete.Root
items={emojiGroups}
grid
open={pickerOpen()}
onOpenChange={setPickerOpen}
onOpenChangeComplete={() => setSearchValue('')}
value={searchValue()}
onValueChange={(value, details) => {
if (details.reason !== 'item-press') {
setSearchValue(value);
}
}}
>
<Autocomplete.Trigger class={styles.EmojiButton} aria-label="Choose emoji">
😀
</Autocomplete.Trigger>
<Autocomplete.Portal>
<Autocomplete.Positioner class={styles.Positioner} sideOffset={4} align="end">
<Autocomplete.Popup class={styles.Popup} aria-label="Select emoji">
<Autocomplete.Input
aria-label="Search emojis"
placeholder="Search emojis…"
class={styles.Input}
/>
<div class={styles.Viewport}>
<Autocomplete.Empty>
<div class={styles.Empty}>No emojis found</div>
</Autocomplete.Empty>
<Autocomplete.List
aria-label="Emoji results"
class={styles.List}
style={{ '--cols': COLUMNS } as JSX.CSSProperties}
>
{(group: EmojiGroup) => (
<Autocomplete.Group items={group.items} class={styles.Group}>
<Autocomplete.GroupLabel class={styles.GroupLabel}>
{group.label}
</Autocomplete.GroupLabel>
<div class={styles.Grid} role="presentation">
<For each={chunkArray(group.items, COLUMNS)}>
{(row, _rowIdx) => (
<Autocomplete.Row class={styles.Row}>
<For each={row}>
{(rowItem) => (
<Autocomplete.Item
value={rowItem}
class={styles.Item}
onClick={() => {
handleInsertEmoji(rowItem.emoji);
setPickerOpen(false);
}}
>
<span class={styles.Emoji}>{rowItem.emoji}</span>
</Autocomplete.Item>
)}
</For>
</Autocomplete.Row>
)}
</For>
</div>
</Autocomplete.Group>
)}
</Autocomplete.List>
</div>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>
</div>
</div>
);
}
const COLUMNS = 5;
function chunkArray<T>(array: T[], size: number): T[][] {
const result: T[][] = [];
for (let i = 0; i < array.length; i += size) {
result.push(array.slice(i, i + size));
}
return result;
}
interface EmojiItem {
emoji: string;
value: string;
name: string;
}
interface EmojiGroup {
value: string;
label: string;
items: EmojiItem[];
}
export const emojiCategories = [
{
label: 'Smileys & Emotion',
emojis: [
{ emoji: '😀', name: 'grinning face' },
{ emoji: '😃', name: 'grinning face with big eyes' },
{ emoji: '😄', name: 'grinning face with smiling eyes' },
{ emoji: '😁', name: 'beaming face with smiling eyes' },
{ emoji: '😆', name: 'grinning squinting face' },
{ emoji: '😅', name: 'grinning face with sweat' },
{ emoji: '🤣', name: 'rolling on the floor laughing' },
{ emoji: '😂', name: 'face with tears of joy' },
{ emoji: '🙂', name: 'slightly smiling face' },
{ emoji: '🙃', name: 'upside-down face' },
{ emoji: '😉', name: 'winking face' },
{ emoji: '😊', name: 'smiling face with smiling eyes' },
{ emoji: '😇', name: 'smiling face with halo' },
{ emoji: '🥰', name: 'smiling face with hearts' },
{ emoji: '😍', name: 'smiling face with heart-eyes' },
{ emoji: '🤩', name: 'star-struck' },
{ emoji: '😘', name: 'face blowing a kiss' },
{ emoji: '😗', name: 'kissing face' },
{ emoji: '☺️', name: 'smiling face' },
{ emoji: '😚', name: 'kissing face with closed eyes' },
{ emoji: '😙', name: 'kissing face with smiling eyes' },
{ emoji: '🥲', name: 'smiling face with tear' },
{ emoji: '😋', name: 'face savoring food' },
{ emoji: '😛', name: 'face with tongue' },
{ emoji: '😜', name: 'winking face with tongue' },
{ emoji: '🤪', name: 'zany face' },
{ emoji: '😝', name: 'squinting face with tongue' },
{ emoji: '🤑', name: 'money-mouth face' },
{ emoji: '🤗', name: 'hugging face' },
{ emoji: '🤭', name: 'face with hand over mouth' },
],
},
{
label: 'Animals & Nature',
emojis: [
{ emoji: '🐶', name: 'dog face' },
{ emoji: '🐱', name: 'cat face' },
{ emoji: '🐭', name: 'mouse face' },
{ emoji: '🐹', name: 'hamster' },
{ emoji: '🐰', name: 'rabbit face' },
{ emoji: '🦊', name: 'fox' },
{ emoji: '🐻', name: 'bear' },
{ emoji: '🐼', name: 'panda' },
{ emoji: '🐨', name: 'koala' },
{ emoji: '🐯', name: 'tiger face' },
{ emoji: '🦁', name: 'lion' },
{ emoji: '🐮', name: 'cow face' },
{ emoji: '🐷', name: 'pig face' },
{ emoji: '🐽', name: 'pig nose' },
{ emoji: '🐸', name: 'frog' },
{ emoji: '🐵', name: 'monkey face' },
{ emoji: '🙈', name: 'see-no-evil monkey' },
{ emoji: '🙉', name: 'hear-no-evil monkey' },
{ emoji: '🙊', name: 'speak-no-evil monkey' },
{ emoji: '🐒', name: 'monkey' },
{ emoji: '🐔', name: 'chicken' },
{ emoji: '🐧', name: 'penguin' },
{ emoji: '🐦', name: 'bird' },
{ emoji: '🐤', name: 'baby chick' },
{ emoji: '🐣', name: 'hatching chick' },
{ emoji: '🐥', name: 'front-facing baby chick' },
{ emoji: '🦆', name: 'duck' },
{ emoji: '🦅', name: 'eagle' },
{ emoji: '🦉', name: 'owl' },
{ emoji: '🦇', name: 'bat' },
],
},
{
label: 'Food & Drink',
emojis: [
{ emoji: '🍎', name: 'red apple' },
{ emoji: '🍏', name: 'green apple' },
{ emoji: '🍊', name: 'tangerine' },
{ emoji: '🍋', name: 'lemon' },
{ emoji: '🍌', name: 'banana' },
{ emoji: '🍉', name: 'watermelon' },
{ emoji: '🍇', name: 'grapes' },
{ emoji: '🍓', name: 'strawberry' },
{ emoji: '🫐', name: 'blueberries' },
{ emoji: '🍈', name: 'melon' },
{ emoji: '🍒', name: 'cherries' },
{ emoji: '🍑', name: 'peach' },
{ emoji: '🥭', name: 'mango' },
{ emoji: '🍍', name: 'pineapple' },
{ emoji: '🥥', name: 'coconut' },
{ emoji: '🥝', name: 'kiwi fruit' },
{ emoji: '🍅', name: 'tomato' },
{ emoji: '🍆', name: 'eggplant' },
{ emoji: '🥑', name: 'avocado' },
{ emoji: '🥦', name: 'broccoli' },
{ emoji: '🥬', name: 'leafy greens' },
{ emoji: '🥒', name: 'cucumber' },
{ emoji: '🌶️', name: 'hot pepper' },
{ emoji: '🫑', name: 'bell pepper' },
{ emoji: '🌽', name: 'ear of corn' },
{ emoji: '🥕', name: 'carrot' },
{ emoji: '🫒', name: 'olive' },
{ emoji: '🧄', name: 'garlic' },
{ emoji: '🧅', name: 'onion' },
{ emoji: '🥔', name: 'potato' },
],
},
];
const emojiGroups: EmojiGroup[] = emojiCategories.map((category) => ({
value: category.label,
label: category.label,
items: category.emojis.map((emoji) => ({
...emoji,
value: emoji.name.toLowerCase(),
})),
}));
Virtualized
Efficiently handle large datasets using a virtualization library like @tanstack/virtual-core.
import { onSettled, For } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Autocomplete } from 'base-ui-solid/autocomplete';
import { useVirtualizer } from './useVirtualizer';
import styles from './index.module.css';
export default function ExampleVirtualizedAutocomplete() {
const virtualizerRef = { current: null } as { current: Virtualizer | null };
return (
<Autocomplete.Root
virtualized
items={virtualizedItems}
openOnInputClick
itemToStringValue={getItemLabel}
onItemHighlighted={(item, { reason, index }) => {
const virtualizer = virtualizerRef.current;
if (!item || !virtualizer) {
return;
}
const isStart = index === 0;
const isEnd = index === virtualizer.options.count - 1;
// `imperative-action` can jump anywhere in the list, so it always needs a scroll:
// unlike the arrow keys it can target an item that is not currently rendered.
const shouldScroll =
reason === 'none' ||
reason === 'imperative-action' ||
(reason === 'keyboard' && (isStart || isEnd));
if (shouldScroll) {
queueMicrotask(() => {
virtualizer.scrollToIndex(index, { align: isEnd ? 'start' : 'end' });
});
}
}}
>
<label class={styles.Label}>
Search 10,000 items
<Autocomplete.Input class={styles.Input} />
</label>
<Autocomplete.Portal>
<Autocomplete.Positioner class={styles.Positioner} sideOffset={4}>
<Autocomplete.Popup class={styles.Popup}>
<Autocomplete.Empty>
<div class={styles.Empty}>No items found.</div>
</Autocomplete.Empty>
<Autocomplete.List class={styles.List}>
<VirtualizedList virtualizerRef={virtualizerRef} />
</Autocomplete.List>
</Autocomplete.Popup>
</Autocomplete.Positioner>
</Autocomplete.Portal>
</Autocomplete.Root>
);
}
function VirtualizedList(props: { virtualizerRef: { current: Virtualizer | null } }) {
const filteredItems = Autocomplete.useFilteredItems<VirtualizedItem>();
const scrollElementRef = { current: null } as { current: HTMLDivElement | null };
const virtualizer = useVirtualizer({
get count() {
return filteredItems().length;
},
getScrollElement: () => scrollElementRef.current,
estimateSize: () => 32,
overscan: 20,
paddingStart: 4,
paddingEnd: 4,
scrollPaddingEnd: 4,
scrollPaddingStart: 4,
});
onSettled(() => {
props.virtualizerRef.current = virtualizer;
return () => {
props.virtualizerRef.current = null;
};
});
const handleScrollElementRef = (element: HTMLDivElement | null) => {
scrollElementRef.current = element;
if (element) {
virtualizer.measure();
}
};
const totalSize = () => virtualizer.getTotalSize();
return (
<div
role="presentation"
ref={handleScrollElementRef}
class={styles.Scroller}
style={{ '--total-size': `${totalSize()}px` } as JSX.CSSProperties}
>
<div
role="presentation"
class={styles.VirtualizedPlaceholder}
style={{ height: `${totalSize()}px` }}
>
<For each={virtualizer.getVirtualItems()}>
{(virtualItem) => {
const item = filteredItems()[virtualItem.index];
if (!item) {
return null;
}
return (
<Autocomplete.Item
index={virtualItem.index}
data-index={virtualItem.index}
ref={virtualizer.measureElement}
value={item}
class={styles.Item}
aria-setsize={filteredItems().length}
aria-posinset={virtualItem.index + 1}
style={{
position: 'absolute',
top: 0,
left: 0,
width: '100%',
height: `${virtualItem.size}px`,
transform: `translateY(${virtualItem.start}px)`,
}}
>
{item.name}
</Autocomplete.Item>
);
}}
</For>
</div>
</div>
);
}
interface VirtualizedItem {
id: string;
name: string;
}
function getItemLabel(item: VirtualizedItem | null) {
return item ? item.name : '';
}
const virtualizedItems: VirtualizedItem[] = Array.from({ length: 10000 }, (_, index) => {
const id = String(index + 1);
const indexLabel = id.padStart(4, '0');
return { id, name: `Item ${indexLabel}` };
});
type Virtualizer = ReturnType<typeof useVirtualizer<HTMLDivElement, Element>>;
When using highlightItem(), scroll your virtualizer to the index reported by onItemHighlighted for the 'imperative-action' reason. The highlighted item may not be rendered yet.
Memoizing items
Solid creates each item component once and updates its reactive bindings, so no component memoization wrapper is needed. Pass the item as a prop and read it through the props object. With a large enough number of items, the mount cost dominates, and virtualization becomes necessary to keep the open interaction fast on low-end devices.
interface Suggestion {
id: string;
label: string;
description: string;
}
function SuggestionItem(props: { item: Suggestion }) {
return (
<Autocomplete.Item value={props.item}>
<span>{props.item.label}</span>
<span>{props.item.description}</span>
</Autocomplete.Item>
);
}
<Autocomplete.List>{(item: Suggestion) => <SuggestionItem item={item} />}</Autocomplete.List>;
API reference
Root
Groups all parts of the autocomplete. Doesn’t render its own HTML element.
namestring—
stringdefaultValueUnion—
value prop instead.string | number | string[]valueUnion—
string | string[] | numberonValueChangefunction—
((value: string, eventDetails: Autocomplete.Root.ChangeEventDetails) => void)defaultOpenbooleanfalse
open prop instead.booleanopenboolean—
booleanonOpenChangefunction—
((open: boolean, eventDetails: Autocomplete.Root.OpenChangeEventDetails) => void)autoHighlightUnionfalse
true: highlight after the user types and keep the highlight while the query changes.'always': always highlight the first item.boolean | 'always'keepHighlightbooleanfalse
booleanhighlightItemOnHoverbooleantrue
:hover to be differentiated from the :focus (data-highlighted) state.booleanactionsRefRefObject<Autocomplete.Root.Actions | null>—
unmount: Ends the closing phase of the autocomplete after an externally controlled closing animation finishes.
Call preventUnmountOnClose() in onOpenChange first, otherwise the autocomplete completes closing on its own.
Whether it leaves the DOM is decided by keepMounted on the portal.close: Closes the autocomplete imperatively when called.highlightItem: Moves or clears the highlight while the popup is open.
'next' and 'previous' move sequentially through the items, including across rows in a
grid, and wrap when loopFocus is enabled. Unlike the arrow keys, they never return the
highlight to the input. 'first' and 'last' highlight the first or last item.
'none' clears the highlight; with autoHighlight="always", the highlight cannot be cleared.
Calling this action does not open the popup. To highlight an item after opening it, call
the action from onOpenChangeComplete when open is true.
Highlight changes requested through this action report the reason 'imperative-action'
to onItemHighlighted.RefObject<Autocomplete.Root.Actions | null>filterfunction—
((item: ItemValue, query: string, itemToString?: ((item: ItemValue) => string)) => boolean) | nullfilteredItemsUnion—
items prop internally.
When items is also provided, this array must preserve its flat or grouped structure.
Nullish entries are not supported, as in items.
Use when you want to control filtering logic externally with the useFilter() hook.any[] | Group<any>[] | ItemValue[] | Group<ItemValue>[]formstring—
stringgridbooleanfalse
booleaninlinebooleanfalse
open unconditionally in conjunction with this prop so the list is considered
visible: <Autocomplete.Root inline open>booleanitemToStringValuefunction—
<Autocomplete.Item value={object}>), this function converts the object value to a string representation for both display in the input and form submission.
If the shape of the object is { value, label }, the label will be used automatically without needing to specify this prop.((itemValue: ItemValue) => string)itemsUnion—
({ items: any[] })[] | ItemValue[]limitnumber-1
numberlocaleIntl.LocalesArgument—
Intl.LocalesArgumentloopFocusbooleantrue
booleanmodalbooleanfalse
true: user interaction is limited to the popup: document page scroll is locked and pointer interactions on outside elements are disabled.false: user interaction with the rest of the document is allowed. On touch devices, a true modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior.booleanmodeUnion'list'
list (default): items are dynamically filtered based on the input value. The input value does not change based on the active item.both: items are dynamically filtered based on the input value, which will temporarily change based on the active item (inline autocompletion).inline: items are static (not filtered), and the input value will temporarily change based on the active item (inline autocompletion).none: items are static (not filtered), and the input value will not change based on the active item.'list' | 'both' | 'inline' | 'none'onItemHighlightedfunction—
undefined if no item is highlighted) and event details with a reason property describing why the highlight changed.
The reason can be: 'keyboard': the highlight changed due to keyboard navigation.'pointer': the highlight changed due to pointer hovering. The event may be a MouseEvent
rather than a PointerEvent.'imperative-action': the highlight changed via actionsRef's highlightItem.'none': the highlight changed for another reason, such as typing, autoHighlight, the
item list changing, or the popup opening or closing.((highlightedValue: ItemValue | undefined, eventDetails: Autocomplete.Root.HighlightEventDetails) => void)onOpenChangeCompletefunction—
((open: boolean) => void)openOnInputClickbooleanfalse
booleansubmitOnItemClickbooleanfalse
booleanvirtualizedbooleanfalse
booleandisabledbooleanfalse
booleanreadOnlybooleanfalse
booleanrequiredbooleanfalse
booleaninputRefJSX.Ref<HTMLInputElement>—
JSX.Ref<HTMLInputElement>idstring—
stringchildrenJSX.Element—
JSX.ElementRoot.State
type AutocompleteRootState = {};Root.Actions
type AutocompleteRootActions = {
unmount: () => void;
close: () => void;
highlightItem: (target: Autocomplete.Root.HighlightItemTarget) => void;
};Root.ChangeEventReason
type AutocompleteRootChangeEventReason =
| 'trigger-press'
| 'input-press'
| 'outside-press'
| 'item-press'
| 'close-press'
| 'escape-key'
| 'list-navigation'
| 'focus-out'
| 'input-change'
| 'input-clear'
| 'clear-press'
| 'chip-remove-press'
| 'cancel-open'
| 'imperative-action'
| 'none';Root.ChangeEventDetails
type AutocompleteRootChangeEventDetails = (
| { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
| { reason: 'input-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
| { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
| { reason: 'item-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'close-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'escape-key'; event: KeyboardEvent }
| { reason: 'list-navigation'; event: KeyboardEvent }
| { reason: 'focus-out'; event: KeyboardEvent | FocusEvent }
| { reason: 'input-change'; event: Event | InputEvent }
| { reason: 'input-clear'; event: Event | FocusEvent | InputEvent }
| { reason: 'clear-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'chip-remove-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'cancel-open'; event: MouseEvent }
| { reason: 'imperative-action'; event: Event }
| { reason: 'none'; event: Event }
) & {
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
};Root.HighlightEventReason
type AutocompleteRootHighlightEventReason = 'keyboard' | 'pointer' | 'imperative-action' | 'none';Root.HighlightEventDetails
type AutocompleteRootHighlightEventDetails =
| { reason: 'imperative-action'; event: Event; index: number }
| { reason: 'none'; event: Event; index: number }
| { reason: 'keyboard'; event: KeyboardEvent; index: number }
| { reason: 'pointer'; event: MouseEvent | PointerEvent; index: number };Root.HighlightItemTarget
type AutocompleteRootHighlightItemTarget = 'next' | 'previous' | 'first' | 'last' | 'none';Root.OpenChangeEventDetails
type AutocompleteRootOpenChangeEventDetails = (
| { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
| { reason: 'input-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
| { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
| { reason: 'item-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'close-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'escape-key'; event: KeyboardEvent }
| { reason: 'list-navigation'; event: KeyboardEvent }
| { reason: 'focus-out'; event: KeyboardEvent | FocusEvent }
| { reason: 'input-change'; event: Event | InputEvent }
| { reason: 'input-clear'; event: Event | FocusEvent | InputEvent }
| { reason: 'clear-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'chip-remove-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'cancel-open'; event: MouseEvent }
| { reason: 'imperative-action'; event: Event }
| { reason: 'none'; event: Event }
) & {
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
/** Prevents the popup from unmounting until the `unmount` action is called. */
preventUnmountOnClose: () => void;
};Value
The current value of the autocomplete. Doesn’t render its own HTML element.
childrenfunction—
JSX.Element | ((value: string) => JSX.Element)Value.State
type AutocompleteValueState = {};Input
A text input to search for items in the list.
Renders an <input> element.
disabledbooleanfalse
booleanclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-popup-open-—
-data-popup-sideUnion—
'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | nulldata-list-empty-—
-data-pressed-—
-data-disabled-—
-data-readonly-—
-data-required-—
-data-valid-—
-data-invalid-—
-data-dirty-—
-data-touched-—
-data-filled-—
-data-focused-—
-Attribute | Description | |
|---|---|---|
data-popup-open | Present when the corresponding popup is open. | |
data-popup-side | Indicates which side the corresponding popup is positioned relative to its anchor. | |
data-list-empty | Present when the corresponding items list is empty. | |
data-pressed | Present when the input is pressed. | |
data-disabled | Present when the component is disabled. | |
data-readonly | Present when the component is readonly. | |
data-required | Present when the component is required. | |
data-valid | Present when the component is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the component is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the component’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the component has been touched (when wrapped in Field.Root). | |
data-filled | Present when the component has a value (when wrapped in Field.Root). | |
data-focused | Present when the input is focused (when wrapped in Field.Root). | |
Input.State
type AutocompleteInputState = {
/** Whether the corresponding popup is open. */
open: boolean;
/** Indicates which side the corresponding popup is positioned relative to its anchor. */
popupSide: Side | null;
/** Present when the corresponding items list is empty. */
listEmpty: boolean;
/** Whether the component should ignore user edits. */
readOnly: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the field has been touched. */
touched: boolean;
/** Whether the field value has changed from its initial value. */
dirty: boolean;
/** Whether the field is valid. */
valid: boolean | null;
/** Whether the field has a value. */
filled: boolean;
/** Whether the field is focused. */
focused: boolean;
};InputGroup
A wrapper for the input and its associated controls.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-popup-open-—
-data-popup-sideUnion—
'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | nulldata-list-empty-—
-data-pressed-—
-data-disabled-—
-data-readonly-—
-data-valid-—
-data-invalid-—
-data-dirty-—
-data-touched-—
-data-filled-—
-data-focused-—
-Attribute | Description | |
|---|---|---|
data-popup-open | Present when the corresponding popup is open. | |
data-popup-side | Indicates which side the corresponding popup is positioned relative to its anchor. | |
data-list-empty | Present when the corresponding items list is empty. | |
data-pressed | Present when the input group is pressed. | |
data-disabled | Present when the component is disabled. | |
data-readonly | Present when the component is readonly. | |
data-valid | Present when the component is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the component is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the component’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the component has been touched (when wrapped in Field.Root). | |
data-filled | Present when the component has a value (when wrapped in Field.Root). | |
data-focused | Present when the component is focused (when wrapped in Field.Root). | |
InputGroup.State
type AutocompleteInputGroupState = {
/** Whether the corresponding popup is open. */
open: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the component should ignore user edits. */
readOnly: boolean;
/** Indicates which side the corresponding popup is positioned relative to its anchor. */
popupSide: Side | null;
/** Present when the corresponding items list is empty. */
listEmpty: boolean;
/** Whether the field has been touched. */
touched: boolean;
/** Whether the field value has changed from its initial value. */
dirty: boolean;
/** Whether the field is valid. */
valid: boolean | null;
/** Whether the field has a value. */
filled: boolean;
/** Whether the field is focused. */
focused: boolean;
};Trigger
A button that opens the popup.
Renders a <button> element.
nativeButtonbooleantrue
<button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>).booleandisabledbooleanfalse
booleanclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-popup-open-—
-data-popup-sideUnion—
'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | nulldata-list-empty-—
-data-pressed-—
-data-disabled-—
-data-readonly-—
-data-required-—
-data-valid-—
-data-invalid-—
-data-dirty-—
-data-touched-—
-data-filled-—
-data-focused-—
-Attribute | Description | |
|---|---|---|
data-popup-open | Present when the corresponding popup is open. | |
data-popup-side | Indicates which side the corresponding popup is positioned relative to its anchor. | |
data-list-empty | Present when the corresponding items list is empty. | |
data-pressed | Present when the trigger is pressed. | |
data-disabled | Present when the component is disabled. | |
data-readonly | Present when the component is readonly. | |
data-required | Present when the component is required. | |
data-valid | Present when the component is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the component is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the component’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the component has been touched (when wrapped in Field.Root). | |
data-filled | Present when the component has a value (when wrapped in Field.Root). | |
data-focused | Present when the trigger is focused (when wrapped in Field.Root). | |
Trigger.State
type AutocompleteTriggerState = {
/** Whether the popup is open. */
open: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Indicates which side the corresponding popup is positioned relative to its anchor. */
popupSide: Side | null;
/** Present when the corresponding items list is empty. */
listEmpty: boolean;
/** Whether the component should ignore user edits. */
readOnly: boolean;
/** Whether the field has been touched. */
touched: boolean;
/** Whether the field value has changed from its initial value. */
dirty: boolean;
/** Whether the field is valid. */
valid: boolean | null;
/** Whether the field has a value. */
filled: boolean;
/** Whether the field is focused. */
focused: boolean;
};Icon
An icon that indicates that the trigger button opens the popup.
Renders a <span> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Icon.State
type AutocompleteIconState = {};Clear
Clears the value when clicked.
Renders a <button> element.
nativeButtonbooleantrue
<button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>).booleandisabledbooleanfalse
booleanclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)keepMountedbooleanfalse
booleanrenderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-popup-open-—
-data-disabled-—
-data-visible-—
-data-starting-style-—
-data-ending-style-—
-Attribute | Description | |
|---|---|---|
data-popup-open | Present when the corresponding popup is open. | |
data-disabled | Present when the button is disabled. | |
data-visible | Present when the clear button is visible. | |
data-starting-style | Present when the button begins animating in. | |
data-ending-style | Present when the button is animating out. | |
Clear.State
type AutocompleteClearState = {
/** Whether the popup is open. */
open: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the clear button should be visible. */
visible: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
};List
A list container for the items.
Renders a <div> element.
childrenfunction—
JSX.Element | ((item: any, index: number) => JSX.Element)classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)List.State
type AutocompleteListState = {
/** Whether the list is empty. */
empty: boolean;
};Portal
A portal element that moves the popup to a different part of the DOM.
By default, the portal element is appended to <body>.
Renders a <div> element.
containerUnion—
HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | nullclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)keepMountedbooleanfalse
booleanrenderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Portal.State
type AutocompletePortalState = {};Backdrop
An overlay displayed beneath the popup.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-open-—
-data-closed-—
-data-starting-style-—
-data-ending-style-—
-Attribute | Description | |
|---|---|---|
data-open | Present when the popup is open. | |
data-closed | Present when the popup is closed. | |
data-starting-style | Present when the popup begins animating in. | |
data-ending-style | Present when the popup is animating out. | |
Backdrop.State
type AutocompleteBackdropState = {
/** Whether the popup is currently open. */
open: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
};Positioner
Positions the popup against the trigger.
Renders a <div> element.
disableAnchorTrackingbooleanfalse
booleanalignAlign'center'
AlignalignOffsetUnion0
data object parameter with the following properties: data.anchor: the dimensions of the anchor element with properties width and height.data.positioner: the dimensions of the positioner element with properties width and height.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.number | OffsetFunctionsideSide'bottom'
SidesideOffsetUnion0
data object parameter with the following properties: data.anchor: the dimensions of the anchor element with properties width and height.data.positioner: the dimensions of the positioner element with properties width and height.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.number | OffsetFunctionarrowPaddingnumber5
numberanchorfunction—
Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null) | nullcollisionAvoidanceCollisionAvoidance—
side controls overflow on the preferred placement axis (top/bottom or left/right): 'flip': keep the requested side when it fits; otherwise try the opposite side
(top and bottom, or left and right).'shift': never change side; keep the requested side and move the popup within
the clipping boundary so it stays visible.'none': do not correct side-axis overflow. align controls overflow on the alignment axis (start/center/end): 'flip': keep side, but swap start and end when the requested alignment overflows.'shift': keep side and requested alignment, then nudge the popup along the
alignment axis to fit.'none': do not correct alignment-axis overflow. fallbackAxisSide controls fallback behavior on the perpendicular axis when the
preferred axis cannot fit: 'start': allow perpendicular fallback and try the logical start side first
(top before bottom, or left before right in LTR).'end': allow perpendicular fallback and try the logical end side first
(bottom before top, or right before left in LTR).'none': do not fallback to the perpendicular axis. When side is 'shift', explicitly setting align only supports 'shift' or 'none'.
If align is omitted, it defaults to 'flip'.CollisionAvoidancecollisionBoundaryBoundary'clipping-ancestors'
BoundarycollisionPaddingPadding5
Paddingstickybooleanfalse
booleanpositionMethodUnion'absolute'
position property to use.'absolute' | 'fixed'classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-open-—
-data-closed-—
-data-anchor-hidden-—
-data-alignUnion—
'start' | 'center' | 'end'data-empty-—
-data-sideUnion—
'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Attribute | Description | |
|---|---|---|
data-open | Present when the popup is open. | |
data-closed | Present when the popup is closed. | |
data-anchor-hidden | Present when the anchor is hidden. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-empty | Present when the items list is empty. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
CSS variables
--anchor-heightnumber—
number--anchor-widthnumber—
number--available-heightnumber—
number--available-widthnumber—
number--transform-originstring—
stringCSS Variable | Description | |
|---|---|---|
--anchor-height | The anchor’s height. | |
--anchor-width | The anchor’s width. | |
--available-height | The available height between the trigger and the edge of the viewport. | |
--available-width | The available width between the trigger and the edge of the viewport. | |
--transform-origin | The coordinates that this element is anchored to. Used for animations and transitions. | |
Positioner.State
type AutocompletePositionerState = {
/** Whether the popup is currently open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: Side;
/** The alignment of the component relative to the anchor. */
align: Align;
/** Whether the anchor element is hidden. */
anchorHidden: boolean;
/** Whether there are no items to display. */
empty: boolean;
};Popup
A container for the list.
Renders a <div> element.
initialFocusfunction—
false: Do not move focus.true: Move focus based on the default behavior (first tabbable element or popup).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse, touch, pen, or keyboard).
Return an element to focus, true to use the default behavior, or false/undefined to do nothing.boolean | RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | void | HTMLElement | null)finalFocusfunction—
false: Do not move focus.true: Move focus based on the default behavior (trigger or previously focused element).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse, touch, pen, or keyboard).
Return an element to focus, true to use the default behavior, or false/undefined to do nothing.boolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-open-—
-data-closed-—
-data-anchor-hidden-—
-data-alignUnion—
'start' | 'center' | 'end'data-empty-—
-data-sideUnion—
'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'data-starting-style-—
-data-ending-style-—
-Attribute | Description | |
|---|---|---|
data-open | Present when the popup is open. | |
data-closed | Present when the popup is closed. | |
data-anchor-hidden | Present when the anchor is hidden. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-empty | Present when the items list is empty. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
data-starting-style | Present when the popup begins animating in. | |
data-ending-style | Present when the popup is animating out. | |
Popup.State
type AutocompletePopupState = {
/** Whether the component is open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: Side;
/** The alignment of the component relative to the anchor. */
align: Align;
/** Whether the anchor element is hidden. */
anchorHidden: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
/** Whether there are no items to display. */
empty: boolean;
};Arrow
Displays an element positioned against the anchor.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-open-—
-data-closed-—
-data-uncentered-—
-data-alignUnion—
'start' | 'center' | 'end'data-sideUnion—
'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Attribute | Description | |
|---|---|---|
data-open | Present when the popup is open. | |
data-closed | Present when the popup is closed. | |
data-uncentered | Present when the arrow is uncentered. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
Arrow.State
type AutocompleteArrowState = {
/** Whether the popup is currently open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: Side;
/** The alignment of the component relative to the anchor. */
align: Align;
/** Whether the arrow cannot be centered on the anchor. */
uncentered: boolean;
};Status
Displays a status message whose content changes are announced politely to screen readers.
Useful for conveying the status of an asynchronously loaded list.
This component’s root element must remain mounted in the DOM to announce
changes consistently across screen readers. Avoid hiding or removing the
component itself with display: none, hidden, aria-hidden, or conditional
rendering. Prefer updating or conditionally rendering its children instead.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Status.State
type AutocompleteStatusState = {};Empty
Renders its children only when the list is empty.
Requires the items prop on the root component.
Announces changes politely to screen readers.
This component’s root element must remain mounted in the DOM to announce
changes consistently across screen readers. Avoid hiding or removing the
component itself with display: none, hidden, aria-hidden, or conditional
rendering. Prefer updating or conditionally rendering its children instead.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Empty.State
type AutocompleteEmptyState = {};Collection
Renders filtered list items.
Doesn’t render its own HTML element.
If rendering a flat list, pass a function child to the List component instead, which implicitly wraps it.
children\*function—
((item: any, index: number) => JSX.Element)Collection.State
type AutocompleteCollectionState = {};Row
Displays a single row of items in a grid list.
Enable grid on the root component to turn the listbox into a grid.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Row.State
type AutocompleteRowState = {};Item
An individual item in the list.
Renders a <div> element.
valueanynull
anyonClickfunction—
Enter with the keyboard if the item is highlighted when the Input or List element has focus.((event: BaseUIEvent<MouseEvent>) => void)indexnumber—
numbernativeButtonbooleanfalse
<button> element when replacing it
via the render prop.
Set to true if the rendered element is a native button.booleandisabledbooleanfalse
booleanchildrenJSX.Element—
JSX.Elementclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-highlighted-—
-data-disabled-—
-Attribute | Description | |
|---|---|---|
data-highlighted | Present when the item is highlighted. | |
data-disabled | Present when the item is disabled. | |
Item.State
type AutocompleteItemState = {
/** Whether the item should ignore user interaction. */
disabled: boolean;
/** Whether the item is highlighted. */
highlighted: boolean;
};Group
Groups related items with the corresponding label.
Renders a <div> element.
itemsany[]—
Collection components will use these items.any[]classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Group.State
type AutocompleteGroupState = {};GroupLabel
An accessible label that is automatically associated with its parent group.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)GroupLabel.State
type AutocompleteGroupLabelState = {};Separator
A visual separator between items or groups.
Renders a <div> element.
orientationOrientation'horizontal'
Orientationclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-orientationUnion—
'horizontal' | 'vertical'Attribute | Description | |
|---|---|---|
data-orientation | Indicates the orientation of the separator. | |
Separator.State
type AutocompleteSeparatorState = {
/** The orientation of the separator. */
orientation: Orientation;
};useFilter
Matches items against a query using Intl.Collator for robust string matching.
This hook is used when externally filtering items.
Matches items against a query using Intl.Collator for robust string matching.
optionsAutocompleteFilterOptions{}
AutocompleteFilterOptionsuseFilter
type ReturnValue = AutocompleteFilter;
useFilteredItems
Returns the internally filtered items when called inside <Autocomplete.Root>.
Returns the internally filtered items. Treat the result as read-only: it is internal state and may be a shared frozen array. Solid returns an accessor; call it in a reactive scope to read the current items.
useFilteredItems
type ReturnValue = Accessor<T[]>;