@preline/select 4.1.2 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,397 @@
1
+ # Advanced Select
2
+
3
+ Advanced select solutions for massive datasets.
4
+
5
+ [![npm](https://img.shields.io/badge/npm-v4.2.0-blue)](https://www.npmjs.com/package/@preline/select) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Demo](https://img.shields.io/badge/demo-online-brightgreen)](https://preline.co/plugins/advanced-select.html)
6
+
7
+ ## Contents
8
+
9
+ - [Overview](#overview)
10
+ - [Installation](#installation)
11
+ - [Basic usage](#basic-usage)
12
+ - [Configuration Options](#configuration-options)
13
+ - [JavaScript API](#javascript-api)
14
+ - [Events](#events)
15
+ - [Common Patterns](#common-patterns)
16
+ - [License](#license)
17
+
18
+ ## Overview
19
+
20
+ The Advanced Select component provides a customizable dropdown select interface with support for search, tags, API integration, and extensive styling options. It's designed for handling large datasets and complex selection scenarios.
21
+
22
+ **Key Features:**
23
+ - Search functionality
24
+ - Tags mode for multiple selections
25
+ - API integration for dynamic options
26
+ - Custom templates and styling
27
+ - Multiple selection support
28
+ - Option grouping
29
+ - Icons and descriptions for options
30
+ - Programmatic control via JavaScript API
31
+ - Event system for selection tracking
32
+
33
+ ## Installation
34
+
35
+ To get started, install Select plugin via npm, else you can skip this step if you are already using Preline UI as a package.
36
+
37
+ ```bash
38
+ npm i @preline/select
39
+ ```
40
+
41
+ Some positioning features require [Floating UI](https://floating-ui.com). Install it if you plan to use `dropdownScope: "window"`, `dropdownPlacement`, or `dropdownAutoPlacement`:
42
+
43
+ ```bash
44
+ npm i @floating-ui/dom
45
+ ```
46
+
47
+ ### CSS
48
+
49
+ Use [`@source`](https://tailwindcss.com/docs/functions-and-directives#source-directive) to register the plugin's JavaScript path for Tailwind CSS scanning, then [`@import`](https://tailwindcss.com/docs/functions-and-directives#import-directive) the plugin's CSS files into your Tailwind CSS file.
50
+
51
+ ```css
52
+ @import "tailwindcss";
53
+
54
+ /* @preline/select */
55
+ @source "../node_modules/@preline/select/*.js";
56
+ @import "./node_modules/@preline/select/variants.css";
57
+ @import "./node_modules/@preline/select/theme.css";
58
+ ```
59
+
60
+ ### JavaScript
61
+
62
+ Include the JavaScript that powers the interactive elements near the end of your `</body>` tag. If you use `dropdownScope: "window"`, `dropdownPlacement`, or `dropdownAutoPlacement`, also load the [Floating UI](https://floating-ui.com) UMD bundle before the plugin. It exposes the `FloatingUIDOM` global the plugin relies on.
63
+
64
+ ```html
65
+ <!-- Optional: required for dropdownScope: "window", dropdownPlacement, dropdownAutoPlacement -->
66
+ <script src="https://cdn.jsdelivr.net/npm/@floating-ui/dom@latest/dist/floating-ui.dom.umd.min.js"></script>
67
+ <script src="./node_modules/@preline/select/index.js"></script>
68
+ ```
69
+
70
+ ### Manual Initialization
71
+
72
+ Use the `non-auto` entry if you need manual initialization. In this mode, automatic initialization on page load is not included, so the component should be initialized explicitly.
73
+
74
+ ```html
75
+ <!-- Optional: required for dropdownScope: "window", dropdownPlacement, dropdownAutoPlacement -->
76
+ <script src="https://cdn.jsdelivr.net/npm/@floating-ui/dom@latest/dist/floating-ui.dom.umd.min.js"></script>
77
+ <script type="module">
78
+ import HSSelect from "@preline/select/non-auto.mjs";
79
+
80
+ new HSSelect(document.querySelector("#select"));
81
+ </script>
82
+ ```
83
+
84
+ ### Via Bundler
85
+
86
+ When using a bundler (Vite, webpack, etc.), import the plugin directly as an ES module. If you use `dropdownScope: "window"`, `dropdownPlacement`, or `dropdownAutoPlacement`, expose `FloatingUIDOM` on `window` before importing the plugin.
87
+
88
+ `@preline/select` is the auto-init entry: it scans the DOM and initializes matching elements automatically.
89
+
90
+ ```js
91
+ // Optional: required for dropdownScope: "window", dropdownPlacement, dropdownAutoPlacement
92
+ import * as FloatingUIDOM from "@floating-ui/dom";
93
+ window.FloatingUIDOM = FloatingUIDOM;
94
+
95
+ import "@preline/select";
96
+ ```
97
+
98
+ `@preline/select/non-auto` is the manual entry: use it when you want explicit control over when initialization happens, either via `autoInit()` or by creating a specific instance yourself.
99
+
100
+ ```js
101
+ // Optional: required for dropdownScope: "window", dropdownPlacement, dropdownAutoPlacement
102
+ import * as FloatingUIDOM from "@floating-ui/dom";
103
+ window.FloatingUIDOM = FloatingUIDOM;
104
+
105
+ import HSSelect from "@preline/select/non-auto";
106
+
107
+ HSSelect.autoInit();
108
+
109
+ // Or initialize a specific element manually
110
+ const el = document.querySelector("#select");
111
+ if (el) new HSSelect(el);
112
+ ```
113
+
114
+ ### TypeScript
115
+
116
+ This package ships with TypeScript type definitions. No additional `@types/` package is needed.
117
+
118
+ ## Basic usage
119
+
120
+ The following example demonstrates the minimal HTML structure required for an advanced select component. This is a base template without custom styling - you can apply your own CSS classes and styles as needed. The component transforms a standard select element into an advanced dropdown.
121
+
122
+ ```html
123
+ <select data-hs-select='{
124
+ "placeholder": "Select option...",
125
+ "toggleTag": "<button type=\"button\"></button>",
126
+ "toggleClasses": "",
127
+ "dropdownClasses": "",
128
+ "optionClasses": "hs-selected:"
129
+ }'>
130
+ <option>Select option</option>
131
+ <option>Name</option>
132
+ <option>Email address</option>
133
+ <option>Description</option>
134
+ <option>User ID</option>
135
+ </select>
136
+ ```
137
+
138
+ **Structure Requirements:**
139
+ - `data-hs-select`: Required on the `<select>` element, contains configuration options as JSON
140
+ - Standard `<option>` elements inside the select
141
+ - Optional `<optgroup>` elements for grouping
142
+
143
+ **Initial State:**
144
+ - Select displays placeholder text when no option is selected
145
+ - Dropdown is closed by default
146
+
147
+ ## Configuration Options
148
+
149
+ ### Data Options
150
+
151
+ Data options are specified in the `data-hs-select` attribute as a JSON object.
152
+
153
+ | Option | Target Element | Type | Default | Description |
154
+ | --- | --- | --- | --- | --- |
155
+ | `data-hs-select` | Select element | - | - | Activate a Custom Select by specifying on an element. Should be added to the select. |
156
+ | `:isOpened` | Inside `data-hs-select` | boolean | `false` | Opens the select if the value is `true`. |
157
+ | `:placeholder` | Inside `data-hs-select` | string | `"Select..."` | Define a default placeholder when nothing is selected. |
158
+ | `:hasSearch` | Inside `data-hs-select` | boolean | `false` | Define a search field inside the dropdown if the value is `true`. |
159
+ | `:minSearchLength` | Inside `data-hs-select` | number | `0` | Specifies the minimum number of characters that must be entered before the search function becomes active. |
160
+ | `:preventSearchFocus` | Inside `data-hs-select` | boolean | `false` | Sets autofocus for the search field inside a dropdown list if the value is `true`. |
161
+ | `:preventSearchInsideDescription` | Inside `data-hs-select` | boolean | `false` | Prevents searching inside the description when set to `true`. |
162
+ | `:mode` | Inside `data-hs-select` | `'default'` \| `'tags'` | `'default'` | Define a select mode. `default` for single/multiple selection, `tags` for tag-based selection. |
163
+ | `:scrollToSelected` | Inside `data-hs-select` | boolean | `false` | Scroll to the selected option when the dropdown is opened. |
164
+ | `:toggleTag` | Inside `data-hs-select` | string (HTML markup) | - | Define a markup for the select toggle. Note: `data-title` is required if you are using a custom placeholder. |
165
+ | `:toggleClasses` | Inside `data-hs-select` | string | - | Define CSS classes for the selects' toggle. CSS classes must be separated by a space. |
166
+ | `:toggleSeparators` | Inside `data-hs-select` | object | - | Define separators for the selects' toggle. |
167
+ | `:toggleSeparators:items` | Inside `data-hs-select` | string | `", "` | Define which separator will be used for separate selected items. |
168
+ | `:toggleSeparators:betweenItemsAndCounter` | Inside `data-hs-select` | string | `"and"` | Define which separator will be used for separate selected items and counter text. |
169
+ | `:toggleCountText` | Inside `data-hs-select` | string | - | This option is only available for multiple select. Determines what text will be after the counter. It also activates the counting mode. |
170
+ | `:toggleCountTextPlacement` | Inside `data-hs-select` | `'postfix'` \| `'prefix'` \| `'postfix-no-space'` \| `'prefix-no-space'` | `'postfix'` | Allows to specify where the text specified in the `toggleCountText` parameter will be located relative to the counter. |
171
+ | `:toggleCountTextMinItems` | Inside `data-hs-select` | number | `1` | This option is only available for multiple select. Defines the minimum number of selected items at which the counting mode will be activated. |
172
+ | `:toggleCountTextMode` | Inside `data-hs-select` | `'countAfterLimit'` \| `'nItemsAndCount'` | `'countAfterLimit'` | This option is only available for multiple select. Controls the display of the contents of the button title. |
173
+ | `:wrapperClasses` | Inside `data-hs-select` | string | - | Define CSS classes for the selects' wrapper. CSS classes must be separated by a space. |
174
+ | `:tagsItemTemplate` | Inside `data-hs-select` | string (HTML markup) | - | This option is only available when tags mode is set up. Define template for the single tag. It could contain: `data-icon` if target option tag has `data-hs-select-option:icon`, `data-title` the text from the target option, `data-remove` the target tag will be deleted when click on tag with this data attribute. |
175
+ | `:tagsItemClasses` | Inside `data-hs-select` | string | - | This option is only available when tags mode is set up. Define CSS classes for the single tags. CSS classes must be separated by a space. |
176
+ | `:tagsInputId` | Inside `data-hs-select` | string | - | This option is only available when tags mode is set up. This option is useful if there is a need to associate a `label` outside the initialized element with the tags input. |
177
+ | `:tagsInputClasses` | Inside `data-hs-select` | string | - | This option is only available when tags mode is set up. Define CSS classes for the input. Defines CSS classes for the search field inside a dropdown list. CSS classes must be separated by a space. |
178
+ | `:dropdownTag` | Inside `data-hs-select` | string (HTML markup) | - | This option is only available when tags mode is set up. Define a markup for the dropdown. |
179
+ | `:dropdownClasses` | Inside `data-hs-select` | string | - | This option is only available when tags mode is set up. Define CSS classes for the dropdown. Defines CSS classes for the search field inside a dropdown list. CSS classes must be separated by a space. |
180
+ | `:dropdownPlacement` | Inside `data-hs-select` | `"top"` \| `"top-left"` \| `"top-right"` \| `"bottom"` \| `"bottom-left"` \| `"bottom-right"` \| `"right"` \| `"right-top"` \| `"right-bottom"` \| `"left"` \| `"left-top"` \| `"left-bottom"` | `"bottom"` | Specifies the position of the menu when opened. Requires the `Floating UI` and `dropdownScope` option to be `window`. |
181
+ | `:dropdownAutoPlacement` | Inside `data-hs-select` | boolean | `false` | Automatically determine the placement of the menu based on the available space. Requires the `Floating UI` and `dropdownScope` option to be `window`. |
182
+ | `:dropdownVerticalFixedPlacement` | Inside `data-hs-select` | `"top"` \| `"bottom"` \| null | `null` | Specifies a fixed vertical position for the menu when opened. It will not change when scrolling. |
183
+ | `:dropdownScope` | Inside `data-hs-select` | `"window"` \| `"parent"` | `"parent"` | Determines whether the dropdown will be moved outside the parent, for correct display in elements with hidden overflow. Requires the `Floating UI` plugin. |
184
+ | `:searchId` | Inside `data-hs-select` | string | - | This option is only available when `hasSearch: true`. This option is useful if there is a need to associate a `label` outside the initialized element with the search input. |
185
+ | `:searchLimit` | Inside `data-hs-select` | number | `Infinity` | This option is only available when `hasSearch: true`. If this option is enabled, the search will display only the first 'n' matching items. |
186
+ | `:isSearchDirectMatch` | Inside `data-hs-select` | boolean | `true` | This option is only available when `hasSearch: true`. If the option is disabled, then in the search results you will be able to see non-direct matches by text. For example, if you entered `england` in the search field, then `Eng-land`, `Eng.land`, `Eng_land` will also be shown. |
187
+ | `:searchClasses` | Inside `data-hs-select` | string | `"block w-[calc(100%-32px)] text-sm border-gray-200 rounded-md focus:border-blue-500 focus:ring-blue-500 dark:bg-neutral-900 dark:border-neutral-700 dark:text-neutral-400 py-2 px-3 my-2 mx-4"` | This option is only available when `:hasSearch` attribute is `true`. Define CSS classes for the search field inside the dropdown. Defines CSS classes for the search field inside a dropdown list. CSS classes must be separated by a space. |
188
+ | `:searchPlaceholder` | Inside `data-hs-select` | string | `"Search..."` | This option is only available when `:hasSearch` attribute is `true`. Determines placeholder for the search field inside the dropdown. |
189
+ | `:searchNoResultTemplate` | Inside `data-hs-select` | string (HTML markup) | `"<span></span>"` | This option is only available when `:hasSearch` attribute is `true`. Define a markup for the "no result" text. |
190
+ | `:searchNoResultText` | Inside `data-hs-select` | string | `"No options found..."` | This option is only available when `:hasSearch` attribute is `true`. Defines the text that will be displayed if no results are found. |
191
+ | `:searchNoResultClasses` | Inside `data-hs-select` | string | `"px-4 text-sm"` | This option is only available when `:hasSearch` attribute is `true`. Defines CSS classes for the "no results" wrapper. CSS classes must be separated by a space. |
192
+ | `:optionAllowEmptyOption` | Inside `data-hs-select` | boolean | `false` | This option determines whether an empty option should be included in the list. When set to `true`, an additional option with an empty string (`""`) as its value will be displayed, allowing users to select a blank choice if needed. |
193
+ | `:optionTemplate` | Inside `data-hs-select` | string (HTML markup) | - | Define template for the single option. It could contain: `data-icon` if target option tag has `data-hs-select-option:icon`, `data-title` the text from the target option, `data-description` if target option tag has `data-hs-select-option:description`. |
194
+ | `:optionTag` | Inside `data-hs-select` | string (HTML markup) | - | Define a markup for the single option. |
195
+ | `:optionClasses` | Inside `data-hs-select` | string | - | Define CSS classes for the single option. CSS classes must be separated by a space. |
196
+ | `:optionGroupTemplate` | Inside `data-hs-select` | string (HTML markup) | - | Define template for the single option group. |
197
+ | `:optgroupTag` | Inside `data-hs-select` | string (HTML markup) | - | Define a markup for the single option group. |
198
+ | `:optgroupClasses` | Inside `data-hs-select` | string | - | Define CSS classes for the single option group. CSS classes must be separated by a space. |
199
+ | `:extraMarkup` | Inside `data-hs-select` | string \| array (HTML markup) | - | Define a markup that could be extra added to the wrapper of the select for the decoration reasons. If it contains the `--prevent-click` class, clicking on this element will not trigger the open function. |
200
+ | `:descriptionClasses` | Inside `data-hs-select` | string | - | Define CSS classes for the description inside the single option. CSS classes must be separated by a space. |
201
+ | `:iconClasses` | Inside `data-hs-select` | string | - | Define CSS classes for the icon inside the single option. CSS classes must be separated by a space. |
202
+ | `:isAddTagOnEnter` | Inside `data-hs-select` | boolean | `true` | Determines whether a tag will be added when the enter key is pressed. |
203
+ | `:isSelectedOptionOnTop` | Inside `data-hs-select` | boolean | `false` | Controls whether selected options should appear at the top of the dropdown list. When set to `true`, selected options will be sorted to the top of the list. |
204
+ | `:apiUrl` | Inside `data-hs-select` | string \| null | `null` | Defines the address where the API is located. |
205
+ | `:apiQuery` | Inside `data-hs-select` | string \| null | `null` | Defines query parameters that are separated by `?`. |
206
+ | `:apiOptions` | Inside `data-hs-select` | RequestInit \| null | `null` | Defines options for the fetch function. |
207
+ | `:apiDataPart` | Inside `data-hs-select` | string \| null | `null` | If data is in some first level parameter, then it allows you to specify the name of this parameter to extract the data. |
208
+ | `:apiSearchQueryKey` | Inside `data-hs-select` | string \| null | `null` | Defines the key for the query search parameter. |
209
+ | `:apiFieldsMap` | Inside `data-hs-select` | `{ id: string; title: string; val?: string; icon?: string \| null; description?: string \| null; } \| null` | `null` | Allows you to convert fields from the API to the fields required for the plugin to work. |
210
+ | `:apiLoadMore` | Inside `data-hs-select` | `boolean \| { perPage?: number; scrollThreshold?: number; }` | `false` | Defines the options for the load more feature. |
211
+ | `:apiSelectedValues` | Inside `data-hs-select` | `string \| string[] \| null` | `null` | Allows to preselect values when loading options from an API. Can be a single value or an array of values for multiple selection. |
212
+ | `:apiIconTag` | Inside `data-hs-select` | string \| null | `null` | Allows to define an `img` tag that will be used when rendering options and in the trigger button. |
213
+ | `data-hs-select-option` | Option element | object | - | Allows to define the parameters for the single option. Should be added to the option. |
214
+ | `:description` | Inside `data-hs-select-option` | string | - | Allows to define the description of the option inside the element that have `data-description` attribute. |
215
+ | `:icon` | Inside `data-hs-select-option` | string | - | Allows to define the icon of the option inside the element that have `data-icon` attribute. |
216
+ | `:additinalClasses` | Inside `data-hs-select-option` | `[string, string[]][]` | - | Allows to define additional classes. The first string is the selector of the element to apply the classes to, the second string is an array of classes to apply. If the selector is set to `null`, the classes will be applied to the option itself. |
217
+ | `:apiFields` | Inside `data-hs-select-option` | `{ [key: string]: unknown; }` | - | Allows to define the fields of the option from the API. |
218
+
219
+ ### Tailwind Modifiers
220
+
221
+ | Name | Description |
222
+ | --- | --- |
223
+ | `hs-select-opened:*` | A modifier that allows you to set Tailwind classes when select has been opened. |
224
+ | `hs-select-disabled:*` | A modifier that allows you to set Tailwind classes when select has "disabled" attribute. |
225
+
226
+ ## JavaScript API
227
+
228
+ The `HSSelect` object is available in the global `window` object after the plugin is loaded.
229
+
230
+ ### Instance Methods
231
+
232
+ These methods are called on a select instance.
233
+
234
+ | Method | Parameters | Return Type | Description |
235
+ | --- | --- | --- | --- |
236
+ | `open()` | None | `void` | Opens the dropdown list programmatically. |
237
+ | `close()` | None | `void` | Closes the dropdown list programmatically. |
238
+ | `setValue(value)` | `value`: `string \| string[]` | `void` | Set the select value. This should be a string for a simple select and an array if it's a multiple select. |
239
+ | `addOption(items)` | `items`: `{ title: string; val: string; options?: { description: string; icon: string; }; }` or array of such objects | `void` | Adds an option (several possible) to the select. The single option should follow this interface. |
240
+ | `removeOption(val)` | `val`: `string \| string[]` | `void` | Removes an option by value (several possible). |
241
+ | `recalculateDirection()` | None | `void` | Force recalculation for dropdown list. Useful when dropdown position needs to be updated after layout changes. |
242
+ | `destroy()` | None | `void` | Destroys the select instance, removes all generated markup, classes, and event listeners. Use when removing select from DOM. |
243
+
244
+ ### Static Methods
245
+
246
+ These methods are called directly on the `HSSelect` class.
247
+
248
+ | Method | Parameters | Return Type | Description |
249
+ | --- | --- | --- | --- |
250
+ | `HSSelect.getInstance(target, isInstance)` | `target`: `HTMLElement \| string` (CSS selector)<br>`isInstance`: `boolean` (optional) | `HTMLElement \| { id: string \| number, element: HSSelect } \| null` | Returns the select instance or element associated with the target. If `isInstance` is `true`, returns collection item object `{ id, element }` where `element` is the `HSSelect` instance. If `isInstance` is `false` or omitted, returns the DOM element (`HTMLElement`). Returns `null` if select instance is not found. |
251
+
252
+ ### Usage Examples
253
+
254
+ **Example 1: Opening and closing dropdown**
255
+ ```javascript
256
+ // Get the select instance
257
+ const instance = HSSelect.getInstance('#hs-select', true);
258
+
259
+ if (instance) {
260
+ const { element } = instance;
261
+
262
+ // Open dropdown
263
+ element.open();
264
+
265
+ // Close dropdown
266
+ element.close();
267
+ }
268
+ ```
269
+
270
+ **Example 2: Setting value programmatically**
271
+ ```javascript
272
+ const instance = HSSelect.getInstance('#hs-select', true);
273
+
274
+ if (instance) {
275
+ const { element } = instance;
276
+
277
+ // Set value for single select
278
+ element.setValue('option-value');
279
+
280
+ // Set value for multiple select
281
+ element.setValue(['value-1', 'value-2']);
282
+ }
283
+ ```
284
+
285
+ **Example 3: Adding and removing options**
286
+ ```javascript
287
+ const instance = HSSelect.getInstance('#hs-select', true);
288
+
289
+ if (instance) {
290
+ const { element } = instance;
291
+
292
+ // Add option
293
+ element.addOption({
294
+ title: 'New Option',
295
+ val: 'new-option',
296
+ options: {
297
+ description: 'Option description',
298
+ icon: '<svg>...</svg>'
299
+ }
300
+ });
301
+
302
+ // Remove option
303
+ element.removeOption('new-option');
304
+ }
305
+ ```
306
+
307
+ **Example 4: Destroying select instance**
308
+ ```javascript
309
+ const instance = HSSelect.getInstance('#hs-select', true);
310
+
311
+ if (instance) {
312
+ const { element } = instance;
313
+ const removeBtn = document.querySelector('#hs-remove-btn');
314
+
315
+ removeBtn.addEventListener('click', () => {
316
+ // Clean up before removing from DOM
317
+ element.destroy();
318
+ // Now safe to remove the element
319
+ document.querySelector('#hs-select').remove();
320
+ });
321
+ }
322
+ ```
323
+
324
+ ## Events
325
+
326
+ Select instances emit events that can be listened to for selection lifecycle hooks.
327
+
328
+ | Event Name | When Fired | Callback Parameter | Description |
329
+ | --- | --- | --- | --- |
330
+ | `on:change` | When the selected value changes | `string | string[]` (new selected value; array in multi-select / tags mode) | Fires after the user picks an option or removes a tag. |
331
+
332
+ ### Event Usage Example
333
+
334
+ ```javascript
335
+ // Get select instance
336
+ const instance = HSSelect.getInstance('#hs-select', true);
337
+
338
+ if (instance) {
339
+ const { element } = instance;
340
+
341
+ // Listen for selection changes
342
+ element.on('change', (value) => {
343
+ console.log('Selected value:', value);
344
+ // value is a string for single-select, string[] for multi-select / tags mode
345
+ });
346
+ }
347
+ ```
348
+
349
+ ## Common Patterns
350
+
351
+ ### Pattern 1: Search Enabled
352
+
353
+ Enable search functionality in dropdown.
354
+
355
+ ```html
356
+ <select data-hs-select='{
357
+ "hasSearch": true,
358
+ "searchPlaceholder": "Search options..."
359
+ }'>
360
+ <!-- Options -->
361
+ </select>
362
+ ```
363
+
364
+ ### Pattern 2: Tags Mode
365
+
366
+ Use tags mode for multiple selections.
367
+
368
+ ```html
369
+ <select multiple data-hs-select='{
370
+ "mode": "tags"
371
+ }'>
372
+ <!-- Options -->
373
+ </select>
374
+ ```
375
+
376
+ ### Pattern 3: API Integration
377
+
378
+ Load options from API.
379
+
380
+ ```html
381
+ <select data-hs-select='{
382
+ "apiUrl": "/api/options",
383
+ "apiFieldsMap": {
384
+ "id": "id",
385
+ "title": "name",
386
+ "val": "value"
387
+ }
388
+ }'>
389
+ <!-- Options -->
390
+ </select>
391
+ ```
392
+
393
+ ## License
394
+
395
+ Copyright (c) 2026 Preline Labs.
396
+
397
+ Licensed under the [MIT License](https://opensource.org/licenses/MIT).
package/index.d.ts CHANGED
@@ -222,6 +222,7 @@ declare class HSSelect extends HSBasePlugin<ISelectOptions> implements ISelect {
222
222
  private lastQuery;
223
223
  private readonly apiPageStart?;
224
224
  private readonly apiTotalPath?;
225
+ private isLoadEventFired;
225
226
  private optionId;
226
227
  private onWrapperClickListener;
227
228
  private onToggleClickListener;
@@ -244,6 +245,7 @@ declare class HSSelect extends HSBasePlugin<ISelectOptions> implements ISelect {
244
245
  private hasValue;
245
246
  private init;
246
247
  private build;
248
+ private fireLoadEvent;
247
249
  private setOptions;
248
250
  private buildWrapper;
249
251
  private buildExtraMarkup;
@@ -261,6 +263,14 @@ declare class HSSelect extends HSBasePlugin<ISelectOptions> implements ISelect {
261
263
  private setupInfiniteScroll;
262
264
  private handleScroll;
263
265
  private loadMore;
266
+ /**
267
+ * Positions the dropdown using Floating UI when `dropdownScope` is set to `"window"`.
268
+ *
269
+ * Requires `@floating-ui/dom` to be loaded on the page (e.g. via CDN or npm).
270
+ * Used by: `dropdownScope: "window"`, `dropdownPlacement`, `dropdownAutoPlacement`.
271
+ *
272
+ * @see https://floating-ui.com
273
+ */
264
274
  private buildFloatingUI;
265
275
  private updateDropdownWidth;
266
276
  private buildSearch;