Search composer (Pro)
ProIncluded in $99A search field with its focus scope inside it: web, academic, social or files, switchable from the keyboard, with recency at the end.
On this page
Installation
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
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
Props
| Prop | Type | Notes |
|---|---|---|
scopes | SearchScope[] | { id, label, icon?, placeholder?, description?, recency? } |
scope, defaultScope, onScopeChange | string | Defaults to the first scope |
recencies | SearchRecency[] | { id, label, short? }. The first means no filter |
recency, defaultRecency, onRecencyChange | string | |
onSubmit | ({ query, scope, recency? }) => void | recency is left out for scopes without it |
hideFootnote | boolean | Drop the scope line under the field |
value, defaultValue, onValueChange | string | The draft, controlled or not |
status, onStop | "idle" | "submitting" | "streaming", () => void | Send becomes Stop in the same footprint |
disabled | boolean | |
labels | Partial<SearchComposerLabels> | Every string, for translation |
Keyboard
| Key | Action |
|---|---|
| Option 1 to 9, Alt 1 to 9 | Switch scope from the field |
| @ and a scope, then Space | Turn the word into the scope token |
| Enter | Search. Shift Enter adds a line |
| Escape | Stop 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.