Combobox
Searchable single-select with input and floating option list.
Examples
Leading addon
Wrap ComboboxInput in ComboboxInputGroup to put an icon or prefix before the text. The group draws the field surface, the trigger moves to a trailing addon, and pressing an addon focuses the input.
Composition
Searchable list
ComboboxInput includes its trigger by default.
- <Combobox>
- <ComboboxInput />
- <ComboboxContent>
- <ComboboxEmpty />
- <ComboboxList>
- <ComboboxGroup>
- <ComboboxGroupLabel />
- <ComboboxItem />
- <ComboboxGroup>
Leading addon
Inside ComboboxInputGroup, ComboboxInput drops its own field surface and moves its trigger to a trailing addon; the popup still aligns to the whole group.
- <Combobox>
- <ComboboxInputGroup>
- <InputGroupAddon />
- <ComboboxInput />
- <ComboboxContent>
- <ComboboxList>
- <ComboboxItem />
- <ComboboxList>
- <ComboboxInputGroup>
Standalone trigger
- <Combobox>
- <ComboboxTrigger />
- <ComboboxContent>
- <ComboboxList>
- <ComboboxItem />
- <ComboboxList>
Installation
The Control UI source installs this component from src/registry/sources/control-ui/ui/combobox.tsx.
npx shadcn@latest add https://control-ui.dev/r/combobox.jsonDependencies
src/registry/sources/control-ui/ui/combobox-disabled-selection.ts
src/registry/lib/listbox-name.ts
src/registry/lib/popup-item-focus.ts
src/registry/sources/control-ui/surface-variants.ts
src/registry/sources/control-ui/control-variants.ts
input-group
scroll-area
Raw code
Primary installed source
"use client";
import { Combobox as ComboboxPrimitive } from "@base-ui/react/combobox";import { mergeProps } from "@base-ui/react/merge-props";import type { ComponentProps, CSSProperties, ReactNode } from "react";import { createContext, use, useEffect, useState } from "react";import type { ControlSize } from "@/components/control-ui/control-variants";import type { FieldKnobStyle } from "@/components/control-ui/knob-contracts/field-knobs";import type { PopupKnobStyle } from "@/components/control-ui/knob-contracts/popup-knobs";import { cn } from "@/components/control-ui/lib/cn";import { listboxNameRef } from "@/components/control-ui/lib/listbox-name";import { popupItemFocusProps } from "@/components/control-ui/lib/popup-item-focus";import { type SkinIconProps, skinScopeAttributes } from "@/components/control-ui/skin";import { useSkin, useSkinIcon } from "@/components/control-ui/skin-provider";import { popupItemStructureClasses } from "@/components/control-ui/surface-variants";import { InputGroup, InputGroupAddon, type InputGroupProps, useInputGroupControlRef, useIsInsideInputGroup,} from "@/components/control-ui/ui/input-group";import { ScrollArea } from "@/components/control-ui/ui/scroll-area";import { shouldAcceptComboboxValueChange } from "./combobox-disabled-selection";
export type ComboboxProps<Value = string, Multiple extends boolean | undefined = false> = Pick< ComboboxPrimitive.Root.Props<Value, Multiple>, | "children" | "multiple" | "value" | "defaultValue" | "onValueChange" | "inputValue" | "defaultInputValue" | "onInputValueChange" | "open" | "defaultOpen" | "onOpenChange" | "disabled" | "readOnly" | "required" | "name" | "form" | "autoHighlight" | "itemToStringLabel" | "itemToStringValue" | "isItemEqualToValue" | "onItemHighlighted" | "openOnInputClick" | "filter" | "limit" | "virtualized" | "modal"> & { items?: readonly Value[] };
export type ComboboxInputProps = Omit<Omit<ComponentProps<"input">, "size">, "style"> & { style?: CSSProperties & FieldKnobStyle } & { size?: ControlSize; /** Accessible name of the built-in trigger button. */ triggerLabel?: string;};
export type ComboboxInputGroupProps = Omit<InputGroupProps, "render">;
export type ComboboxTriggerProps = ComponentProps<"button"> & { style?: CSSProperties & FieldKnobStyle };
export type ComboboxContentProps = Omit< ComboboxPrimitive.Popup.Props & Pick< ComboboxPrimitive.Positioner.Props, "side" | "sideOffset" | "align" | "alignOffset" | "anchor" | "collisionBoundary" | "collisionPadding" >, "style"> & { style?: CSSProperties & PopupKnobStyle };
export type ComboboxListProps<Value = unknown> = Omit<ComponentProps<"div">, "children"> & { children?: ReactNode | ((item: Value, index: number) => ReactNode);} & { style?: CSSProperties & PopupKnobStyle };
export type ComboboxItemProps<Value = unknown> = Omit< Omit<ComponentProps<"div">, "value"> & { value?: Value; disabled?: boolean; }, "style"> & { style?: CSSProperties & PopupKnobStyle };
export type ComboboxEmptyProps = Omit<ComponentProps<"div">, "style"> & { style?: CSSProperties & FieldKnobStyle & PopupKnobStyle };
export type ComboboxGroupProps = ComponentProps<"div"> & { style?: CSSProperties & FieldKnobStyle };
export type ComboboxGroupLabelProps = Omit<ComponentProps<"div">, "style"> & { style?: CSSProperties & PopupKnobStyle };
type DisabledComboboxValueRegistry = { register: (value: unknown, disabled: boolean) => () => void;};
const ComboboxDisabledValueContext = createContext<DisabledComboboxValueRegistry | null>(null);
export function Combobox<Value = string, Multiple extends boolean | undefined = false>({ children, onValueChange, autoHighlight = true, ...props}: ComboboxProps<Value, Multiple>) { const [disabledValues] = useState(() => new Set<unknown>()); const [committedValue, setCommittedValue] = useState<unknown>(() => props.value ?? props.defaultValue ?? null); const [disabledValueRegistry] = useState<DisabledComboboxValueRegistry>(() => ({ register(value, disabled) { if (!disabled || value === undefined) return () => {}; disabledValues.add(value); return () => disabledValues.delete(value); }, }));
return ( <ComboboxDisabledValueContext.Provider value={disabledValueRegistry}> <ComboboxPrimitive.Root autoHighlight={autoHighlight} {...props} onValueChange={(value, eventDetails) => { const previousValue = props.value === undefined ? committedValue : props.value; if (!shouldAcceptComboboxValueChange(value, previousValue, disabledValues)) { eventDetails.cancel(); return; } setCommittedValue(value); onValueChange?.(value, eventDetails); }} > {children} </ComboboxPrimitive.Root> </ComboboxDisabledValueContext.Provider> );}
function ComboboxChevronIcon(props: SkinIconProps) { return ( <svg viewBox="0 0 12 12" fill="none" aria-hidden="true" {...props}> <path d="M3 4.5 6 7.5 9 4.5" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round" /> </svg> );}
export function ComboboxTrigger({ className, children, "aria-label": ariaLabel = "Toggle suggestions", ...props }: ComboboxTriggerProps) { const ChevronDownGlyph = useSkinIcon("chevronDown", ComboboxChevronIcon); return ( <ComboboxPrimitive.Trigger data-control-ui="combobox" data-control-family="field" data-field-kind="combobox" data-slot="trigger" aria-label={ariaLabel} className={cn("group inline-flex size-6 shrink-0 items-center justify-center", className)} {...props} > {children ?? ( <ComboboxPrimitive.Icon data-control-ui="combobox" data-control-family="field" data-field-kind="combobox" data-slot="icon"> <ChevronDownGlyph aria-hidden="true" /> </ComboboxPrimitive.Icon> )} </ComboboxPrimitive.Trigger> );}
export function ComboboxInputGroup(props: ComboboxInputGroupProps) { return <InputGroup {...props} render={<ComboboxPrimitive.InputGroup />} />;}
export function ComboboxInput({ ref, size = "md", className, triggerLabel, ...props }: ComboboxInputProps) { const groupControlRef = useInputGroupControlRef(ref); if (useIsInsideInputGroup()) { return ( <> <ComboboxPrimitive.Input {...props} ref={groupControlRef} data-control-ui="input-group" data-control-family="field" data-field-kind="input-group" data-slot="input" className={cn("h-full min-w-0 flex-1", className)} /> <InputGroupAddon> <ComboboxTrigger aria-label={triggerLabel} /> </InputGroupAddon> </> ); } return ( <ComboboxPrimitive.InputGroup data-control-ui="combobox" data-control-family="field" data-field-kind="combobox" data-slot="input-group" className="relative flex w-full items-center" > <ComboboxPrimitive.Input ref={ref} data-control-ui="combobox" data-field-kind="combobox" data-slot="input" data-control="true" data-control-family="field" data-size={size} className={cn("w-full min-w-0", className)} {...props} /> <ComboboxTrigger aria-label={triggerLabel} className="absolute end-1.5 top-1/2 -translate-y-1/2" /> </ComboboxPrimitive.InputGroup> );}
const comboboxContentClasses = "w-[var(--anchor-width)]";
export function ComboboxContent({ className, children, side = "bottom", sideOffset = 6, align = "start", alignOffset, anchor, collisionBoundary, collisionPadding, ...props}: ComboboxContentProps) { const skin = useSkin(); return ( <ComboboxPrimitive.Portal> <ComboboxPrimitive.Positioner data-control-ui="combobox" data-popup-kind="combobox" data-control-family="popup" data-slot="positioner" {...skinScopeAttributes(skin)} side={side} align={align} sideOffset={sideOffset} alignOffset={alignOffset} anchor={anchor} collisionBoundary={collisionBoundary} collisionPadding={collisionPadding} className="z-(--z-popup)" > <ComboboxPrimitive.Popup data-control-ui="combobox" data-popup-kind="combobox" data-control-family="popup" data-slot="content" data-surface="floating" data-popup-part="list-surface" className={ typeof className === "function" ? (state) => cn(comboboxContentClasses, className(state)) : cn(comboboxContentClasses, className) } {...props} > {children} </ComboboxPrimitive.Popup> </ComboboxPrimitive.Positioner> </ComboboxPrimitive.Portal> );}
export function ComboboxList<Value = unknown>({ className, children, ref, ...props }: ComboboxListProps<Value>) { const listRef = listboxNameRef(ref); return ( <ScrollArea className="w-full" viewportClassName="overscroll-y-contain" maxHeight="min(var(--cui-popup-list-max-height), var(--available-height))" lockAxis="x" > <ComboboxPrimitive.List data-control-ui="combobox" data-popup-kind="combobox" data-slot="list" data-control-family="popup" data-popup-part="list-content" className={className} {...props} ref={listRef} > {children} </ComboboxPrimitive.List> </ScrollArea> );}
export function ComboboxEmpty({ className, children, ...props }: ComboboxEmptyProps) { return ( <ComboboxPrimitive.Empty data-control-ui="combobox" data-control-family="popup" data-popup-kind="combobox" data-slot="empty" className={cn("empty:h-0 empty:overflow-hidden empty:p-0", className)} {...props} > {children} </ComboboxPrimitive.Empty> );}
function ComboboxCheckIcon(props: SkinIconProps) { return ( <svg viewBox="0 0 12 12" fill="none" aria-hidden="true" {...props}> <path d="M2.5 6.5 5 9l4.5-5" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round" /> </svg> );}
export function ComboboxItem<Value = unknown>({ className, children, disabled, value, ...props }: ComboboxItemProps<Value>) { const disabledValueRegistry = use(ComboboxDisabledValueContext); const CheckGlyph = useSkinIcon("check", ComboboxCheckIcon);
useEffect(() => disabledValueRegistry?.register(value, Boolean(disabled)), [disabled, disabledValueRegistry, value]);
return ( <ComboboxPrimitive.Item data-control-ui="combobox" data-popup-kind="combobox" data-control-family="popup" data-slot="item" data-popup-part="item" data-disabled={disabled ? "true" : undefined} aria-disabled={disabled || undefined} disabled={disabled} value={value} className={cn(popupItemStructureClasses, className)} {...mergeProps(popupItemFocusProps, props)} > <span data-control-ui="combobox" data-control-family="popup" data-popup-kind="combobox" data-slot="item-text" className="flex min-w-0 flex-1 items-center truncate" > {children} </span> <span data-control-ui="combobox" data-popup-kind="combobox" data-control-family="popup" data-slot="item-indicator" className="flex shrink-0 items-center justify-center" > <ComboboxPrimitive.ItemIndicator> <CheckGlyph aria-hidden="true" /> </ComboboxPrimitive.ItemIndicator> </span> </ComboboxPrimitive.Item> );}
export function ComboboxGroup({ className, children, ...props }: ComboboxGroupProps) { return ( <ComboboxPrimitive.Group data-control-ui="combobox" data-control-family="field" data-field-kind="combobox" data-slot="group" className={className} {...props} > {children} </ComboboxPrimitive.Group> );}
export function ComboboxGroupLabel({ className, children, ...props }: ComboboxGroupLabelProps) { return ( <ComboboxPrimitive.GroupLabel data-control-ui="combobox" data-popup-kind="combobox" data-slot="group-label" data-control-family="popup" data-popup-part="label" className={className} {...props} > {children} </ComboboxPrimitive.GroupLabel> );}
Knobs
Typed custom properties the recipe paints with. Set one on the root — style, a utility class, or a skin — and every slot inherits it.
| Knob | Syntax | Default |
|---|---|---|
--cui-field-label-radius | <length-percentage> | var(--radius-control) |
--cui-field-label-background | <color> | transparent |
--cui-field-label-hover-background | <color> | var(--hover-fill) |
--cui-field-label-checked-background | <color> | oklch(from var(--primary) l c h / 0.06) |
--cui-field-label-border-color | <color> | var(--border) |
--cui-field-label-checked-border-color | <color> | var(--primary) |
--cui-field-label-border-width | <length> | var(--control-rim-width) |
--cui-field-label-padding-block | <length-percentage> | calc(var(--spacing) * 3) |
--cui-field-label-padding-inline | <length-percentage> | calc(var(--spacing) * 3) |
--cui-field-legend-foreground | <color> | var(--foreground) |
--cui-field-legend-font-size | <length-percentage> | var(--text-label) |
--cui-field-legend-font-weight | <number> | var(--font-weight-semibold) |
--cui-field-radius | <length-percentage> | var(--nest-radius, var(--radius-control)) |
--cui-field-background | <color> | var(--control-fill) |
--cui-field-hover-background | <color> | var(--hover-fill) |
--cui-field-affordance-background | <color> | transparent |
--cui-field-affordance-shadow | * | 0 0 transparent |
--cui-field-affordance-foreground | <color> | var(--muted-foreground) |
--cui-field-affordance-hover-background | <color> | var(--hover-fill) |
--cui-field-foreground | <color> | var(--foreground) |
--cui-field-border-color | <color> | var(--control-rim) |
--cui-field-focus-border-color | <color> | var(--focus-rim) |
--cui-field-border-width | <length> | var(--control-rim-width) |
--cui-field-shadow | * | var(--shadow-inset) |
--cui-field-backdrop-filter | * | blur(0px) |
--cui-field-height | <length-percentage> | var(--control-h-md) |
--cui-field-padding-inline | <length-percentage> | var(--padding-x) |
--cui-field-font-size | <length-percentage> | var(--text-body) |
--cui-field-font-weight | <number> | var(--font-weight-normal) |
--cui-field-font-family | * | var(--font-body) |
--cui-field-group-radius | <length-percentage> | var(--radius-panel) |
--cui-field-group-background | <color> | var(--card) |
--cui-field-group-border-color | <color> | var(--border) |
--cui-field-group-border-width | <length> | 1px |
--cui-field-group-shadow | * | 0 0 transparent |
--cui-field-group-padding-block | <length-percentage> | calc(var(--spacing) * 3) |
--cui-field-group-padding-inline | <length-percentage> | calc(var(--spacing) * 4) |
--cui-field-group-separator-color | <color> | var(--border) |
--cui-field-group-separator-inset | <length-percentage> | 0px |
--cui-field-label-font-size | <length-percentage> | var(--text-label) |
--cui-field-label-font-weight | <number> | var(--font-weight-medium) |
--cui-field-description-font-size | <length-percentage> | var(--text-caption) |
| Knob | Syntax | Default |
|---|---|---|
--cui-popup-title-foreground | <color> | var(--cui-popup-foreground) |
--cui-popup-title-font-size | <length-percentage> | var(--text-heading-3) |
--cui-popup-title-font-weight | <number> | var(--font-weight-semibold) |
--cui-popup-title-line-height | <number> | var(--text-heading-3--line-height) |
--cui-popup-title-letter-spacing | <length> | -0.025em |
--cui-popup-description-foreground | <color> | var(--muted-foreground) |
--cui-popup-description-font-size | <length-percentage> | var(--text-body) |
--cui-popup-close-inset | <length-percentage> | calc(var(--spacing) * 3) |
--cui-popup-item-inset | <length-percentage> | calc(var(--spacing) * 8) |
--cui-popup-label-padding-block | <length-percentage> | var(--cui-popup-item-padding-block) |
--cui-popup-label-padding-inline | <length-percentage> | var(--cui-popup-item-padding-inline) |
--cui-popup-label-font-size | <length-percentage> | var(--text-micro) |
--cui-popup-label-font-weight | <number> | var(--font-weight-medium) |
--cui-popup-label-letter-spacing | <length> | 0.08em |
--cui-popup-label-text-transform | none | uppercase | lowercase | capitalize | uppercase |
--cui-popup-separator-inset | <length-percentage> | calc(var(--popover-padding) * -1) |
--cui-popup-shortcut-font-size | <length-percentage> | var(--text-body) |
--cui-popup-shortcut-letter-spacing | <length> | 0.02em |
--cui-popup-separator-gap | <length-percentage> | calc(var(--spacing) * 1) |
--cui-popup-submenu-indicator-foreground | <color> | var(--cui-popup-item-foreground) |
--cui-popup-command-padding | <length-percentage> | 0px |
--cui-popup-command-heading-padding-block | <length-percentage> | calc(var(--spacing) * 1.5) |
--cui-popup-command-heading-padding-inline | <length-percentage> | calc(var(--spacing) * 2) |
--cui-popup-command-heading-font-size | <length-percentage> | var(--text-caption) |
--cui-popup-command-heading-letter-spacing | <length> | calc(var(--cui-popup-command-heading-font-size) * 0.08) |
--cui-popup-command-heading-text-transform | none | uppercase | lowercase | capitalize | uppercase |
--cui-popup-dialog-max-inline-size | <length-percentage> | 32rem |
--cui-popup-list-max-height | <length-percentage> | 20rem |
--cui-popup-item-description-foreground | <color> | var(--muted-foreground) |
--cui-popup-item-description-font-size | <length-percentage> | var(--text-label) |
--cui-popup-shortcut-foreground | <color> | var(--muted-foreground) |
--cui-popup-tooltip-arrow-radius | <length-percentage> | min(var(--radius-sm), 3px) |
--cui-popup-shortcut-highlight-foreground | <color> | var(--cui-popup-item-highlight-foreground) |
--cui-popup-submenu-indicator-highlight-foreground | <color> | var(--cui-popup-item-highlight-foreground) |
--cui-popup-status-success-foreground | <color> | var(--success-text) |
--cui-popup-status-warning-foreground | <color> | var(--warning-text) |
--cui-popup-status-info-foreground | <color> | var(--info-text) |
--cui-popup-status-error-foreground | <color> | var(--destructive) |
--cui-popup-radius | <length-percentage> | var(--radius-popover) |
--cui-popup-background | <color> | var(--popover) |
--cui-popup-foreground | <color> | var(--popover-foreground) |
--cui-popup-border-color | <color> | var(--control-rim) |
--cui-popup-border-width | <length> | var(--control-rim-width) |
--cui-popup-shadow | * | var(--shadow-pop) |
--cui-popup-backdrop-filter | * | blur(var(--backdrop-blur-popover)) |
--cui-popup-backdrop-background | <color> | oklch(from var(--foreground) l c h / var(--overlay-opacity)) |
--cui-popup-backdrop-blur | <length> | var(--backdrop-blur-overlay) |
--cui-popup-item-radius | <length-percentage> | var(--radius-popup-item-fit) |
--cui-popup-item-font-size | <length-percentage> | var(--text-body) |
--cui-popup-item-icon-size | <length-percentage> | 1rem |
--cui-popup-item-padding-block | <length-percentage> | calc(var(--spacing) * 1) |
--cui-popup-item-padding-inline | <length-percentage> | calc(var(--padding-x) * 0.5) |
--cui-popup-item-min-height | <length-percentage> | max(var(--target-min), var(--control-h-xs)) |
--cui-popup-item-highlight-shadow | * | none |
--cui-popup-item-foreground | <color> | var(--foreground) |
--cui-popup-item-highlight-background | <color> | var(--hover-fill) |
--cui-popup-item-highlight-foreground | <color> | var(--cui-popup-item-foreground) |
--cui-popup-item-highlight-muted-foreground | <color> | var(--muted-foreground) |
--cui-popup-item-disabled-opacity | <number> | var(--disabled-opacity) |
--cui-popup-separator-color | <color> | var(--cui-popup-border-color) |