/** * KTUI - Free & Open-Source Tailwind UI Components by Keenthemes * Copyright 2025 by Keenthemes Inc */ import KTComponent from '../component'; import { KTSelectConfigInterface } from './config'; export declare class KTSelect extends KTComponent { protected readonly _name: string; protected readonly _dataOptionPrefix: string; protected _element: HTMLElement; protected _config: KTSelectConfigInterface; protected _defaultConfig: KTSelectConfigInterface; private static globalConfig; private static openDropdowns; private _wrapperElement; private _displayElement; private _dropdownContentElement; private _searchInputElement; private _options; private _optionsContainer; private _dropdownIsOpen; private _state; private _searchModule; private _remoteModule; private _comboboxModule; private _tagsModule; private _dropdownModule; private _loadMoreIndicator; private _selectAllButton; private _selectAllButtonToggle; private _focusManager; private _eventManager; private _typeToSearchBuffer; private _mutationObserver; private _preSelectedValues; /** * Constructor: Initializes the select component */ constructor(element: HTMLElement, config?: KTSelectConfigInterface); /** * Set global select configuration options. * This allows setting default configuration that will be applied to all new KTSelect instances. * @param options Partial select config to merge with global config. * @example * KTSelect.config({ * enableSearch: true, * searchPlaceholder: 'Type to search...', * dropdownZindex: 9999, * height: 300 * }); */ static config(options: Partial): void; /** * Override _buildConfig to include static globalConfig in the merge chain */ protected _buildConfig(config?: object): void; /** * Override _dispatchEvent to also dispatch on document for global listeners (jQuery compatibility) */ protected _dispatchEvent(eventType: string, payload?: object | null): void; getElement(): HTMLElement; /** * Initialize remote data fetching */ private _initializeRemoteData; /** * Clear existing options from the select element */ private _clearExistingOptions; /** * Unified method to render options in dropdown - eliminates code duplication */ private _renderOptionsInDropdown; /** * Update dropdown with new options from the original select element */ private _updateDropdownWithNewOptions; /** * Complete the setup for remote data after HTML structure is created */ private _completeRemoteSetup; /** * Helper to show a dropdown message (error, loading, noResults) */ private _showDropdownMessage; /** * Render loading state in dropdown */ private _renderLoadingState; /** * Render error state * @param message Error message */ private _renderErrorState; /** * Add "Load More" button for pagination */ private _addLoadMoreButton; /** * Handle load more button click */ private _handleLoadMore; /** * Update options in the dropdown * @param newItems New items to add to the dropdown */ private _updateOptionsInDropdown; /** * ======================================================================== * INITIALIZATION METHODS * ======================================================================== */ /** * Set up the component after everything is initialized */ private _setupComponent; /** * Creates the HTML structure for the select component */ private _createHtmlStructure; /** * Setup all element references after DOM is created */ private _setupElementReferences; /** * Attach all event listeners to elements */ private _attachEventListeners; /** * Initialize search module if search is enabled */ private _initializeSearchModule; /** * Apply ARIA attributes and update display */ private _updateDisplayAndAriaAttributes; /** * Apply initial disabled state if configured */ private _applyInitialDisabledState; /** * Generate options HTML from data items */ private _generateOptionsHtml; /** * Extract nested property value from object using dot notation */ private _getValueByKey; /** * Pre-select options that have the selected attribute */ private _preSelectOptions; /** * ======================================================================== * DROPDOWN MANAGEMENT * ======================================================================== */ /** * Open the dropdown */ openDropdown(): void; /** * Close the dropdown */ closeDropdown(): void; /** * Update dropdown position */ updateDropdownPosition(): void; /** * Focus on the first selected option if any exists in the dropdown */ private _focusSelectedOption; /** * ======================================================================== * SELECTION MANAGEMENT * ======================================================================== */ /** * Select an option by value */ private _selectOption; /** * Sync native select value attribute for FormData support */ private _syncNativeSelectValue; /** * Update selected option display value */ updateSelectedOptionDisplay(): void; /** * Check if an option was originally disabled in the HTML */ private _isOptionOriginallyDisabled; /** * Update CSS classes for selected options */ private _updateSelectedOptionClass; /** * Clear all selected options */ clearSelection(): void; /** * Deselect a specific option by value * @param value The value of the option to deselect * @public */ deselectOption(value: string): void; /** * Set selected options programmatically */ setSelectedOptions(options: HTMLOptionElement[]): void; /** * Select the currently focused option */ selectFocusedOption(): void; /** * ======================================================================== * EVENT HANDLERS * ======================================================================== */ /** * Handle click within the dropdown */ private _handleDropdownOptionClick; /** * Handle clicking on an option in the dropdown */ private _handleOptionClick; /** * Handle document click for closing dropdown */ private _handleDocumentClick; /** * ======================================================================== * ACCESSIBILITY METHODS * ======================================================================== */ /** * Set ARIA attributes for accessibility */ private _setAriaAttributes; /** * ======================================================================== * PUBLIC API * ======================================================================== */ /** * Get the search input element */ getSearchInput(): HTMLInputElement | null; /** * Returns the current selection as **option value** strings (not labels, not DOM nodes). * For single-select, the array has zero or one entry; use {@link getValue} for a scalar. * For multiple-select, the array may contain multiple values in arbitrary order. */ getSelectedOptions(): string[]; /** * Returns the selected option **value** for single-select, or `null` when nothing is selected. * When the select is configured with `multiple: true`, always returns `null` — use {@link getSelectedOptions} instead. */ getValue(): string | null; /** * Get configuration */ getConfig(): KTSelectConfigInterface; /** * Get option elements */ getOptionsElement(): NodeListOf; /** * Get dropdown element */ getDropdownElement(): HTMLElement; /** * Get value display element */ getValueDisplayElement(): HTMLElement; /** * Get wrapper element */ getWrapperElement(): HTMLElement; /** * Show all options in the dropdown */ showAllOptions(): void; /** * Toggle multi-select functionality */ enableMultiSelect(): void; /** * Disable multi-select functionality */ disableMultiSelect(): void; /** * Toggle the selection of an option */ toggleSelection(value: string): void; /** * Clean up all resources when the component is destroyed * This overrides the parent dispose method */ dispose(): void; /** * ======================================================================== * DYNAMIC CONTROL METHODS * ======================================================================== */ /** * Programmatically enable the select component * @public */ enable(): void; /** * Programmatically disable the select component * @public */ disable(): void; /** * Update the dropdown to sync with native select element changes * For remote selects, refetches data from the server and preserves selections * Optionally accepts new options to replace existing ones (static selects only) * * @param newOptions Optional array of new options [{value, text}, ...] (static selects only) * @public * @remarks * - For static selects: rebuilds dropdown from native select or new options * - For remote selects: fetches fresh data, preserves matching selections * - Selections are preserved if their values exist in new remote data * - Selections are cleared if their values don't exist in new data * @fires updated - After update completes successfully * @fires updateError - If remote data fetch fails */ update(newOptions?: Array<{ value: string; text: string; }>): void; /** * Reload remote data and rebuild the dropdown * Only works with remote data enabled * @returns Promise that resolves when reload completes * @public */ reload(): Promise; /** * Refresh the visual display and state without rebuilding options * For remote selects, refetches data from the server and preserves selections * that exist in the newly fetched data * * @public * @remarks * - For static selects: syncs visual state with native select * - For remote selects: fetches fresh data, preserves matching selections * - Selections are preserved if their values exist in new remote data * - Selections are cleared if their values don't exist in new data * @fires refreshed - After refresh completes successfully * @fires refreshError - If remote data fetch fails */ refresh(): void; /** * ======================================================================== * STATIC METHODS * ======================================================================== */ /** * Create instances of KTSelect for all matching elements */ static createInstances(): void; /** * Initialize all KTSelect instances */ static init(): void; /** * Get an existing KTSelect instance from an element */ static getInstance(element: HTMLElement): KTSelect | null; /** * Get an existing KTSelect instance or create a new one */ static getOrCreateInstance(element: HTMLElement, config?: KTSelectConfigInterface): KTSelect; /** * Handle remote search * @param event Input event */ private _handleRemoteSearch; private _searchDebounceTimeout; /** * Render loading state for search */ private _renderSearchLoadingState; private _originalOptionsHtml; /** * Render error state for search * @param message Error message */ private _renderSearchErrorState; /** * Restore original options when search is cleared */ private _restoreOriginalOptions; /** * Update search results in the dropdown * @param items Search result items */ private _updateSearchResults; /** * Update original select element with search results * @param items Search result items */ private _updateOriginalSelectWithSearchResults; /** * Check if dropdown is open */ isDropdownOpen(): boolean; getSelectedOptionsText(): string; /** * Check if an option is disabled (either in dropdown or original select) */ private _isOptionDisabled; /** * Centralized keyboard event handler for all select modes */ private _handleKeyboardEvent; renderDisplayTemplateForSelected(selectedValues: string[]): string; getDisplayElement(): HTMLElement; private _observeNativeSelect; private _rebuildOptionsFromNative; private _syncSelectionFromNative; private _handleSelectAllClick; updateSelectAllButtonState(): void; /** * Destroy the component and clean up resources */ destroy(): void; } //# sourceMappingURL=select.d.ts.map