search
Type-to-filter select prompt.
Preview
Filtering
search
◇ Select timezone│ pac│ ◉ Pacific (UTC-8)│ ○ Asia/Pacific└
After submit
search
◆ Select timezone│ Pacific
Usage
import { search, isCancel } from 'termprompt';
const timezone = await search({
message: 'Select timezone',
options: [
{ value: 'utc', label: 'UTC' },
{ value: 'est', label: 'Eastern', hint: 'UTC-5' },
{ value: 'pst', label: 'Pacific', hint: 'UTC-8' },
{ value: 'cet', label: 'Central European', hint: 'UTC+1' },
{ value: 'jst', label: 'Japan', hint: 'UTC+9' },
],
});
if (isCancel(timezone)) process.exit(0);
console.log(timezone);
Props
| Prop | Type | Default | Description |
|---|---|---|---|
message | string | required | Question text |
options | SearchOption<T>[] | required | Full list to filter from |
placeholder | string? | none | Gray text when query is empty |
maxItems | number | 10 | Visible results before scrolling |
SearchOption
| Field | Type | Description |
|---|---|---|
value | T | Value returned on selection |
label | string | Searchable display text |
hint | string? | Also searchable, shown on active |
How Filtering Works
Case-insensitive search against both label and hint. Results update on every keystroke and the cursor resets to the first match.
Keyboard
| Key | Action |
|---|---|
| Type | Filter options |
Up / Down | Navigate results |
Backspace | Edit query |
Enter | Submit |
Esc | Cancel |