Autocomplete
A wrapper for Base UI Autocomplete with type-to-filter suggestions, grouped items, async search, inline completion mode, and clear/trigger controls.
Installation
npx shadcn@latest add @glrk-ui/autocompleteIf you haven't set up the prerequisites yet, check out registry setup.
Virtualised Installation
AutocompleteVirtualisedWrapper renders large flat lists efficiently using @tanstack/react-virtual. Install separately — grouping is not supported.
npx shadcn@latest add @glrk-ui/autocomplete-virtualUsage
Basic
import { AutocompleteWrapper } from "@/components/ui/autocomplete"
<AutocompleteWrapper
items={["Apple", "Banana", "Orange"]}
placeholder="Search fruits..."
className="w-64"
/>With clear and trigger buttons
<AutocompleteWrapper
items={items}
placeholder="Search..."
showClear
showTrigger
className="w-64"
/>Controlled
const [value, setValue] = useState("")
<AutocompleteWrapper
items={items}
value={value}
onValueChange={setValue}
placeholder="Search..."
showClear
/>Item objects
const frameworks = [
{ value: "next", label: "Next.js" },
{ value: "remix", label: "Remix" },
{ value: "astro", label: "Astro" },
]
<AutocompleteWrapper items={frameworks} placeholder="Select framework..." />Grouped items
const grouped = [
{
group: "Frontend",
items: [
{ value: "react", label: "React" },
{ value: "vue", label: "Vue" },
],
},
{
group: "Backend",
items: [
{ value: "node", label: "Node.js" },
{ value: "go", label: "Go" },
],
},
]
<AutocompleteWrapper items={grouped} placeholder="Search tech..." showClear />Limit results
<AutocompleteWrapper items={items} placeholder="Search..." limit={5} />Inline mode
Completes input text inline as the user types:
<AutocompleteWrapper items={items} mode="inline" placeholder="Start typing..." />Custom status and empty slots
Override the default loading/empty UI with renderStatus and renderEmpty:
<AutocompleteWrapper
items={items}
renderStatus={isFetching
? <p className="flex items-center gap-2 p-2 text-sm"><Loader2 className="size-4 animate-spin" /> Fetching...</p>
: null
}
renderEmpty={<p className="py-6 text-center text-sm">Nothing here yet</p>}
/>Async search
Disable client-side filter with filter={null} and supply results externally:
const [inputValue, setInputValue] = useState("")
const [results, setResults] = useState<string[]>([])
const [isFetching, setIsFetching] = useState(false)
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
function handleValueChange(val: string) {
setInputValue(val)
if (timerRef.current) clearTimeout(timerRef.current)
if (!val.trim()) { setResults([]); return }
setIsFetching(true)
timerRef.current = setTimeout(async () => {
setResults(await fetchSuggestions(val))
setIsFetching(false)
}, 400)
}
<AutocompleteWrapper
items={results}
value={inputValue}
onValueChange={handleValueChange}
filter={null}
placeholder="Search..."
showClear
renderStatus={isFetching
? <p className="flex items-center gap-2 p-2 text-sm"><Loader2 className="size-4 animate-spin" /> Fetching...</p>
: null
}
renderEmpty={<p className="py-6 text-center text-sm">No results found</p>}
/>Virtualised — large lists
Use AutocompleteVirtualisedWrapper for lists with hundreds or thousands of items:
import { AutocompleteVirtualisedWrapper } from "@/components/ui/autocomplete-virtualised"
<AutocompleteVirtualisedWrapper
items={largeList}
placeholder="Search 1000 items…"
className="w-64"
showClear
/>Custom row height and overscan:
<AutocompleteVirtualisedWrapper
items={largeList}
placeholder="Search…"
maxHeight={200}
estimateSize={36}
virtualizerOptions={{ overscan: 10 }}
/>Reference
Prop
Type
Virtualised Reference
AutocompleteVirtualisedWrapper accepts all the same props as AutocompleteWrapper except groupCls. The following props are unique to the virtualised variant:
Prop
Type
Related Components
Combobox
A wrapper for Base UI Combobox with single and multi-select, chips, grouped items, async loading, custom label rendering, and create-new support.
Date Picker
A popover-based date picker wrapping Calendar and Popover. Supports single, range, and multiple selection modes with smart auto-close behavior. Includes a DateTimePicker variant with a scrollable time slot panel.