Aurora Combobox
aurora-dinglebear-ai/aurora-comboboxUnverifiedComponent
Searchable selection control for large option sets like gateways, models, branches, and files.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/dinglebear-ai/aurora/main/aurora-combobox.jsonSource
1"use client"23import * as React from "react"4import { Check, ChevronsUpDown, Search } from "lucide-react"5import { cn } from "@/lib/utils"6import { Button } from "./button"7import { Input } from "./input"8import { Listbox } from "./listbox"9import { isNavigationKey, nextEnabledIndex } from "@/registry/aurora/lib/widget-interactions"1011export interface ComboboxOption {12 value: string13 label: string14 description?: string15}1617export interface ComboboxProps {18 options: ComboboxOption[]19 value?: string20 defaultValue?: string21 onValueChange?: (value: string) => void22 /** Trigger label shown when nothing is selected. */23 placeholder?: string24 /** Placeholder for the in-dropdown search field. */25 searchPlaceholder?: string26 emptyMessage?: string27 /** Render the dropdown open on first paint (uncontrolled). */28 defaultOpen?: boolean29 className?: string30}3132function Combobox({ options, value, defaultValue, onValueChange, placeholder = "Search...", searchPlaceholder = "Search...", emptyMessage = "No results found.", defaultOpen = false, className }: ComboboxProps) {33 const controlled = value !== undefined34 const [internalValue, setInternalValue] = React.useState(defaultValue ?? "")35 const [query, setQuery] = React.useState("")36 const [open, setOpen] = React.useState(defaultOpen)37 const [activeIndex, setActiveIndex] = React.useState(-1)38 const current = controlled ? value : internalValue39 const selected = options.find((option) => option.value === current)40 const filtered = options.filter((option) => `${option.label} ${option.description ?? ""}`.toLowerCase().includes(query.toLowerCase()))41 const containerRef = React.useRef<HTMLDivElement>(null)42 const triggerRef = React.useRef<HTMLButtonElement>(null)43 const inputRef = React.useRef<HTMLInputElement>(null)44 const listboxId = React.useId()4546 const close = React.useCallback((restoreFocus = false) => {47 // Move focus before unmounting the popup. Deferring this until the next48 // animation frame lets the focused input disappear first, which briefly49 // drops focus to <body> and breaks the combobox focus-return contract.50 if (restoreFocus) triggerRef.current?.focus()51 setOpen(false)52 setQuery("")53 setActiveIndex(-1)54 }, [])5556 const openAt = React.useCallback((edge: "first" | "last" = "first") => {57 setOpen(true)58 const index = edge === "first" ? 0 : Math.max(0, filtered.length - 1)59 setActiveIndex(filtered.length > 0 ? index : -1)60// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from aurora
All 176 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Aurora Accordionaurora-accordion | aurora | Components | Unverified | 2 deps | |
| Aurora Alert Dialogaurora-alert-dialog | aurora | Components | Unverified | 2 deps | |
| Aurora Aspect Ratioaurora-aspect-ratio | aurora | Components | Unverified | no deps | |
| Aurora Avataraurora-avatar | aurora | Components | Unverified | 1 dep | |
| Aurora Badgeaurora-badge | aurora | Components | Unverified | 2 deps | |
| Aurora Banneraurora-banner | aurora | Components | Unverified | 1 dep | |
| Aurora Breadcrumbaurora-breadcrumb | aurora | Components | Unverified | 2 deps | |
| Aurora Buttonaurora-button | aurora | Components | Unverified | 2 deps |
