Caret-Tui

Select

An interactive single-choice list menu.

Select provides an accessible, navigable list of options. It features keyboard navigation (Up/Down arrows or j/k keys), pagination (Ctrl+U/D), and support for disabled items and sub-descriptions.

Usage

import { Select } from 'caret-tui';

const options = [
  { label: 'Development', value: 'dev', description: 'Local environment' },
  { label: 'Staging', value: 'stage', description: 'Testing environment' },
  { label: 'Production', value: 'prod', disabled: true }
];

const App = () => (
  <Select 
    label="Choose Environment:"
    options={options} 
    onSelect={(val) => console.log(val)} 
  />
);

Props

PropTypeDefaultDescription
optionsSelectOption<T>[]-The array of choices available.
onSelect(value: T) => void-Callback fired when an option is selected.
onCancel() => void-Optional callback fired if the user presses Esc.
labelstring-An optional title displayed above the list.
visibleCountnumber8Maximum number of options to show simultaneously.
isActivebooleantrueIf false, keyboard interaction is disabled.

SelectOption<T> Definition

FieldTypeDescription
labelstringThe primary text displayed for the option.
valueTThe underlying value.
descriptionstringSecondary text displayed underneath the label when focused.
disabledbooleanIf true, the option is grayed out and cannot be selected.

On this page