Skip to content
Sign upPro
ComposerSearch composerMenu

Search composer (Pro)

ProIncluded in $99

A search field with its focus scope inside it: web, academic, social or files, switchable from the keyboard, with recency at the end.

ProA science reporter checks a reader's question: @academic turns into the scope, the past year narrows it, then it searches.

Installation

$ pnpm dlx shadcn@latest add @chatcn-pro/search-composer

Needs chatcn Pro

This command works with a Pro license, along with every Pro component.

Or start free: sign up and get three Pro components on us, with a new one every month.

Usage

tsx
import { SearchComposer } from "@/components/ui/chatcn/pro/search-composer"

<SearchComposer
  scope={scope}
  onScopeChange={setScope}
  onSubmit={({ query, scope, recency }) => search(query, { scope, recency })}
  status={status}
  onStop={stop}
/>

The scope is a token at the start of the field, so what you are searching is never a setting hidden somewhere else. It sets the placeholder and the line under the field, and recency sits at the end for scopes that have it (files do not by default). Option or Alt with a number switches scope without leaving the text, and @academic or @papers typed at the start turns into the token. On a phone the query takes the first row and the scope, recency and Search share the second. searchScopes and searchRecencies are exported to extend or reorder; pass your own with scopes and recencies. Everything else is the free PromptInput in its one row form: IME safe Enter, paste, Stop in the send footprint.

Examples

States

ProEach scope, a recency filter, files without recency, searching, a long query, a narrow field and disabled.

Props

PropTypeNotes
scopesSearchScope[]{ id, label, icon?, placeholder?, description?, recency? }
scope, defaultScope, onScopeChangestringDefaults to the first scope
recenciesSearchRecency[]{ id, label, short? }. The first means no filter
recency, defaultRecency, onRecencyChangestring
onSubmit({ query, scope, recency? }) => voidrecency is left out for scopes without it
hideFootnotebooleanDrop the scope line under the field
value, defaultValue, onValueChangestringThe draft, controlled or not
status, onStop"idle" | "submitting" | "streaming", () => voidSend becomes Stop in the same footprint
disabledboolean
labelsPartial<SearchComposerLabels>Every string, for translation

Keyboard

KeyAction
Option 1 to 9, Alt 1 to 9Switch scope from the field
@ and a scope, then SpaceTurn the word into the scope token
EnterSearch. Shift Enter adds a line
EscapeStop a running search

Accessibility

  • The scope token is a menu button named with the current scope, for example Search in: Academic.
  • Scopes are radio items with their shortcut shown; picking one returns focus to the field.
  • Switching scope from the keyboard is announced politely.
  • The field's name includes the scope, so it is heard with every focus.

Motion

Menus open from their trigger in 180 ms like every kit menu. Switching scope never animates because it is mostly done from the keyboard; the token and placeholder change in place.