/** * Select primitive for list selection. * Uses signals for state and integrates with the focus manager. * * Simplified model: navigation directly changes the selection. * No separate "focused" vs "selected" state - they are the same. * * Handles edge cases with dynamic option lists: * - preferredIndex: internal unclamped index (where user wants to be) * - selectedIndex: computed safe index (clamped to valid range, -1 if empty) * - value: derived from selectedIndex (undefined if no options) */ import { type Focusable } from "./focus.js"; export interface SelectOptions { /** Initial selected value */ initialValue?: T; /** Called when selection changes */ onChange?: (value: T | undefined) => void; /** * Custom keypress handler. * Return true to consume the key, false to let it bubble. * Called before default handling (Up/Down/Enter/Space). */ onKeypress?: (key: string) => boolean; /** Comparison function for values (default: ===) */ isEqual?: (a: T, b: T) => boolean; /** * Whether the select participates in focus management (default: true). * Set to false for FZF-like patterns where an input is focused * but the select handles navigation. */ focusable?: boolean; } export interface Select extends Focusable { /** The currently selected value (undefined if no options) */ value: () => T | undefined; /** The index of the currently selected option (-1 if no options) */ selectedIndex: () => number; /** Whether this select has focus in the focus manager */ focused: () => boolean; /** Check if the given value is currently selected */ isSelected: (value: T) => boolean; /** Check if the given index is currently selected */ isSelectedIndex: (index: number) => boolean; /** Set selection by value */ setValue: (value: T) => void; /** Set selection by index */ setIndex: (index: number) => void; /** Select the next option */ next: () => void; /** Select the previous option */ prev: () => void; focus: () => void; blur: () => void; dispose: () => void; handleKey: (key: string) => boolean; /** @internal - set option count for navigation bounds */ _setOptionCount: (count: number) => void; /** @internal - get option values */ _getOptionValues: () => T[]; /** @internal - register option value at index */ _registerOption: (index: number, value: T) => void; /** @internal - clear registered options (called before re-render) */ _clearOptions: () => void; } /** * Create a select primitive with reactive state. * * Navigation directly changes the selection - no separate "highlight" state. * Handles dynamic option lists gracefully (empty lists → undefined value). * * @example * ```tsx * const sel = createSelect({ initialValue: "a" }); * * function MySelect() { * return ( * * ); * } * * // Access current value (undefined if no options) * console.log(sel.value()); * * // Navigate (and select) next option * sel.next(); * ``` */ export declare function createSelect(options?: SelectOptions): Select; //# sourceMappingURL=select.d.ts.map