Combobox
nexvyn/comboboxFreeComponent
A filterable select with live search, proximity highlight, and native select mirror for forms.
Live preview
live · rendered by the registry
Rendered by nexvyn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.nexvyn.dev/r/combobox.jsonSource
1'use client'23import {4 createContext,5 forwardRef,6 useCallback,7 useContext,8 useEffect,9 useId,10 useMemo,11 useRef,12 useState,13 type HTMLAttributes,14 type ReactNode,15} from 'react'16import { createPortal } from 'react-dom'17import { type MotionValue } from 'motion/react'18import { cn } from '@/lib/utils'19import { useProximityHighlight, ProximityHighlight } from '@/lib/hooks/use-proximity-highlight'20import { matchesSearch, buildSearchableText } from '@/lib/search-match'2122export interface ComboboxOption {23 value: string24 label: string25 description?: string26}2728interface ComboboxContextValue {29 value: string30 setValue: (v: string) => void31 open: boolean32 setOpen: (next: boolean) => void33 query: string34 setQuery: (q: string) => void35 disabled: boolean36 triggerId: string37 contentId: string38 nextIndex: () => number39 labelMap: React.MutableRefObject<Map<string, string>>40 registerOption: (value: string, label: string) => void41 options: ComboboxOption[]42 placeholder: string43 emptyMessage: string44 clearable: boolean45 openOnFocus: boolean46 setValueRef: React.MutableRefObject<(v: string) => void>47 activeDescendantId: string | null48 setActiveDescendantId: (id: string | null) => void49 suppressNextFocusOpenRef: React.MutableRefObject<boolean>50}5152const ComboboxContext = createContext<ComboboxContextValue | null>(null)5354function useComboboxCtx(componentName: string) {55 const ctx = useContext(ComboboxContext)56 if (!ctx) throw new Error(`${componentName} must be used within Combobox`)57 return ctx58}5960interface ComboboxContentContextValue {61 activeIndex: number | null62 setActiveIndex: (i: number | null) => void63 highlightX: ReturnType<typeof import('motion/react').useSpring>64 highlightSize: MotionValue<number>65 highlightOpacity: ReturnType<typeof import('motion/react').useSpring>66 axis: 'x' | 'y'67 registerItem: (index: number, el: HTMLElement | null) => void68 filteredOptions: ComboboxOption[]69 setValueRef: React.MutableRefObject<(v: string) => void>70}7172const ComboboxContentContext = createContext<ComboboxContentContextValue | null>(null)7374function useComboboxContentCtx(componentName: string) {75 const ctx = useContext(ComboboxContentContext)76 if (!ctx) throw new Error(`${componentName} must be used within ComboboxContent`)77 return ctx78}7980export interface ComboboxProps {81 children: ReactNode82 options: ComboboxOption[]83 value?: string84 defaultValue?: string85 onValueChange?: (value: string) => void86 placeholder?: string87// … truncated
What it pulls in
npm packages
Files it writes
More from nexvyn
All 40 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | nexvyn | Components | Free | 1 dep | |
| Action Buttonaction-button | nexvyn | Components | Free | 3 deps · 4 files | |
| Adaptive Actionsadaptive-actions | nexvyn | Components | Free | 1 dep | |
| AI Inputai-input | nexvyn | Components | Free | 1 dep · 2 files | |
| Badgebadge | nexvyn | Components | Free | 2 deps · 2 files | |
| Bars Themebars-theme | nexvyn | Components | Free | 1 dep · 3 files | |
| Bounce Sidebarbounce-sidebar | nexvyn | Components | Free | 1 dep · 2 files | |
| Breadcrumbsbreadcrumbs | nexvyn | Components | Free | 1 dep · 2 files |
