Search

A search field with results and recent searches.

Recent searches

  • sign-in
  • onboarding emails

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/search

Usage

import { Search, type SearchResult } from "./ui/uicontext/components/kit/Search.ts"
const Message = UiSchema.TaggedEnum({	RequestedSearch: { query: Schema.String },	RequestedOpenResult: { id: Schema.String },})export const WorkspaceSearch = (h: Html.H<typeof Message.Type>, query: string, results: ReadonlyArray<SearchResult>) =>	Search(h, {		props: { query, results, status: "ready", recent: ["sign-in", "onboarding"] },		onEmit: {			RequestedSearch: ({ query }) => Message.RequestedSearch({ query }),			RequestedOpen: ({ id }) => Message.RequestedOpenResult({ id }),			RequestedAsk: () => undefined,			RequestedStop: () => undefined,		},	})

API reference

Props

Search props
NameTypeDefaultDescription
queryrequiredstring—The query the results are for
resultsrequiredSearchResult[]—The results for query, best first
statusrequired"idle" | "loading" | "ready"—Whether the results are being fetched (loading shows placeholders) or are in (ready)
totalnumber—Every match, when there are more than shown
sourcesSearchSource[]—Where results can come from, shown as filters: Issues, Docs, People
selectedstring[]—The sources filtered to; none means all
answerSearchAnswer | null—An AI answer to the query, streamed in, with its citations
canCan(["ask"])—What the asker may do: "ask" asks for an AI answer (plan, role and setting allowing)
labelstring"Search"The search field's accessible name; "Search" by default
placeholderstring—The field's placeholder; "Search…" by default
hintstring—Shown before anything is typed
recentstring[]—The person's recent searches, latest first: listed before anything is typed, and picking one searches it again. The app keeps them, from RequestedSearch.
localestring—The locale counts and dates are written in, such as "en-US"; the browser's by default
agentIdstring—This search's id for agents, unique on the page
scopesSearchScope[]—Tokens that narrow the search: from:, in:, has:
groupedboolean—Give each run of results from one source a heading (send them sorted by source)

Events

Search events
EventPayloadDescription
RequestedSearch{ query: string; sources: string[] }The query or the source filter changed: the app fetches results
RequestedOpen{ id: string }A result was opened, by Enter or a click: the app goes there
RequestedAsk{ query: string }The person asked for an AI answer to the query
RequestedStop{}The person stopped the answer being written

Agent actions

What agents can do with Search
ActionDescription
SubmittedQuerySearch for a query; returns once its results are in
ToggledSourceFilter to a source by id, or "all"
OpenedResultOpen a result by its id
ClickedAskAsk for an AI answer to the current query, with sources
ClickedStopStop the answer being written

Accessibility

  • The field is a combobox inside a search landmark: Up and Down move through the results and Enter opens one, while focus stays in the field.
  • The source filters are toggle buttons (aria-pressed), the result count is a status, and the AI answer is a live region that says when it's still being written.
  • Agents search, filter, open a result, and ask for or stop an answer.

Source