Search Dialog
A search palette pinned near the top of the screen. You filter the results; it groups them with counts, moves through them with the arrow keys, and opens the active one with Enter.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/search-dialog.jsonCopies Search Dialog and the components it uses (Button, Command, Dialog, Kbd, and Toggle) into your app, installs the packages, and adds the styles. Then import it from @/components/ui/search-dialog. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @hugeicons/core-free-icons @hugeicons/reactAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Add the components it uses: Button, Command, Dialog, Kbd, and Toggle.
Copy and paste the following code into your project.
'use client'; import { Children, Fragment, isValidElement, type ReactElement, type ReactNode, type Ref } from 'react'; import { CloseIcon } from '@/lib/sprout/icons/close-icon'; import { cn } from '@/lib/sprout/classes'; import { Button } from '@/components/ui/button'; import { Kbd } from '@/components/ui/kbd'; import { Toggle } from '@/components/ui/toggle'; import { Command, CommandGroup, CommandInput, CommandItem, CommandList } from '@/components/ui/command'; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogTitle, type DialogContentProps, } from '@/components/ui/dialog'; export interface SearchDialogProps { open: boolean; onOpenChange: (open: boolean) => void; title: string; description: string; className?: string; container?: DialogContentProps['container']; children: ReactNode; } export function SearchDialog({ open, onOpenChange, title, description, className, container, children, }: SearchDialogProps) { return ( <Dialog open={open} onOpenChange={next => onOpenChange(next)}> <DialogContent data-slot="search-dialog" placement="top" showCloseButton={false} container={container} className={cn('sprout-search-dialog', className)} > <DialogTitle className="sprout-command-sr-only">{title}</DialogTitle> <DialogDescription className="sprout-command-sr-only">{description}</DialogDescription> <Command shouldFilter={false} loop label={title} className="sprout-search-command"> {children} </Command> </DialogContent> </Dialog> ); } export interface SearchInputProps { ref?: Ref<HTMLInputElement>; value: string; onValueChange: (value: string) => void; placeholder: string; label: string; closeLabel?: string; } export function SearchInput({ ref, value, onValueChange, placeholder, label, closeLabel = 'Close search', }: SearchInputProps) { return ( <div data-slot="search-input" className="sprout-search-input"> <CommandInput ref={ref} value={value} onValueChange={onValueChange} placeholder={placeholder} aria-label={label} /> <DialogClose render={<Button variant="ghost" size="icon-sm" aria-label={closeLabel} />}> <CloseIcon size="md" aria-hidden="true" /> </DialogClose> </div> ); } export interface SearchFiltersProps { label: string; children: ReactNode; } export function SearchFilters({ label, children }: SearchFiltersProps) { return ( <div data-slot="search-filters" role="group" aria-label={label} className="sprout-search-filters"> {children} </div> ); } export interface SearchFilterProps { pressed: boolean; onPressedChange: (pressed: boolean) => void; icon?: ReactNode; children: ReactNode; } export function SearchFilter({ pressed, onPressedChange, icon, children }: SearchFilterProps) { return ( <Toggle data-slot="search-filter" variant="outline" size="sm" pressed={pressed} onPressedChange={next => onPressedChange(next)} > {icon} {children} </Toggle> ); } export interface SearchListProps { label: string; children: ReactNode; } export function SearchList({ label, children }: SearchListProps) { return ( <CommandList aria-label={label} className="sprout-search-list"> {children} </CommandList> ); } export interface SearchGroupProps { heading: string; count: number; children: ReactNode; } export function SearchGroup({ heading, count, children }: SearchGroupProps) { if (count === 0) return null; return ( <CommandGroup className="sprout-search-group" heading={ <span className="sprout-search-group-heading"> {heading}{' '} <span data-slot="search-group-count" className="sprout-search-group-count"> {count} </span> </span> } > {children} </CommandGroup> ); } export interface SearchItemIconProps { children: ReactNode; } export function SearchItemIcon({ children }: SearchItemIconProps) { return ( <span data-slot="search-item-icon" className="sprout-search-item-icon"> {children} </span> ); } export interface SearchItemProps { value: string; onSelect: () => void; media: ReactNode; title: string; meta?: string | undefined; detail?: string | undefined; trailing?: ReactNode; } export function SearchItem({ value, onSelect, media, title, meta, detail, trailing }: SearchItemProps) { return ( <CommandItem value={value} onSelect={() => onSelect()} className="sprout-search-item"> <span data-slot="search-item-media" className="sprout-search-item-media"> {media} </span> <span className="sprout-search-item-text"> <span className="sprout-search-item-line"> <span data-slot="search-item-title" className="sprout-search-item-title"> {title} </span> {meta && ( <> <span aria-hidden="true" className="sprout-search-item-dot"> · </span> <span data-slot="search-item-meta" className="sprout-search-item-meta"> {meta} </span> </> )} </span> {detail && ( <span data-slot="search-item-detail" className="sprout-search-item-detail"> {detail} </span> )} </span> {trailing && ( <span data-slot="search-item-trailing" className="sprout-search-item-trailing"> {trailing} </span> )} <Kbd variant="outline" aria-hidden="true" className="sprout-search-item-enter"> ↵ </Kbd> </CommandItem> ); } function tiles(media: ReactNode) { const nodes = isValidElement(media) && media.type === Fragment ? (media as ReactElement<{ children?: ReactNode }>).props.children : media; return Children.toArray(nodes).map((node, index) => ( <span key={index} data-slot="search-empty-tile" className="sprout-search-empty-tile"> {node} </span> )); } export interface SearchEmptyProps { media?: ReactNode; title: string; description: string; action?: ReactNode; } export function SearchEmpty({ media, title, description, action }: SearchEmptyProps) { return ( <div data-slot="search-empty" role="status" className="sprout-search-empty"> {media && ( <div aria-hidden="true" className="sprout-search-empty-media"> <span className="sprout-search-empty-tiles">{tiles(media)}</span> </div> )} <div className="sprout-search-empty-text"> <p className="sprout-search-empty-title">{title}</p> <p className="sprout-search-empty-description">{description}</p> </div> {action} </div> ); } export interface SearchFooterProps { children: ReactNode; } export function SearchFooter({ children }: SearchFooterProps) { return ( <footer data-slot="search-footer" className="sprout-search-footer"> {children} </footer> ); } export interface SearchHintProps { keys: string; children: ReactNode; } export function SearchHint({ keys, children }: SearchHintProps) { return ( <span data-slot="search-hint" className="sprout-search-hint"> <Kbd variant="outline">{keys}</Kbd> {children} </span> ); }And the files it imports:
lib/sprout/icons/close-icon.tsxlib/sprout/icons/create-icon.tsx
Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-dialog-content.sprout-search-dialog { --sprout-dialog-padding: 0px; flex-direction: column; gap: 0; padding: 0; display: flex; overflow: hidden; } .sprout-search-command.sprout-command { border-radius: inherit; background: none; flex: 1; min-height: 0; padding: 0; } .sprout-search-input { border-bottom: 1px solid var(--sprout-line); flex-shrink: 0; align-items: center; gap: 4px; height: 48px; padding-inline: 4px 8px; display: flex; } .sprout-search-input > .sprout-command-input-wrapper { flex: 1; min-width: 0; height: 100%; padding: 0; } .sprout-search-input .sprout-command-input-group { background: none; border: 0; border-radius: 0; gap: 10px; height: 100%; padding-inline: 12px 4px; } .sprout-search-input .sprout-command-input { font-size: var(--sprout-text-base); } .sprout-search-filters { border-bottom: 1px solid var(--sprout-line); scrollbar-width: none; flex-shrink: 0; gap: 6px; padding: 8px 12px; display: flex; overflow-x: auto; } .sprout-search-filters::-webkit-scrollbar { display: none; } .sprout-search-dialog .sprout-search-list { height: min(28rem, 60dvh); max-height: none; padding: 0 8px 8px; scroll-padding-block: 8px; } .sprout-search-list > .sprout-command-list-sizer { min-height: 100%; } .sprout-search-group.sprout-command-group { padding: 4px 0 0; overflow: visible; } .sprout-search-group + .sprout-search-group { border-top: 1px dashed var(--sprout-line); margin-top: 4px; } .sprout-search-group > .sprout-command-group-heading { padding: 10px 8px 4px; } .sprout-search-group-heading { align-items: center; gap: 6px; display: flex; } .sprout-search-group-count { background: var(--sprout-hover); font-variant-numeric: tabular-nums; text-align: center; border-radius: 4px; min-width: 8px; padding-inline: 4px; } .sprout-search-item.sprout-command-item { border-radius: calc(var(--sprout-radius-panel) - 4px); overflow-wrap: normal; gap: 10px; min-height: 34px; padding: 6px 12px; font-size: .875rem; } .sprout-search-item > .sprout-command-item-check { display: none; } .sprout-search-item-media, .sprout-search-item-icon { flex-shrink: 0; justify-content: center; align-items: center; width: 20px; height: 20px; display: flex; } .sprout-search-item-icon { color: var(--sprout-muted); width: 18px; height: 20px; } .sprout-search-item-icon svg { width: 18px; height: 18px; } .sprout-search-item-media svg { flex-shrink: 0; } .sprout-search-item-text { flex-direction: column; flex: 1; min-width: 0; display: flex; } .sprout-search-item-line { align-items: baseline; gap: 6px; min-width: 0; display: flex; } .sprout-search-item-title, .sprout-search-item-meta, .sprout-search-item-detail { text-overflow: ellipsis; white-space: nowrap; min-width: 0; overflow: hidden; } .sprout-search-item-title { flex-shrink: 1; font-weight: 500; } .sprout-search-item-dot, .sprout-search-item-meta, .sprout-search-item-detail, .sprout-search-item-trailing { color: var(--sprout-muted); } .sprout-search-item-dot { flex-shrink: 0; } .sprout-search-item-meta { flex-shrink: 0; max-width: 40%; } .sprout-search-item-detail { font-size: var(--sprout-text-xs); line-height: 1rem; } .sprout-search-item-trailing { font-size: var(--sprout-text-xs); white-space: nowrap; flex-shrink: 0; } .sprout-search-item-enter, .sprout-search-item[data-selected] > .sprout-search-item-trailing { display: none; } .sprout-search-item[data-selected] > .sprout-search-item-enter { display: inline-flex; } .sprout-search-empty { box-sizing: border-box; text-align: center; flex-direction: column; flex: 1; justify-content: center; align-items: center; gap: 12px; min-height: 100%; padding: 16px 24px; display: flex; } .sprout-search-empty-media { background-image: linear-gradient(var(--sprout-line) 1px, transparent 1px), linear-gradient(90deg, var(--sprout-line) 1px, transparent 1px); background-size: 16px 16px; justify-content: center; align-items: center; width: 224px; height: 112px; display: flex; mask-image: radial-gradient(closest-side, oklch(0% 0 0) 30%, #0000 100%); } .sprout-search-empty-tiles { align-items: center; display: flex; } .sprout-search-empty-tile { border: 1px solid var(--sprout-line); border-radius: var(--sprout-radius-panel); background: var(--sprout-surface); width: 44px; height: 44px; box-shadow: var(--sprout-shadow-panel); color: var(--sprout-muted); justify-content: center; align-items: center; margin-inline: -4px; display: flex; } .sprout-search-empty-tile:first-child:not(:only-child) { rotate: -8deg; } .sprout-search-empty-tile:last-child:not(:only-child) { rotate: 8deg; } .sprout-search-empty-tile > svg { width: 20px; height: 20px; } .sprout-search-empty-text { flex-direction: column; gap: 4px; max-width: 24rem; display: flex; } .sprout-search-empty-title { font-weight: 600; } .sprout-search-empty-description { color: var(--sprout-muted); text-wrap: pretty; } .sprout-search-empty-title, .sprout-search-empty-description { margin: 0; } .sprout-search-footer { border-top: 1px solid var(--sprout-line); background: color-mix(in oklab, var(--sprout-canvas) 70%, var(--sprout-surface)); height: 44px; color: var(--sprout-muted); font-size: var(--sprout-text-xs); flex-shrink: 0; align-items: center; gap: 16px; padding-inline: 16px; line-height: 1rem; display: none; } .sprout-search-hint { white-space: nowrap; align-items: center; gap: 6px; display: inline-flex; } @media (width >= 40rem) { .sprout-dialog-content.sprout-search-dialog { max-width: 42rem; } .sprout-search-footer { display: flex; } } }Import it from
@/components/ui/search-dialog. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/search-dialog.
Jump to a page or action
The workspace palette: Recent, Pages, and Quick actions groups with icon tiles, a Clear search recovery, and footer hints. ⌘K or Ctrl+K toggles it.
Nothing opened yet
Usage
import {
SearchDialog,
SearchEmpty,
SearchFooter,
SearchGroup,
SearchHint,
SearchInput,
SearchItem,
SearchItemIcon,
SearchList,
} from "@tulipfarm/sprout/search-dialog";
<SearchDialog
open={open}
onOpenChange={setOpen}
title="Jump to…"
description="Find workspace pages and quick actions."
>
<SearchInput
ref={inputRef}
value={query}
onValueChange={setQuery}
placeholder="Find a page or action…"
label="Find a page or action"
/>
<SearchList label="Pages and actions">
{pages.length ? (
<SearchGroup heading="Pages" count={pages.length}>
{pages.map((page) => (
<SearchItem
key={page.id}
value={page.id}
title={page.title}
media={<SearchItemIcon><page.icon size={14} aria-hidden="true" /></SearchItemIcon>}
onSelect={() => open(page)}
/>
))}
</SearchGroup>
) : (
<SearchEmpty
title="No pages or actions found"
description="Try another page or action name."
action={<Button variant="outline" size="sm" onClick={clear}>Clear search</Button>}
/>
)}
</SearchList>
<SearchFooter>
<SearchHint keys="↑↓">Select</SearchHint>
<SearchHint keys="↵">Open</SearchHint>
<SearchHint keys="Esc">Close</SearchHint>
</SearchFooter>
</SearchDialog>Search Dialog does not filter. Match the query yourself and render only the results, then show SearchEmpty when nothing is left. Clear the query when the dialog closes. Give every SearchItem avalue that is unique across groups, such as the group name plus the id when one entry appears under Recent and Pages.
Commands and events
Pass a shortcut letter as trailing; on the active row it swaps for the Enter key. media can be a bare icon, centered in a 28px box, or a muted SearchItemIcon. detailadds a second line such as a time. A group whose count is 0 is not rendered, and long titles truncate.
Calendar commands
Commands with trailing shortcut keys and events with kind icons and times. The Enter hint replaces the shortcut on the active row. Press / to open.
No command run yet
Filters, meta, and empty media
SearchFilters holds a row of SearchFilter toggles that scrolls sideways when narrow. meta sits after the title behind a dot. Give SearchEmpty one to three icons asmedia to show them as fanned tiles over a faint grid.
Filters, meta, and detail
Toggle filters under the input, a meta label after each title, a second detail line, and an empty state with fanned icon tiles and a Clear filters action.
Nothing selected
API
SearchDialog takes open, onOpenChange, a visually hidden title and description, plusclassName and container. It is 42rem wide from 640px and pins 12% from the top. SearchInput takes a controlledvalue and onValueChange,placeholder, label, closeLabel, and aref so a Clear search button can refocus it.
SearchFilters takes label; SearchFiltertakes pressed, onPressedChange, and an optionalicon. SearchList takes label and keeps a steady height. SearchGroup takes heading andcount. SearchItem takes value,onSelect, media, title, and optionalmeta, detail, and trailing.SearchEmpty takes title, description, and optional media and action.SearchFooter holds SearchHints, each withkeys; it hides below 640px. Every part sets adata-slot.
Accessibility
Focus moves to the search field, a combobox that controls the resultslistbox, and the active result is announced througharia-activedescendant. Arrow keys move and wrap at the ends, Home and End jump, Alt with arrows jumps between groups, and Enter opens. Group names include their count. Filters are toggle buttons witharia-pressed. The empty state is a status, so its message is announced. Escape or the close button closes the dialog and returns focus to the trigger.
The dialog fades and scales over 180ms, and highlights and filters change over 120ms. Motion stops when reduced motion is requested.
Theme tokens
Search Dialog uses --sprout-surface, --sprout-canvas,--sprout-text, --sprout-muted,--sprout-line, --sprout-input,--sprout-hover, --sprout-active,--sprout-focus, --sprout-overlay, and the panel shadows and radii. It needs no brand color, so it looks the same with the neutral and TulipFarm themes in light and dark mode.