Select#

A focusable single-choice menu. ↑/k and ↓/j move the selection (wrapping); the chosen option is marked with .

Import#

TSX
import { Select } from '@sigx/terminal';
import type { SelectOption } from '@sigx/terminal';

Usage#

TSX
/** @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#

PropTypeNotes
optionsSelectOption[]required — the choices
modelModel<string>two-way bound selected value
labelstringcaption above the list
autofocusbooleangrab focus on mount
showDescriptionbooleanrender the selected option's description below

Events#

EventPayloadWhen
changestringselection moves
submitstringEnter

SelectOption#

TypeScript
interface SelectOption<T = string> {
    label: string;
    value: T;
    description?: string;
}

See also#