MultiSelect#

A checkbox list with a movable cursor. The model holds the array of checked values. ↑/k ↓/j move, Space toggles, a toggles all, Enter submits.

Import#

TSX
import { MultiSelect } from '@sigx/terminal';
import type { MultiSelectOption } from '@sigx/terminal';

Usage#

TSX
/** @jsxImportSource @sigx/terminal */
import { component, defineApp, signal, MultiSelect } from '@sigx/terminal';
import type { MultiSelectOption } from '@sigx/terminal';

const options: MultiSelectOption[] = [
    { label: 'TypeScript', value: 'ts', group: 'Language' },
    { label: 'ESLint', value: 'eslint', group: 'Tooling' },
    { label: 'Vitest', value: 'vitest', group: 'Tooling' },
];

const App = component(() => {
    const features = signal<string[]>([]);
    return () => (
        <box border="rounded" label="Features">
            <MultiSelect
                options={options}
                model={() => features}
                label="Select features"
                required
                showHint
                autofocus
                onSubmit={(v) => console.log('chosen:', v)}
            />
        </box>
    );
});

defineApp(<App />).mount({ clearConsole: true });

Props#

PropTypeNotes
optionsMultiSelectOption[]required — the choices
modelModel<string[]>two-way bound array of checked values
labelstringcaption above the list
autofocusbooleangrab focus on mount
requiredbooleanblock an empty submit
showHintbooleanshow the keys hint

Events#

EventPayloadWhen
changestring[]the checked set changes
submitstring[]Enter (blocked with a hint when required and nothing is checked)

MultiSelectOption#

TypeScript
interface MultiSelectOption<T = string> {
    label: string;
    value: T;
    description?: string;
    group?: string; // section header when it differs from the previous option's group
}

Set group to render section headers; the cursor skips headers. Pre-sort options by group.

See also#