@oslokommune/punkt-elements
Version:
Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo
39 lines (38 loc) • 1.81 kB
TypeScript
/**
* Shared combobox input utility functions used by both Elements and React packages.
* Covers keyboard actions, focus-out validation, match checking, and input display.
*/
import type { IPktComboboxOption } from '../../shared-types/combobox';
export type TInputKeyAction = 'addValue' | 'focusListbox' | 'closeOptions' | null;
/**
* Determines the action for a keydown event on the combobox input.
*/
export declare const getInputKeyAction: (key: string, shiftKey: boolean, multiple: boolean) => TInputKeyAction;
/**
* Determines if a key is an arrow/toggle key for select-only mode.
*/
export declare const isArrowToggleKey: (key: string) => boolean;
export type TFocusOutAction = 'addUserValue' | 'selectOption' | 'removeValue' | 'none';
export interface IFocusOutResult {
action: TFocusOutAction;
value: string | null;
}
/**
* Determines what to do with the input value when focus leaves the combobox.
*/
export declare const getInputValueAction: (inputValue: string, currentValues: string[], options: IPktComboboxOption[], allowUserInput: boolean, multiple: boolean) => IFocusOutResult;
export interface ICheckForMatchesResult {
addValueText: string | null;
userInfoMessage: string;
shouldRemoveValue: boolean;
shouldResetInput: boolean;
}
/**
* Determines the info message and actions based on search input.
* Wraps getSearchInfoMessage, adding the empty-input case.
*/
export declare const checkForMatches: (inputValue: string, currentValues: string[], options: IPktComboboxOption[], allowUserInput: boolean, multiple: boolean) => ICheckForMatchesResult;
/**
* Determines what text to display in a single-select input for the given value.
*/
export declare const getSingleValueForInput: (value: string, options: IPktComboboxOption[], displayValueAs: string) => string;