Combobox
basecn/comboboxFreeComponent
An input combined with a list of predefined items to select.
Live preview
live · rendered by the registry
Rendered by basecn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://basecn.dev/r/combobox.jsonSource
1import { Combobox as ComboboxPrimitive } from "@base-ui/react/combobox";2import { CheckIcon, XIcon } from "lucide-react";34import { cn } from "@/lib/utils";5import { Button } from "@/registry/components/ui/button";6import { Input } from "@/registry/components/ui/input";7import { Separator } from "@/registry/components/ui/separator";8import { RefObject } from "react";910const Combobox = ComboboxPrimitive.Root;1112function ComboboxInput(13 props: ComboboxPrimitive.Input.Props & {14 ref?: RefObject<HTMLInputElement | null>;15 }16) {17 return (18 <ComboboxPrimitive.Input19 data-slot="combobox-input"20 render={<Input />}21 {...props}22 />23 );24}2526function ComboboxTrigger(props: ComboboxPrimitive.Trigger.Props) {27 return (28 <ComboboxPrimitive.Trigger29 data-slot="combobox-trigger"30 render={<Button variant="outline" />}31 {...props}32 />33 );34}3536function ComboboxIcon(props: ComboboxPrimitive.Icon.Props) {37 return <ComboboxPrimitive.Icon data-slot="combobox-icon" {...props} />;38}3940function ComboboxClear({41 children,42 className,43 ...props44}: ComboboxPrimitive.Clear.Props) {45 return (46 <ComboboxPrimitive.Clear47 className={cn(48 "flex h-9 w-6 items-center justify-center rounded bg-transparent p-0",49 className50 )}51 aria-label="Clear selection"52 data-slot="combobox-clear"53 {...props}54 >55 {children ?? <XIcon className="size-4" />}56 </ComboboxPrimitive.Clear>57 );58}5960function ComboboxValue(props: ComboboxPrimitive.Value.Props) {61 return <ComboboxPrimitive.Value data-slot="combobox-value" {...props} />;62}6364function ComboboxChips({65 className,66 ...props67}: ComboboxPrimitive.Chips.Props & { ref?: RefObject<HTMLDivElement | null> }) {68 return (69 <ComboboxPrimitive.Chips70 data-slot="combobox-chips"71 className={cn(72 "min-h-9 flex flex-wrap items-start gap-1 rounded-md border px-1.5 py-1.5 transition-[color,box-shadow]",73 "focus-within:border-ring focus-within:ring-ring/50 focus-within:ring-[3px]",74 className75 )}76 {...props}77 />78 );79}8081function ComboboxChip({ className, ...props }: ComboboxPrimitive.Chip.Props) {82 return (83 <ComboboxPrimitive.Chip84 data-slot="combobox-chip"85 className={cn(86 "flex items-center gap-1 rounded-md bg-muted px-1 ps-2 pe-0 text-xs outline-none cursor-default focus-within:bg-primary focus-within:text-primary-foreground",87 className88 )}89 {...props}90 />91 );92}9394// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from basecn
All 56 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | basecn | Components | Free | 2 deps | |
| Alertalert | basecn | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | basecn | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | basecn | Components | Free | no deps | |
| Autocompleteautocomplete | basecn | Components | Free | 2 deps | |
| Avataravatar | basecn | Components | Free | 1 dep | |
| Badgebadge | basecn | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | basecn | Components | Free | 2 deps |
