Documentation menu
Getting Started
Components
Primitives
- Agent Thinking
- Alert
- Alert Dialog
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Checkbox
- Command
- Command Palette
- Context Menu
- Data Table
- Dialog
- Dropdown Menu
- Empty
- Field
- Glow Cloud
- Input
- Label
- Medication Schedule
- Period Tabs
- Popover
- Rainbow Button
- Scroll Area
- Select
- Selectable Card
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Tag
- Textarea
- Timeline
- Tooltip
- Use Count Up
Charts and metrics
Patterns
- Confirm Button
- Date Picker
- Embedded
- Empty State
- Entity Drawer
- Error Boundary
- Field Row
- File Dropzone
- Form Dialog
- Kv
- List Editor
- List Page
- Live Time
- Mini Table
- Money
- Note Field
- Note Text
- Page Card
- Page Header
- Page Tabs
- Page Toolbar
- Person Cell
- Picture Field
- Print Card
- Range Switcher
- Row Actions
- Search Input
- Search Select
- Selected Box
- Signature Pad
- Status Badge
- Sub Nav Layout
- Suggest Input
- Tab Icons
- Table Footer
- Theme Accent Picker
- Time Picker
- View All Link
Dashboard cards
Advanced
Device frames
Website widgets
Website screens
Website panels
Patterns
Search Select
A searchable picker for long lists, grouped, with keyboard support.
import { useState } from "react"
import { SearchSelect } from "@/registry/vcare/ui/search-select"
const items = [
{ id: "cbc", label: "Complete blood count", group: "Haematology", trailing: "₹350" },
{ id: "esr", label: "ESR", group: "Haematology", trailing: "₹120" },
{ id: "lipid", label: "Lipid profile", group: "Biochemistry", trailing: "₹600" },
{ id: "hba1c", label: "HbA1c", group: "Biochemistry", trailing: "₹450" },
{ id: "tsh", label: "TSH", group: "Hormones", trailing: "₹300" },
]
export default function SearchSelectDemo() {
const [value, setValue] = useState("")
return <SearchSelect className="w-72" items={items} value={value} onChange={setValue} placeholder="Pick a test" title="Tests" />
}Installation
npx shadcn@latest add @vcare/search-selectOr install directly from the URL: https://ui.vcarehms.com/r/search-select.json
- Install the dependencies:
npm i lucide-react - Add the registry items it uses: command-palette, utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/search-select.tsx
import { useState, type ReactNode } from 'react';
import { ChevronsUpDown, Search } from 'lucide-react';
import { CommandPalette, type CommandPaletteGroup } from '@/registry/vcare/ui/command-palette';
import { cn } from '@/registry/vcare/lib/utils';
export interface SearchItem {
id: string;
label: string;
description?: string;
group?: string;
keywords?: string[];
media?: ReactNode;
trailing?: ReactNode;
}
/** A command-palette picker for long lists: search, arrow keys, Enter. Items can be grouped. */
export function SearchPickDialog({
open,
onOpenChange,
items,
onPick,
title,
placeholder,
emptyLabel,
footer,
onSearch,
}: {
onSearch?: (q: string) => void;
open: boolean;
onOpenChange: (o: boolean) => void;
items: SearchItem[];
onPick: (id: string) => void;
title: string;
placeholder?: string;
emptyLabel?: string;
footer?: ReactNode;
}) {
const groups: CommandPaletteGroup[] = [];
for (const it of items) {
const heading = it.group;
let g = groups.find((x) => x.heading === heading);
if (!g) {
g = { heading, items: [] };
groups.push(g);
}
g.items.push({
id: it.id,
label: it.label,
description: it.description,
keywords: it.keywords,
media: it.media,
trailing: it.trailing,
});
}
return (
<CommandPalette
open={open}
onOpenChange={onOpenChange}
groups={groups}
size="wide"
density="compact"
title={title}
description={title}
placeholder={placeholder ?? title}
emptyLabel={emptyLabel}
footer={footer === undefined ? undefined : (footer as never)}
onSearch={onSearch}
onSelect={(i) => {
onPick(i.id);
onOpenChange(false);
}}
/>
);
}
/** Select-like button that opens the searchable list. */
export function SearchSelect({
items,
value,
onChange,
placeholder,
title,
emptyLabel,
className,
disabled,
}: {
items: SearchItem[];
value: string;
onChange: (id: string) => void;
placeholder: string;
title?: string;
emptyLabel?: string;
className?: string;
disabled?: boolean;
}) {
const [open, setOpen] = useState(false);
const chosen = items.find((i) => i.id === value);
return (
<>
<button
type="button"
disabled={disabled}
onClick={() => setOpen(true)}
className={cn(
'flex h-control w-full items-center justify-between gap-2 rounded-lg border bg-background px-3 text-start text-sm transition-colors hover:bg-muted/50 disabled:opacity-50',
!chosen && 'text-muted-foreground',
className,
)}
>
<span className="flex min-w-0 items-center gap-2">
<Search className="size-3.5 shrink-0 opacity-60" />
<span className="truncate">{chosen?.label ?? placeholder}</span>
</span>
<ChevronsUpDown className="size-3.5 shrink-0 opacity-50" />
</button>
<SearchPickDialog
open={open}
onOpenChange={setOpen}
items={items}
onPick={onChange}
title={title ?? placeholder}
placeholder={placeholder}
emptyLabel={emptyLabel}
/>
</>
);
}Usage
import { SearchPickDialog, SearchSelect } from "@/components/ui/search-select"Exports
SearchPickDialog, SearchSelect
Dependencies
lucide-react@^1.80.0(npm)@vcare/command-palette(registry)@vcare/utils(registry)
Raw item: /r/search-select.json