Select
A focusable single-choice menu. ↑/k and ↓/j move the selection (wrapping); the chosen option is marked with ❯.
Import
import { Select } from '@sigx/terminal';
import type { SelectOption } from '@sigx/terminal';
Usage
/** @jsxImportSource @sigx/terminal */
import { component, defineApp, signal, Select } from '@sigx/terminal';
import type { SelectOption } from '@sigx/terminal';
const options: SelectOption[] = [
{ label: 'Development', value: 'dev', description: 'Local dev build' },
{ label: 'Staging', value: 'staging', description: 'Pre-production' },
{ label: 'Production', value: 'prod', description: 'Live environment' },
];
const App = component(() => {
const env = signal('dev');
return () => (
<box border="rounded" label="Deploy target">
<Select
options={options}
model={() => env}
label="Environment"
showDescription
autofocus
onChange={(v) => console.log('selected:', v)}
onSubmit={(v) => console.log('confirmed:', v)}
/>
<br />
<text>Target: {env.value}</text>
</box>
);
});
defineApp(<App />).mount({ clearConsole: true });
Props
| Prop | Type | Notes |
|---|---|---|
options | SelectOption[] | required — the choices |
model | Model<string> | two-way bound selected value |
label | string | caption above the list |
autofocus | boolean | grab focus on mount |
showDescription | boolean | render the selected option's description below |
Events
| Event | Payload | When |
|---|---|---|
change | string | selection moves |
submit | string | Enter |
SelectOption
interface SelectOption<T = string> {
label: string;
value: T;
description?: string;
}
See also
- Radio — every option always visible.
- MultiSelect — choose several.
- select() prompt — the imperative form.
