Site Search
nswds-ui/site-searchFreeComponent
Cmd/Ctrl-K site search palette on the Base UI autocomplete and dialog primitives — grouped results, keyboard filtering and an onSelect callback for framework routing.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/digitalnsw/nswds-ui/main/apps/registry/public/r/site-search.jsonSource
1'use client'23import { Autocomplete } from '@base-ui/react/autocomplete'4import { Dialog } from '@base-ui/react/dialog'5import React from 'react'67import { IconSearch } from '@/icons/search'8import { cn } from '@/lib/utils'910import { Button } from '@/components/button'1112/** A single searchable destination. `keywords` extend matching beyond the title. */13type SiteSearchItem = {14 title: string15 href: string16 keywords?: string[]17}1819/** A titled section of results, rendered with a muted group heading. */20type SiteSearchGroup = {21 title: string22 items: SiteSearchItem[]23}2425type SiteSearchProps = {26 /** The searchable site map, as titled groups of items. */27 groups: SiteSearchGroup[]28 /**29 * Called with the chosen item on click or Enter, after the palette closes.30 * Navigation is the APP's job — call your router here (e.g. next/navigation's31 * `router.push(item.href)`). The design system ships no framework code, so it32 * never navigates itself; this mirrors the DS-wide framework-free rule33 * (see `Link` / `LinkProvider`).34 */35 onSelect: (item: SiteSearchItem) => void36 /** Whether the palette is open. Use when controlled. */37 open?: boolean38 /** Called whenever the palette asks to open or close. */39 onOpenChange?: (open: boolean) => void40 /** Whether the palette is initially open (uncontrolled). */41 defaultOpen?: boolean42 /**43 * Wire the global Cmd/Ctrl-K toggle on `document`, with cleanup on unmount.44 * Defaults to true. Only one shortcut-enabled SiteSearch should be mounted45 * per page, or each press toggles all of them.46 */47 shortcut?: boolean48 /**49 * Accessible name for the palette, applied as `aria-label` to the dialog50 * panel, the search input and the default trigger. Defaults to51 * `'Search site'`. Mirrors ExpandableSearch's `label` prop — localise it52 * rather than hardcoding English into consumers' pages.53 */54 label?: string55 /** Placeholder for the search input. */56 placeholder?: string57 /** Message shown when no items match the query. */58 emptyMessage?: string59 /**60 * The element that opens the palette. Defaults to a ghost icon `Button`61 * named by `label`. Pass an element to replace it — it is composed via Base62 * UI's `render` prop, so it inherits the trigger behaviour and ARIA — or63 * `null` to render no trigger at all (open via `open` or the shortcut).64 * A custom trigger owns its own accessible name — `label` is applied as65// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from @nswds/ui
All 46 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Aspect Ratioaspect-ratio | @nswds/ui | Components | Free | 2 deps · 2 files | |
| Badgebadge | @nswds/ui | Components | Free | 4 deps · 2 files | |
| Buttonbutton | @nswds/ui | Components | Free | 4 deps · 2 files | |
| Cardcard | @nswds/ui | Components | Free | 2 deps · 2 files | |
| Collapsiblecollapsible | @nswds/ui | Components | Free | 1 dep | |
| Drawerdrawer | @nswds/ui | Components | Free | 3 deps · 2 files | |
| Expandable Searchexpandable-search | @nswds/ui | Components | Free | 3 deps · 2 files | |
| Fieldfield | @nswds/ui | Components | Free | 4 deps · 2 files |
