Combobox
A wrapper for Base UI Combobox with single and multi-select, chips, grouped items, async loading, custom label rendering, and create-new support.
—Installation
npx shadcn@latest add @glrk-ui/comboboxIf you haven't set up the prerequisites yet, check out registry setup.
Virtualised Installation
ComboboxVirtualisedWrapper renders large flat lists efficiently using @tanstack/react-virtual. Install separately — grouping is not supported.
npx shadcn@latest add @glrk-ui/combobox-virtualUsage
Basic
import { ComboboxWrapper } from "@/components/ui/combobox"
<ComboboxWrapper
items={["Apple", "Banana", "Orange"]}
placeholder="Search fruits..."
/>Multiple selection (chips)
Pass multiple to enable chip-based multi-select:
<ComboboxWrapper
multiple
items={["Apple", "Banana", "Orange"]}
placeholder="Search fruits..."
/>Items format
items accepts primitives, item objects, groups, and separators — mixed freely:
const items = [
"Simple string",
42,
"---", // separator
{ label: "Custom label", value: "custom" },
{ label: <><SunIcon /> Light</>, value: "light" }, // ReactNode label
{ label: "Disabled", value: "off", disabled: true },
{
group: "Category",
items: ["Option A", "Option B"],
},
]
<ComboboxWrapper items={items} placeholder="Pick one" />Grouped items
<ComboboxWrapper
items={[
{ group: "Fruits", items: ["Apple", "Banana"] },
{ group: "Veggies", items: ["Carrot", "Broccoli"] },
]}
placeholder="Select food"
/>Trigger and clear buttons
<ComboboxWrapper items={items} showTrigger showClear placeholder="Search" />
<ComboboxWrapper items={items} showTrigger={false} placeholder="No chevron" />Indicator placement
<ComboboxWrapper items={items} indicatorAt="left" placeholder="Left check" />
<ComboboxWrapper items={items} indicatorAt="right" placeholder="Right check" /> {/* default */}
<ComboboxWrapper items={items} indicatorAt="" placeholder="No indicator" />Disabled item
<ComboboxWrapper
items={[
{ label: "Available", value: "a" },
{ label: "Unavailable", value: "b", disabled: true },
]}
placeholder="Select"
/>Loading state
<ComboboxWrapper items={[]} isLoading placeholder="Search..." />Shows "Loading..." in the empty slot while isLoading is true.
Empty message
<ComboboxWrapper items={items} emptyMessage="Nothing matched" placeholder="Search" />Controlled value
Single:
const [value, setValue] = useState<allowedPrimitiveT>("")
<ComboboxWrapper
items={items}
value={value}
onValueChange={setValue}
/>Multiple:
const [values, setValues] = useState<allowedPrimitiveT[]>([])
<ComboboxWrapper
multiple
items={items}
value={values}
onValueChange={setValues}
/>Controlled query and open state
const [query, setQuery] = useState("")
const [open, setOpen] = useState(false)
<ComboboxWrapper
items={items}
query={query}
onQueryChange={setQuery}
open={open}
onOpenChange={setOpen}
/>Async items
Combine controlled query with async fetch:
const [query, setQuery] = useState("")
const { data: items = [], isLoading } = useQuery({
queryKey: ["users", query],
queryFn: () => fetchUsers(query),
})
<ComboboxWrapper
items={items}
isLoading={isLoading}
query={query}
onQueryChange={setQuery}
placeholder="Search users..."
/>Async search
Disable client filtering with filter={() => true} and update items externally on input change:
const [results, setResults] = useState<string[]>([])
const [isFetching, setIsFetching] = useState(false)
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
function handleInputChange(query: string) {
if (timerRef.current) clearTimeout(timerRef.current)
if (!query.trim()) { setResults([]); return }
setIsFetching(true)
timerRef.current = setTimeout(async () => {
setResults(await fetchOptions(query))
setIsFetching(false)
}, 400)
}
<ComboboxWrapper
items={results}
filter={() => true}
onInputValueChange={handleInputChange}
placeholder="Type to 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>}
/>Custom status and empty slots
Override the default loading/empty UI with renderStatus and renderEmpty:
<ComboboxWrapper
items={items}
isLoading={isLoading}
renderStatus={isLoading ? <MySpinner /> : null}
renderEmpty={<p className="py-6 text-center">Nothing here yet</p>}
/>Custom chip label (renderValue)
Used in multiple mode — controls what renders inside each chip. Receives the raw value string and the matched item:
<ComboboxWrapper
multiple
items={[
{ label: <><SunIcon /> Light</>, value: "light" },
{ label: <><MoonIcon /> Dark</>, value: "dark" },
]}
renderValue={(value, option) => (
<span className="flex items-center gap-1">
{value === "light" ? <SunIcon className="size-3" /> : <MoonIcon className="size-3" />}
{value}
</span>
)}
/>Custom input label (getItemLabel)
Controls the string shown in the input after selection (single mode). Useful when item labels are ReactNodes:
<ComboboxWrapper
items={[
{ label: <><SunIcon /> Light</>, value: "light" },
{ label: <><MoonIcon /> Dark</>, value: "dark" },
]}
getItemLabel={(value) => value === "light" ? "Light mode" : "Dark mode"}
/>Without
getItemLabel, the wrapper usesextractTextto derive a string from ReactNode labels automatically.
Create new item
Use hideList to hide the dropdown list (render your own "Create" item), and wire up onValueChange to extend items:
const [items, setItems] = useState(["Apple", "Banana"])
const [query, setQuery] = useState("")
const hasMatch = items.some(
(i) => String(i).toLowerCase() === query.toLowerCase()
)
<ComboboxWrapper
items={items}
query={query}
onQueryChange={setQuery}
onValueChange={(v) => {
if (!items.includes(v as string)) setItems((prev) => [...prev, v as string])
}}
hideList={hasMatch || !query}
placeholder="Type to create..."
/>Additional input props
Pass native input attributes via inputProps:
<ComboboxWrapper
items={items}
inputProps={{ autoComplete: "off", maxLength: 50 }}
/>Custom styling
<ComboboxWrapper
items={items}
placeholder="Styled"
triggerCls="w-72"
contentCls="max-h-48"
groupCls="pb-0"
itemCls="text-xs"
/>Virtualised — large lists
Use ComboboxVirtualisedWrapper for lists with hundreds or thousands of items:
import { ComboboxVirtualisedWrapper } from "@/components/ui/combobox-virtualised"
<ComboboxVirtualisedWrapper
items={largeList}
placeholder="Search 1000 items…"
triggerCls="w-64"
showClear
/>Custom row height and overscan:
<ComboboxVirtualisedWrapper
items={largeList}
placeholder="Search…"
maxHeight={200}
estimateSize={36}
virtualizerOptions={{ overscan: 10 }}
/>Reference
Prop
Type
Virtualised Reference
ComboboxVirtualisedWrapper accepts all the same props as ComboboxWrapper except multiple, hideList, groupCls, and renderValue. The following props are unique to the virtualised variant:
Prop
Type