Glrk UI

Autocomplete

A wrapper for Base UI Autocomplete with type-to-filter suggestions, grouped items, async search, inline completion mode, and clear/trigger controls.

Basic
Default — type to filter
With clear — dismiss input value
With trigger — toggle popup
Items
Grouped — items under labelled sections
Limit — max 5 suggestions shown
Inline mode — completes input text inline
State
Controlled — value + onValueChange
Disabled
Async
Async search — filter=null, results fetched on typing, 400ms debounce
Virtualised
1000 items — virtualised list
1000 items — custom height + overscan

Installation

npx shadcn@latest add @glrk-ui/autocomplete

If 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-virtual

Usage

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>}
/>

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