svelte-multiselect 11.5.0 → 11.5.1

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.
@@ -0,0 +1,1675 @@
1
+ <!-- eslint-disable-next-line @stylistic/quotes -- TS generics require string literals -->
2
+ <script lang="ts" generics="Option extends import('./types').Option">import { tick, untrack } from 'svelte';
3
+ import { flip } from 'svelte/animate';
4
+ import { SvelteMap, SvelteSet } from 'svelte/reactivity';
5
+ import { highlight_matches } from './attachments';
6
+ import CircleSpinner from './CircleSpinner.svelte';
7
+ import Icon from './Icon.svelte';
8
+ import { fuzzy_match, get_label, get_style, has_group, is_object } from './utils';
9
+ import Wiggle from './Wiggle.svelte';
10
+ let { activeIndex = $bindable(null), activeOption = $bindable(null), createOptionMsg = `Create this option...`, allowUserOptions = false, allowEmpty = false, autocomplete = `off`, autoScroll = true, breakpoint = 800, defaultDisabledTitle = `This option is disabled`, disabled = false, disabledInputTitle = `This input is disabled`, duplicateOptionMsg = `This option is already selected`, duplicates = false, keepSelectedInDropdown = false, key = (opt) => `${get_label(opt)}`.toLowerCase(), filterFunc = (opt, searchText) => {
11
+ if (!searchText)
12
+ return true;
13
+ const label = `${get_label(opt)}`;
14
+ return fuzzy
15
+ ? fuzzy_match(searchText, label)
16
+ : label.toLowerCase().includes(searchText.toLowerCase());
17
+ }, fuzzy = true, closeDropdownOnSelect = false, form_input = $bindable(null), highlightMatches = true, id = null, input = $bindable(null), inputClass = ``, inputStyle = null, inputmode = null, invalid = $bindable(false), liActiveOptionClass = ``, liActiveUserMsgClass = ``, liOptionClass = ``, liOptionStyle = null, liSelectedClass = ``, liSelectedStyle = null, liUserMsgClass = ``, loading = false, matchingOptions = $bindable([]), maxOptions = undefined, maxSelect = $bindable(null), maxSelectMsg = (current, max) => (max > 1 ? `${current}/${max}` : ``), maxSelectMsgClass = ``, name = null, noMatchingOptionsMsg = `No matching options`, open = $bindable(false), options = $bindable(), outerDiv = $bindable(null), outerDivClass = ``, parseLabelsAsHtml = false, pattern = null, placeholder = null, removeAllTitle = `Remove all`, removeBtnTitle = `Remove`, minSelect = null, required = false, resetFilterOnAdd = true, searchText = $bindable(``), value = $bindable(null), selected = $bindable(value !== null && value !== undefined
18
+ ? (Array.isArray(value) ? value : [value])
19
+ : (options
20
+ ?.filter((opt) => typeof opt === `object` && opt !== null && opt?.preselected)
21
+ .slice(0, maxSelect ?? undefined) ?? [])), sortSelected = false, selectedOptionsDraggable = !sortSelected, style = null, ulOptionsClass = ``, ulSelectedClass = ``, ulSelectedStyle = null, ulOptionsStyle = null, expandIcon, selectedItem, children, removeIcon, afterInput, spinner, disabledIcon, option, userMsg, onblur, onclick, onfocus, onkeydown, onkeyup, onmousedown, onmouseenter, onmouseleave, ontouchcancel, ontouchend, ontouchmove, ontouchstart, onadd, oncreate, onremove, onremoveAll, onchange, onopen, onclose, onselectAll, onreorder, portal: portal_params = {},
22
+ // Select all feature
23
+ selectAllOption = false, liSelectAllClass = ``,
24
+ // Dynamic options loading
25
+ loadOptions,
26
+ // Animation parameters for selected options flip animation
27
+ selectedFlipParams = { duration: 100 },
28
+ // Option grouping feature
29
+ collapsibleGroups = false, collapsedGroups = $bindable(new Set()), groupSelectAll = false, ungroupedPosition = `first`, groupSortOrder = `none`, searchExpandsCollapsedGroups = false, searchMatchesGroups = false, keyboardExpandsCollapsedGroups = false, stickyGroupHeaders = false, liGroupHeaderClass = ``, liGroupHeaderStyle = null, groupHeader, ongroupToggle, oncollapseAll, onexpandAll, collapseAllGroups = $bindable(), expandAllGroups = $bindable(),
30
+ // Keyboard shortcuts for common actions
31
+ shortcuts = {}, ...rest } = $props();
32
+ // Generate unique IDs for ARIA associations (combobox pattern)
33
+ // Uses provided id prop or generates a random one using crypto API
34
+ const internal_id = $derived(id ?? `sms-${crypto.randomUUID().slice(0, 8)}`);
35
+ const listbox_id = $derived(`${internal_id}-listbox`);
36
+ // Parse shortcut string into modifier+key parts
37
+ function parse_shortcut(shortcut) {
38
+ const parts = shortcut.toLowerCase().split(`+`).map((part) => part.trim());
39
+ const key = parts.pop() ?? ``;
40
+ return {
41
+ key,
42
+ ctrl: parts.includes(`ctrl`),
43
+ shift: parts.includes(`shift`),
44
+ alt: parts.includes(`alt`),
45
+ meta: parts.includes(`meta`) || parts.includes(`cmd`),
46
+ };
47
+ }
48
+ function matches_shortcut(event, shortcut) {
49
+ if (!shortcut)
50
+ return false;
51
+ const parsed = parse_shortcut(shortcut);
52
+ // Require non-empty key to prevent "ctrl+" from matching any key with ctrl pressed
53
+ if (!parsed.key)
54
+ return false;
55
+ const key_matches = event.key.toLowerCase() === parsed.key;
56
+ const ctrl_matches = event.ctrlKey === parsed.ctrl;
57
+ const shift_matches = event.shiftKey === parsed.shift;
58
+ const alt_matches = event.altKey === parsed.alt;
59
+ const meta_matches = event.metaKey === parsed.meta;
60
+ return (key_matches && ctrl_matches && shift_matches && alt_matches && meta_matches);
61
+ }
62
+ // Default shortcuts
63
+ const default_shortcuts = {
64
+ select_all: `ctrl+a`,
65
+ clear_all: `ctrl+shift+a`,
66
+ open: null,
67
+ close: null,
68
+ };
69
+ const effective_shortcuts = $derived({
70
+ ...default_shortcuts,
71
+ ...shortcuts,
72
+ });
73
+ // Extract loadOptions config into single derived object (supports both simple function and config object)
74
+ const load_options_config = $derived.by(() => {
75
+ if (!loadOptions)
76
+ return null;
77
+ const is_fn = typeof loadOptions === `function`;
78
+ return {
79
+ fetch: is_fn ? loadOptions : loadOptions.fetch,
80
+ debounce_ms: is_fn ? 300 : (loadOptions.debounceMs ?? 300),
81
+ batch_size: is_fn ? 50 : (loadOptions.batchSize ?? 50),
82
+ on_open: is_fn ? true : (loadOptions.onOpen ?? true),
83
+ };
84
+ });
85
+ // Helper to compare arrays/values for equality to avoid unnecessary updates.
86
+ // Prevents infinite loops when value/selected are bound to reactive wrappers
87
+ // that clone arrays on assignment (e.g. Superforms, Svelte stores). See issue #309.
88
+ // Treats null/undefined/[] as equivalent empty states to prevent extra updates on init (#369).
89
+ function values_equal(val1, val2) {
90
+ if (val1 === val2)
91
+ return true;
92
+ const empty1 = val1 == null || (Array.isArray(val1) && val1.length === 0);
93
+ const empty2 = val2 == null || (Array.isArray(val2) && val2.length === 0);
94
+ if (empty1 && empty2)
95
+ return true;
96
+ if (Array.isArray(val1) && Array.isArray(val2)) {
97
+ return val1.length === val2.length &&
98
+ val1.every((item, idx) => item === val2[idx]);
99
+ }
100
+ return false;
101
+ }
102
+ // Sync selected ↔ value bidirectionally. Use untrack to prevent each effect from
103
+ // reacting to changes in the "destination" value, and values_equal to prevent
104
+ // infinite loops with reactive wrappers that clone arrays. See issue #309.
105
+ $effect.pre(() => {
106
+ const new_value = maxSelect === 1 ? (selected[0] ?? null) : selected;
107
+ if (!values_equal(untrack(() => value), new_value))
108
+ value = new_value;
109
+ });
110
+ $effect.pre(() => {
111
+ const new_selected = maxSelect === 1
112
+ ? (value ? [value] : [])
113
+ : (Array.isArray(value) ? value : []);
114
+ if (!values_equal(untrack(() => selected), new_selected))
115
+ selected = new_selected;
116
+ });
117
+ let wiggle = $state(false); // controls wiggle animation when user tries to exceed maxSelect
118
+ let ignore_hover = $state(false); // ignore mouseover during keyboard navigation to prevent scroll-triggered hover
119
+ // Track last selection action for aria-live announcements
120
+ let last_action = $state(null);
121
+ // Clear last_action after announcement so option counts can be announced again
122
+ $effect(() => {
123
+ if (last_action) {
124
+ const timer = setTimeout(() => (last_action = null), 1000);
125
+ return () => clearTimeout(timer);
126
+ }
127
+ });
128
+ // Internal state for loadOptions feature (null = never loaded)
129
+ let loaded_options = $state([]);
130
+ let load_options_has_more = $state(true);
131
+ let load_options_loading = $state(false);
132
+ let load_options_last_search = $state(null);
133
+ let debounce_timer = null;
134
+ let effective_options = $derived(loadOptions ? loaded_options : (options ?? []));
135
+ // Cache selected keys and labels to avoid repeated .map() calls
136
+ let selected_keys = $derived(selected.map(key));
137
+ let selected_labels = $derived(selected.map(get_label));
138
+ // Sets for O(1) lookups (used in template, has_user_msg, group_header_state, batch operations)
139
+ let selected_keys_set = $derived(new Set(selected_keys));
140
+ let selected_labels_set = $derived(new Set(selected_labels));
141
+ // Memoized Set of disabled option keys for O(1) lookups in large option sets
142
+ let disabled_option_keys = $derived(new Set(effective_options
143
+ .filter((opt) => is_object(opt) && opt.disabled)
144
+ .map(key)));
145
+ // Check if an option is disabled (uses memoized Set for O(1) lookup)
146
+ const is_disabled = (opt) => disabled_option_keys.has(key(opt));
147
+ // Group matching options by their `group` key
148
+ // Note: SvelteMap used here to satisfy eslint svelte/prefer-svelte-reactivity rule,
149
+ // though a plain Map would work since this is recreated fresh on each derivation
150
+ let grouped_options = $derived.by(() => {
151
+ const groups_map = new SvelteMap();
152
+ const ungrouped = [];
153
+ for (const opt of matchingOptions) {
154
+ if (has_group(opt)) {
155
+ const existing = groups_map.get(opt.group);
156
+ if (existing)
157
+ existing.push(opt);
158
+ else
159
+ groups_map.set(opt.group, [opt]);
160
+ }
161
+ else {
162
+ ungrouped.push(opt);
163
+ }
164
+ }
165
+ let grouped = [...groups_map.entries()].map(([group, options]) => ({
166
+ group,
167
+ options,
168
+ collapsed: collapsedGroups.has(group),
169
+ }));
170
+ // Apply group sorting if specified
171
+ if (groupSortOrder && groupSortOrder !== `none`) {
172
+ grouped = grouped.toSorted((group_a, group_b) => {
173
+ if (typeof groupSortOrder === `function`) {
174
+ return groupSortOrder(group_a.group, group_b.group);
175
+ }
176
+ const cmp = group_a.group.localeCompare(group_b.group);
177
+ return groupSortOrder === `desc` ? -cmp : cmp;
178
+ });
179
+ }
180
+ if (ungrouped.length === 0)
181
+ return grouped;
182
+ const ungrouped_entry = { group: null, options: ungrouped, collapsed: false };
183
+ return ungroupedPosition === `first`
184
+ ? [ungrouped_entry, ...grouped]
185
+ : [...grouped, ungrouped_entry];
186
+ });
187
+ // Flattened options for navigation (excludes options in collapsed groups)
188
+ let navigable_options = $derived(grouped_options.flatMap(({ options: group_opts, collapsed }) => collapsed && collapsibleGroups ? [] : group_opts));
189
+ // Pre-computed Map for O(1) index lookups (avoids O(n²) in template)
190
+ let navigable_index_map = $derived(new Map(navigable_options.map((opt, idx) => [opt, idx])));
191
+ let group_header_state = $derived.by(() => {
192
+ const state = new SvelteMap();
193
+ for (const { group, options: opts, collapsed } of grouped_options) {
194
+ if (group === null)
195
+ continue;
196
+ const selectable = get_selectable_opts(opts, collapsed);
197
+ const all_selected = selectable.length > 0 &&
198
+ selectable.every((opt) => selected_keys_set.has(key(opt)));
199
+ // Count selected options (only needed when keepSelectedInDropdown is enabled)
200
+ let selected_count = 0;
201
+ if (keepSelectedInDropdown) {
202
+ for (const opt of opts) {
203
+ if (selected_keys_set.has(key(opt)))
204
+ selected_count++;
205
+ }
206
+ }
207
+ state.set(group, { all_selected, selected_count });
208
+ }
209
+ return state;
210
+ });
211
+ // Update collapsedGroups state: 'add' adds groups, 'delete' removes groups, 'set' replaces all
212
+ function update_collapsed_groups(action, groups) {
213
+ const items = typeof groups === `string` ? [groups] : [...groups];
214
+ if (action === `set`)
215
+ collapsedGroups = new SvelteSet(items);
216
+ else {
217
+ const updated = new SvelteSet(collapsedGroups);
218
+ for (const group of items)
219
+ updated[action](group);
220
+ collapsedGroups = updated;
221
+ }
222
+ }
223
+ // Toggle group collapsed state
224
+ function toggle_group_collapsed(group_name) {
225
+ const was_collapsed = collapsedGroups.has(group_name);
226
+ update_collapsed_groups(was_collapsed ? `delete` : `add`, group_name);
227
+ ongroupToggle?.({ group: group_name, collapsed: !was_collapsed });
228
+ }
229
+ // Collapse/expand all groups (exposed via bindable props)
230
+ collapseAllGroups = () => {
231
+ const groups = grouped_options
232
+ .map((entry) => entry.group)
233
+ .filter((group_name) => group_name !== null);
234
+ if (groups.length === 0)
235
+ return;
236
+ update_collapsed_groups(`set`, groups);
237
+ oncollapseAll?.({ groups });
238
+ };
239
+ expandAllGroups = () => {
240
+ const groups = [...collapsedGroups];
241
+ if (groups.length === 0)
242
+ return;
243
+ update_collapsed_groups(`set`, []);
244
+ onexpandAll?.({ groups });
245
+ };
246
+ // Expand specified groups and fire ongroupToggle for each
247
+ function expand_groups(groups_to_expand) {
248
+ if (groups_to_expand.length === 0)
249
+ return;
250
+ update_collapsed_groups(`delete`, groups_to_expand);
251
+ for (const group of groups_to_expand)
252
+ ongroupToggle?.({ group, collapsed: false });
253
+ }
254
+ // Get names of collapsed groups that have matching options
255
+ const get_collapsed_with_matches = () => grouped_options.flatMap(({ group, collapsed, options: opts }) => group && collapsed && opts.length > 0 ? [group] : []);
256
+ // Auto-expand collapsed groups when search matches their options
257
+ $effect(() => {
258
+ if (searchExpandsCollapsedGroups && searchText && collapsibleGroups) {
259
+ expand_groups(get_collapsed_with_matches());
260
+ }
261
+ });
262
+ // Normalize placeholder prop (supports string or { text, persistent } object)
263
+ const placeholder_text = $derived(typeof placeholder === `string` ? placeholder : placeholder?.text ?? null);
264
+ const placeholder_persistent = $derived(typeof placeholder === `object` && placeholder?.persistent === true);
265
+ // Helper to sort selected options (used by add() and select_all())
266
+ function sort_selected(items) {
267
+ if (sortSelected === true) {
268
+ return items.toSorted((op1, op2) => `${get_label(op1)}`.localeCompare(`${get_label(op2)}`));
269
+ }
270
+ else if (typeof sortSelected === `function`) {
271
+ return items.toSorted(sortSelected);
272
+ }
273
+ return items;
274
+ }
275
+ if (!loadOptions && !((options?.length ?? 0) > 0)) {
276
+ if (allowUserOptions || loading || disabled || allowEmpty) {
277
+ options = []; // initializing as array avoids errors when component mounts
278
+ }
279
+ else {
280
+ // error on empty options if user is not allowed to create custom options and loading is false
281
+ // and component is not disabled and allowEmpty is false
282
+ console.error(`MultiSelect: received no options`);
283
+ }
284
+ }
285
+ if (maxSelect !== null && maxSelect < 1) {
286
+ console.error(`MultiSelect: maxSelect must be null or positive integer, got ${maxSelect}`);
287
+ }
288
+ if (!Array.isArray(selected)) {
289
+ console.error(`MultiSelect: selected prop should always be an array, got ${selected}`);
290
+ }
291
+ if (maxSelect && typeof required === `number` && required > maxSelect) {
292
+ console.error(`MultiSelect: maxSelect=${maxSelect} < required=${required}, makes it impossible for users to submit a valid form`);
293
+ }
294
+ if (parseLabelsAsHtml && allowUserOptions) {
295
+ console.warn(`MultiSelect: don't combine parseLabelsAsHtml and allowUserOptions. It's susceptible to XSS attacks!`);
296
+ }
297
+ if (sortSelected && selectedOptionsDraggable) {
298
+ console.warn(`MultiSelect: sortSelected and selectedOptionsDraggable should not be combined as any ` +
299
+ `user re-orderings of selected options will be undone by sortSelected on component re-renders.`);
300
+ }
301
+ if (allowUserOptions && !createOptionMsg && createOptionMsg !== null) {
302
+ console.error(`MultiSelect: allowUserOptions=${allowUserOptions} but createOptionMsg=${createOptionMsg} is falsy. ` +
303
+ `This prevents the "Add option" <span> from showing up, resulting in a confusing user experience.`);
304
+ }
305
+ if (maxOptions &&
306
+ (typeof maxOptions != `number` || maxOptions < 0 || maxOptions % 1 != 0)) {
307
+ console.error(`MultiSelect: maxOptions must be undefined or a positive integer, got ${maxOptions}`);
308
+ }
309
+ let option_msg_is_active = $state(false); // controls active state of <li>{createOptionMsg}</li>
310
+ let window_width = $state(0);
311
+ // Check if option matches search text (label or optionally group name)
312
+ const matches_search = (opt, search) => {
313
+ if (filterFunc(opt, search))
314
+ return true;
315
+ if (searchMatchesGroups && search && has_group(opt)) {
316
+ return fuzzy
317
+ ? fuzzy_match(search, opt.group)
318
+ : opt.group.toLowerCase().includes(search.toLowerCase());
319
+ }
320
+ return false;
321
+ };
322
+ $effect.pre(() => {
323
+ // When using loadOptions, server handles filtering, so skip client-side filterFunc
324
+ matchingOptions = effective_options.filter((opt) => {
325
+ // Check if option is already selected and should be excluded
326
+ const keep_in_list = !selected_keys_set.has(key(opt)) ||
327
+ duplicates ||
328
+ keepSelectedInDropdown;
329
+ if (!keep_in_list)
330
+ return false;
331
+ // When using loadOptions, server handles filtering; otherwise check search match
332
+ return loadOptions || matches_search(opt, searchText);
333
+ });
334
+ });
335
+ // reset activeIndex if out of bounds (can happen when options change while dropdown is open)
336
+ $effect(() => {
337
+ if (activeIndex !== null && !navigable_options[activeIndex]) {
338
+ activeIndex = null;
339
+ }
340
+ });
341
+ // update activeOption when activeIndex changes
342
+ $effect(() => {
343
+ activeOption = navigable_options[activeIndex ?? -1] ?? null;
344
+ });
345
+ // Compute the ID of the currently active option for aria-activedescendant
346
+ const active_option_id = $derived(activeIndex !== null && activeIndex < navigable_options.length
347
+ ? `${internal_id}-opt-${activeIndex}`
348
+ : undefined);
349
+ // Helper to check if removing an option would violate minSelect constraint
350
+ const can_remove = $derived(minSelect === null || selected.length > minSelect);
351
+ // toggle an option between selected and unselected states (for keepSelectedInDropdown mode)
352
+ function toggle_option(option_to_toggle, event) {
353
+ const is_currently_selected = selected_keys_set.has(key(option_to_toggle));
354
+ if (is_currently_selected) {
355
+ if (can_remove)
356
+ remove(option_to_toggle, event);
357
+ }
358
+ else
359
+ add(option_to_toggle, event);
360
+ }
361
+ // add an option to selected list
362
+ function add(option_to_add, event) {
363
+ event.stopPropagation();
364
+ if (maxSelect !== null && selected.length >= maxSelect)
365
+ wiggle = true;
366
+ if (!isNaN(Number(option_to_add)) && typeof selected_labels[0] === `number`) {
367
+ option_to_add = Number(option_to_add); // convert to number if possible
368
+ }
369
+ const is_duplicate = selected_keys_set.has(key(option_to_add));
370
+ if ((maxSelect === null || maxSelect === 1 || selected.length < maxSelect) &&
371
+ (duplicates || !is_duplicate)) {
372
+ if (!effective_options.includes(option_to_add) && // first check if we find option in the options list
373
+ // this has the side-effect of not allowing to user to add the same
374
+ // custom option twice in append mode
375
+ [true, `append`].includes(allowUserOptions) &&
376
+ searchText.length > 0) {
377
+ // user entered text but no options match, so if allowUserOptions = true | 'append', we create
378
+ // a new option from the user-entered text
379
+ if (typeof effective_options[0] === `object`) {
380
+ // if 1st option is an object, we create new option as object to keep type homogeneity
381
+ option_to_add = { label: searchText };
382
+ }
383
+ else {
384
+ if ([`number`, `undefined`].includes(typeof effective_options[0]) &&
385
+ !isNaN(Number(searchText))) {
386
+ // create new option as number if it parses to a number and 1st option is also number or missing
387
+ option_to_add = Number(searchText);
388
+ }
389
+ else {
390
+ option_to_add = searchText; // else create custom option as string
391
+ }
392
+ }
393
+ // Fire oncreate event for all user-created options, regardless of type
394
+ oncreate?.({ option: option_to_add });
395
+ if (allowUserOptions === `append`) {
396
+ if (loadOptions) {
397
+ loaded_options = [...loaded_options, option_to_add];
398
+ }
399
+ else {
400
+ options = [...(options ?? []), option_to_add];
401
+ }
402
+ }
403
+ }
404
+ if (resetFilterOnAdd)
405
+ searchText = ``; // reset search string on selection
406
+ if ([``, undefined, null].includes(option_to_add)) {
407
+ console.error(`MultiSelect: encountered falsy option`, option_to_add);
408
+ return;
409
+ }
410
+ // for maxSelect = 1 we always replace current option with new one
411
+ if (maxSelect === 1)
412
+ selected = [option_to_add];
413
+ else {
414
+ selected = sort_selected([...selected, option_to_add]);
415
+ }
416
+ clear_validity();
417
+ handle_dropdown_after_select(event);
418
+ last_action = { type: `add`, label: `${get_label(option_to_add)}` };
419
+ onadd?.({ option: option_to_add });
420
+ onchange?.({ option: option_to_add, type: `add` });
421
+ }
422
+ }
423
+ // remove an option from selected list
424
+ function remove(option_to_drop, event) {
425
+ event.stopPropagation();
426
+ if (selected.length === 0)
427
+ return;
428
+ const idx = selected.findIndex((opt) => key(opt) === key(option_to_drop));
429
+ let option_removed = selected[idx];
430
+ if (option_removed === undefined && allowUserOptions) {
431
+ // if option with label could not be found but allowUserOptions is truthy,
432
+ // assume it was created by user and create corresponding option object
433
+ // on the fly for use as event payload
434
+ const is_object_option = typeof effective_options[0] === `object`;
435
+ option_removed = (is_object_option ? { label: option_to_drop } : option_to_drop);
436
+ }
437
+ if (option_removed === undefined) {
438
+ console.error(`MultiSelect: can't remove option ${JSON.stringify(option_to_drop)}, not found in selected list`);
439
+ return;
440
+ }
441
+ selected = selected.filter((_, remove_idx) => remove_idx !== idx);
442
+ clear_validity();
443
+ last_action = { type: `remove`, label: `${get_label(option_removed)}` };
444
+ onremove?.({ option: option_removed });
445
+ onchange?.({ option: option_removed, type: `remove` });
446
+ }
447
+ function open_dropdown(event) {
448
+ event.stopPropagation();
449
+ if (disabled)
450
+ return;
451
+ open = true;
452
+ if (!(event instanceof FocusEvent)) {
453
+ // avoid double-focussing input when event that opened dropdown was already input FocusEvent
454
+ input?.focus();
455
+ }
456
+ onopen?.({ event });
457
+ }
458
+ function close_dropdown(event, retain_focus = false) {
459
+ open = false;
460
+ if (!retain_focus)
461
+ input?.blur();
462
+ activeIndex = null;
463
+ onclose?.({ event });
464
+ }
465
+ function clear_validity() {
466
+ invalid = false;
467
+ form_input?.setCustomValidity(``);
468
+ }
469
+ function handle_dropdown_after_select(event) {
470
+ const reached_max = selected.length >= (maxSelect ?? Infinity);
471
+ const should_close = closeDropdownOnSelect === true ||
472
+ closeDropdownOnSelect === `retain-focus` ||
473
+ (closeDropdownOnSelect === `if-mobile` && window_width &&
474
+ window_width < breakpoint);
475
+ if (reached_max || should_close) {
476
+ close_dropdown(event, closeDropdownOnSelect === `retain-focus`);
477
+ }
478
+ else
479
+ input?.focus();
480
+ }
481
+ // Check if a user message (create option, duplicate warning, no match) is visible
482
+ const has_user_msg = $derived(searchText.length > 0 && Boolean((allowUserOptions && createOptionMsg) ||
483
+ (!duplicates && selected_labels_set.has(searchText)) ||
484
+ (navigable_options.length === 0 && noMatchingOptionsMsg)));
485
+ // Handle arrow key navigation through options (uses navigable_options to skip collapsed groups)
486
+ async function handle_arrow_navigation(direction) {
487
+ ignore_hover = true;
488
+ // Auto-expand collapsed groups when keyboard navigating
489
+ if (keyboardExpandsCollapsedGroups && collapsibleGroups && collapsedGroups.size > 0) {
490
+ expand_groups(get_collapsed_with_matches());
491
+ await tick();
492
+ }
493
+ // toggle user message when no options match but user can create
494
+ if (allowUserOptions && !navigable_options.length && searchText.length > 0) {
495
+ option_msg_is_active = !option_msg_is_active;
496
+ return;
497
+ }
498
+ if (activeIndex === null && !navigable_options.length)
499
+ return; // nothing to navigate
500
+ // activate first option or navigate with wrap-around
501
+ if (activeIndex === null) {
502
+ activeIndex = 0;
503
+ }
504
+ else {
505
+ const total = navigable_options.length + (has_user_msg ? 1 : 0);
506
+ activeIndex = (activeIndex + direction + total) % total; // +total handles negative mod
507
+ }
508
+ // update active state based on new index
509
+ option_msg_is_active = has_user_msg && activeIndex === navigable_options.length;
510
+ activeOption = option_msg_is_active
511
+ ? null
512
+ : navigable_options[activeIndex] ?? null;
513
+ if (autoScroll) {
514
+ await tick();
515
+ document.querySelector(`ul.options > li.active`)?.scrollIntoViewIfNeeded?.();
516
+ }
517
+ }
518
+ // handle all keyboard events this component receives
519
+ async function handle_keydown(event) {
520
+ if (disabled)
521
+ return; // Block all keyboard handling when disabled
522
+ // Check keyboard shortcuts first (before other key handling)
523
+ const shortcut_actions = [
524
+ {
525
+ key: `select_all`,
526
+ condition: () => !!selectAllOption && navigable_options.length > 0 && maxSelect !== 1,
527
+ action: () => select_all(event),
528
+ },
529
+ {
530
+ key: `clear_all`,
531
+ condition: () => selected.length > 0,
532
+ action: () => remove_all(event),
533
+ },
534
+ {
535
+ key: `open`,
536
+ condition: () => !open,
537
+ action: () => open_dropdown(event),
538
+ },
539
+ {
540
+ key: `close`,
541
+ condition: () => open,
542
+ action: () => {
543
+ close_dropdown(event);
544
+ searchText = ``;
545
+ },
546
+ },
547
+ ];
548
+ for (const { key, condition, action } of shortcut_actions) {
549
+ if (matches_shortcut(event, effective_shortcuts[key]) && condition()) {
550
+ event.preventDefault();
551
+ event.stopPropagation();
552
+ action();
553
+ return;
554
+ }
555
+ }
556
+ // on escape or tab out of input: close options dropdown and reset search text
557
+ if (event.key === `Escape` || event.key === `Tab`) {
558
+ event.stopPropagation();
559
+ close_dropdown(event);
560
+ searchText = ``;
561
+ } // on enter key: toggle active option
562
+ else if (event.key === `Enter`) {
563
+ event.stopPropagation();
564
+ event.preventDefault(); // prevent enter key from triggering form submission
565
+ if (activeOption) {
566
+ if (selected_keys_set.has(key(activeOption))) {
567
+ if (can_remove)
568
+ remove(activeOption, event);
569
+ }
570
+ else
571
+ add(activeOption, event); // add() handles resetFilterOnAdd internally when successful
572
+ }
573
+ else if (allowUserOptions && searchText.length > 0) {
574
+ // user entered text but no options match, so if allowUserOptions is truthy, we create new option
575
+ add(searchText, event);
576
+ }
577
+ else {
578
+ // no active option and no search text means the options dropdown is closed
579
+ // in which case enter means open it
580
+ open_dropdown(event);
581
+ }
582
+ } // on up/down arrow keys: update active option
583
+ else if (event.key === `ArrowDown` || event.key === `ArrowUp`) {
584
+ event.stopPropagation();
585
+ event.preventDefault();
586
+ await handle_arrow_navigation(event.key === `ArrowUp` ? -1 : 1);
587
+ } // on backspace key: remove last selected option
588
+ else if (event.key === `Backspace` && selected.length > 0 && !searchText) {
589
+ event.stopPropagation();
590
+ if (can_remove) {
591
+ const last_option = selected.at(-1);
592
+ if (last_option)
593
+ remove(last_option, event);
594
+ }
595
+ // Don't prevent default, allow normal backspace behavior if not removing
596
+ } // make first matching option active on any keypress (if none of the above special cases match)
597
+ else if (navigable_options.length > 0 && activeIndex === null) {
598
+ // Don't stop propagation or prevent default here, allow normal character input
599
+ activeIndex = 0;
600
+ }
601
+ }
602
+ function remove_all(event) {
603
+ event.stopPropagation();
604
+ // Keep the first minSelect items, remove the rest
605
+ let removed_options = [];
606
+ if (minSelect === null) {
607
+ // If no minSelect constraint, remove all
608
+ removed_options = selected;
609
+ selected = [];
610
+ }
611
+ else if (selected.length > minSelect) {
612
+ // Keep the first minSelect items
613
+ removed_options = selected.slice(minSelect);
614
+ selected = selected.slice(0, minSelect);
615
+ }
616
+ // Only fire events if something was actually removed
617
+ if (removed_options.length > 0) {
618
+ searchText = ``; // always clear on remove all (resetFilterOnAdd only applies to add operations)
619
+ last_action = { type: `removeAll`, label: `${removed_options.length} options` };
620
+ onremoveAll?.({ options: removed_options });
621
+ onchange?.({ options: selected, type: `removeAll` });
622
+ }
623
+ }
624
+ // Check if option index is within maxOptions visibility limit
625
+ const is_option_visible = (idx) => idx >= 0 && (maxOptions == null || idx < maxOptions);
626
+ // Get non-disabled, selectable options from a list
627
+ // For collapsed groups: returns all non-disabled options (user explicitly wants this group)
628
+ // For expanded groups/top-level: respects maxOptions rendering limit
629
+ const get_selectable_opts = (opts, skip_visibility_check = false) => opts.filter((opt) => {
630
+ if (is_disabled(opt))
631
+ return false;
632
+ if (skip_visibility_check)
633
+ return true;
634
+ return is_option_visible(navigable_index_map.get(opt) ?? -1);
635
+ });
636
+ // Batch-add options to selection with all side effects (used by select_all and group select)
637
+ function batch_add_options(options_to_add, event) {
638
+ const remaining = Math.max(0, (maxSelect ?? Infinity) - selected.length);
639
+ const to_add = options_to_add
640
+ .filter((opt) => !selected_keys_set.has(key(opt)))
641
+ .slice(0, remaining);
642
+ if (to_add.length === 0)
643
+ return;
644
+ selected = sort_selected([...selected, ...to_add]);
645
+ if (resetFilterOnAdd)
646
+ searchText = ``;
647
+ clear_validity();
648
+ handle_dropdown_after_select(event);
649
+ onselectAll?.({ options: to_add });
650
+ onchange?.({ options: selected, type: `selectAll` });
651
+ }
652
+ // Batch-add options for top-level "Select all" (only visible/navigable options)
653
+ function select_all(event) {
654
+ event.stopPropagation();
655
+ batch_add_options(get_selectable_opts(navigable_options), event);
656
+ }
657
+ // Toggle group selection: works even when group is collapsed
658
+ // If all selectable options are selected, deselect them; otherwise select all
659
+ function toggle_group_selection(group_opts, group_collapsed, all_selected, event) {
660
+ event.stopPropagation();
661
+ const selectable = get_selectable_opts(group_opts, group_collapsed);
662
+ if (all_selected) {
663
+ // Deselect all options in this group
664
+ const keys_to_remove = new Set(selectable.map(key));
665
+ const removed = selected.filter((opt) => keys_to_remove.has(key(opt)));
666
+ selected = selected.filter((opt) => !keys_to_remove.has(key(opt)));
667
+ if (removed.length > 0) {
668
+ onremoveAll?.({ options: removed });
669
+ onchange?.({ options: selected, type: `removeAll` });
670
+ }
671
+ }
672
+ else {
673
+ // Select all non-disabled, non-selected options in this group
674
+ batch_add_options(selectable, event);
675
+ }
676
+ }
677
+ // O(1) lookup using pre-computed Set instead of O(n) array.includes()
678
+ const is_selected = (label) => selected_labels_set.has(label);
679
+ const if_enter_or_space = (handler) => (event) => {
680
+ if (event.key === `Enter` || event.code === `Space`) {
681
+ event.preventDefault();
682
+ handler(event);
683
+ }
684
+ };
685
+ // Handle option interaction (click or keyboard) - DRY helper for template
686
+ const handle_option_interact = (opt, opt_disabled, event) => {
687
+ if (opt_disabled)
688
+ return;
689
+ if (keepSelectedInDropdown)
690
+ toggle_option(opt, event);
691
+ else
692
+ add(opt, event);
693
+ };
694
+ function on_click_outside(event) {
695
+ if (!outerDiv)
696
+ return;
697
+ const target = event.target;
698
+ // Check if click is inside the main component
699
+ if (outerDiv.contains(target))
700
+ return;
701
+ // If portal is active, also check if click is inside the portalled options dropdown
702
+ if (portal_params?.active && ul_options && ul_options.contains(target))
703
+ return;
704
+ // Click is outside both the main component and any portalled dropdown
705
+ close_dropdown(event);
706
+ }
707
+ let drag_idx = $state(null);
708
+ // event handlers enable dragging to reorder selected options
709
+ const drop = (target_idx) => (event) => {
710
+ if (!event.dataTransfer)
711
+ return;
712
+ event.dataTransfer.dropEffect = `move`;
713
+ const start_idx = parseInt(event.dataTransfer.getData(`text/plain`));
714
+ const new_selected = [...selected];
715
+ if (start_idx < target_idx) {
716
+ new_selected.splice(target_idx + 1, 0, new_selected[start_idx]);
717
+ new_selected.splice(start_idx, 1);
718
+ }
719
+ else {
720
+ new_selected.splice(target_idx, 0, new_selected[start_idx]);
721
+ new_selected.splice(start_idx + 1, 1);
722
+ }
723
+ selected = new_selected;
724
+ drag_idx = null;
725
+ onreorder?.({ options: new_selected });
726
+ onchange?.({ options: new_selected, type: `reorder` });
727
+ };
728
+ const dragstart = (idx) => (event) => {
729
+ if (!event.dataTransfer)
730
+ return;
731
+ // only allow moving, not copying (also affects the cursor during drag)
732
+ event.dataTransfer.effectAllowed = `move`;
733
+ event.dataTransfer.dropEffect = `move`;
734
+ event.dataTransfer.setData(`text/plain`, `${idx}`);
735
+ };
736
+ let ul_options = $state();
737
+ const handle_input_keydown = (event) => {
738
+ handle_keydown(event); // Restore internal logic
739
+ // Call original forwarded handler
740
+ onkeydown?.(event);
741
+ };
742
+ const handle_input_focus = (event) => {
743
+ open_dropdown(event);
744
+ onfocus?.(event);
745
+ };
746
+ // Override input's focus method to ensure dropdown opens on programmatic focus
747
+ // https://github.com/janosh/svelte-multiselect/issues/289
748
+ $effect(() => {
749
+ if (!input)
750
+ return;
751
+ const orig_focus = input.focus.bind(input);
752
+ input.focus = (options) => {
753
+ orig_focus(options);
754
+ if (!disabled && !open) {
755
+ open_dropdown(new FocusEvent(`focus`, { bubbles: true }));
756
+ }
757
+ };
758
+ return () => {
759
+ if (input)
760
+ input.focus = orig_focus;
761
+ };
762
+ });
763
+ const handle_input_blur = (event) => {
764
+ // For portalled dropdowns, don't close on blur since clicks on portalled elements
765
+ // will cause blur but we want to allow the click to register first
766
+ // (otherwise mobile touch event is unable to select options https://github.com/janosh/svelte-multiselect/issues/335)
767
+ if (portal_params?.active) {
768
+ onblur?.(event); // Let the click handler manage closing for portalled dropdowns
769
+ return;
770
+ }
771
+ // For non-portalled dropdowns, close when focus moves outside the component
772
+ if (!outerDiv?.contains(event.relatedTarget))
773
+ close_dropdown(event);
774
+ onblur?.(event); // Call original handler (if any passed as component prop)
775
+ };
776
+ // reset form validation when required prop changes
777
+ // https://github.com/janosh/svelte-multiselect/issues/285
778
+ $effect.pre(() => {
779
+ required = required; // trigger effect when required changes
780
+ form_input?.setCustomValidity(``);
781
+ });
782
+ function portal(node, params) {
783
+ let { target_node, active } = params;
784
+ if (!active)
785
+ return;
786
+ let render_in_place = typeof window === `undefined` ||
787
+ !document.body.contains(node);
788
+ if (!render_in_place) {
789
+ document.body.appendChild(node);
790
+ node.style.position = `fixed`;
791
+ const update_position = () => {
792
+ if (!target_node || !open)
793
+ return (node.hidden = true);
794
+ const rect = target_node.getBoundingClientRect();
795
+ node.style.left = `${rect.left}px`;
796
+ node.style.top = `${rect.bottom}px`;
797
+ node.style.width = `${rect.width}px`;
798
+ node.hidden = false;
799
+ };
800
+ if (open)
801
+ tick().then(update_position);
802
+ window.addEventListener(`scroll`, update_position, true);
803
+ window.addEventListener(`resize`, update_position);
804
+ $effect(() => {
805
+ if (open && target_node)
806
+ update_position();
807
+ else
808
+ node.hidden = true;
809
+ });
810
+ return {
811
+ update(params) {
812
+ target_node = params.target_node;
813
+ render_in_place = typeof window === `undefined` ||
814
+ !document.body.contains(node);
815
+ if (open && !render_in_place && target_node)
816
+ tick().then(update_position);
817
+ else if (!open || !target_node)
818
+ node.hidden = true;
819
+ },
820
+ destroy() {
821
+ if (!render_in_place)
822
+ node.remove();
823
+ window.removeEventListener(`scroll`, update_position, true);
824
+ window.removeEventListener(`resize`, update_position);
825
+ },
826
+ };
827
+ }
828
+ }
829
+ // Dynamic options loading - captures search at call time to avoid race conditions
830
+ async function load_dynamic_options(reset) {
831
+ if (!load_options_config || load_options_loading ||
832
+ (!reset && !load_options_has_more)) {
833
+ return;
834
+ }
835
+ // Capture search term at call time to avoid race with user typing during fetch
836
+ const search = searchText;
837
+ const offset = reset ? 0 : loaded_options.length;
838
+ load_options_loading = true;
839
+ try {
840
+ const limit = load_options_config.batch_size;
841
+ const result = await load_options_config.fetch({ search, offset, limit });
842
+ loaded_options = reset ? result.options : [...loaded_options, ...result.options];
843
+ load_options_has_more = result.hasMore;
844
+ load_options_last_search = search;
845
+ }
846
+ catch (err) {
847
+ console.error(`MultiSelect: loadOptions error:`, err);
848
+ }
849
+ finally {
850
+ load_options_loading = false;
851
+ }
852
+ }
853
+ // Single effect handles initial load + search changes
854
+ $effect(() => {
855
+ if (!load_options_config)
856
+ return;
857
+ // Reset state when dropdown closes so next open triggers fresh load
858
+ if (!open) {
859
+ load_options_last_search = null;
860
+ loaded_options = [];
861
+ load_options_has_more = true;
862
+ return;
863
+ }
864
+ if (debounce_timer)
865
+ clearTimeout(debounce_timer);
866
+ const search = searchText;
867
+ const is_first_load = load_options_last_search === null;
868
+ if (is_first_load) {
869
+ if (load_options_config.on_open) {
870
+ // Load immediately on dropdown open
871
+ load_dynamic_options(true);
872
+ }
873
+ else if (search) {
874
+ // onOpen=false but user typed - debounce and load
875
+ debounce_timer = setTimeout(() => load_dynamic_options(true), load_options_config.debounce_ms);
876
+ }
877
+ // If onOpen=false and no search text, do nothing (wait for user to type)
878
+ }
879
+ else if (search !== load_options_last_search) {
880
+ // Subsequent loads: debounce search changes
881
+ // Clear stale results immediately so UI doesn't show wrong results while loading
882
+ loaded_options = [];
883
+ load_options_has_more = true;
884
+ debounce_timer = setTimeout(() => load_dynamic_options(true), load_options_config.debounce_ms);
885
+ }
886
+ return () => {
887
+ if (debounce_timer)
888
+ clearTimeout(debounce_timer);
889
+ };
890
+ });
891
+ function handle_options_scroll(event) {
892
+ if (!load_options_config || load_options_loading || !load_options_has_more)
893
+ return;
894
+ const { scrollTop, scrollHeight, clientHeight } = event.target;
895
+ if (scrollHeight - scrollTop - clientHeight <= 100)
896
+ load_dynamic_options(false);
897
+ }
898
+ </script>
899
+
900
+ <svelte:window
901
+ onclick={on_click_outside}
902
+ ontouchstart={on_click_outside}
903
+ bind:innerWidth={window_width}
904
+ />
905
+
906
+ <div
907
+ bind:this={outerDiv}
908
+ class:disabled
909
+ class:single={maxSelect === 1}
910
+ class:open
911
+ class:invalid
912
+ class="multiselect {outerDivClass} {rest.class ?? ``}"
913
+ onmouseup={open_dropdown}
914
+ title={disabled ? disabledInputTitle : null}
915
+ data-id={id}
916
+ role="searchbox"
917
+ tabindex="-1"
918
+ {style}
919
+ >
920
+ <!-- form control input invisible to the user, only purpose is to abort form submission if this component fails data validation -->
921
+ <!-- bind:value={selected} prevents form submission if required prop is true and no options are selected -->
922
+ <input
923
+ {name}
924
+ required={Boolean(required)}
925
+ value={selected.length >= Number(required) ? JSON.stringify(selected) : null}
926
+ tabindex="-1"
927
+ aria-hidden="true"
928
+ aria-label="ignore this, used only to prevent form submission if select is required but empty"
929
+ class="form-control"
930
+ bind:this={form_input}
931
+ oninvalid={() => {
932
+ invalid = true
933
+ let msg
934
+ if (maxSelect && maxSelect > 1 && Number(required) > 1) {
935
+ msg = `Please select between ${required} and ${maxSelect} options`
936
+ } else if (Number(required) > 1) {
937
+ msg = `Please select at least ${required} options`
938
+ } else {
939
+ msg = `Please select an option`
940
+ }
941
+ form_input?.setCustomValidity(msg)
942
+ }}
943
+ />
944
+ <span class="expand-icon">
945
+ {#if expandIcon}
946
+ {@render expandIcon({ open })}
947
+ {:else}
948
+ <Icon
949
+ icon="ChevronExpand"
950
+ style="width: 15px; min-width: 1em; padding: 0 1pt; cursor: pointer"
951
+ />
952
+ {/if}
953
+ </span>
954
+ <ul
955
+ class="selected {ulSelectedClass}"
956
+ aria-label="selected options"
957
+ style={ulSelectedStyle}
958
+ >
959
+ {#each selected as option, idx (duplicates ? `${key(option)}-${idx}` : key(option))}
960
+ {@const selectedOptionStyle =
961
+ [get_style(option, `selected`), liSelectedStyle].filter(Boolean).join(
962
+ ` `,
963
+ ) ||
964
+ null}
965
+ <li
966
+ class={liSelectedClass}
967
+ role="option"
968
+ aria-selected="true"
969
+ animate:flip={selectedFlipParams}
970
+ draggable={selectedOptionsDraggable && !disabled && selected.length > 1}
971
+ ondragstart={dragstart(idx)}
972
+ ondragover={(event) => {
973
+ event.preventDefault() // needed for ondrop to fire
974
+ }}
975
+ ondrop={drop(idx)}
976
+ ondragenter={() => (drag_idx = idx)}
977
+ class:active={drag_idx === idx}
978
+ style={selectedOptionStyle}
979
+ onmouseup={(event) => event.stopPropagation()}
980
+ >
981
+ {#if selectedItem}
982
+ {@render selectedItem({
983
+ option,
984
+ idx,
985
+ })}
986
+ {:else if children}
987
+ {@render children({
988
+ option,
989
+ idx,
990
+ })}
991
+ {:else if parseLabelsAsHtml}
992
+ {@html get_label(option)}
993
+ {:else}
994
+ {get_label(option)}
995
+ {/if}
996
+ {#if !disabled && can_remove}
997
+ <button
998
+ onclick={(event) => remove(option, event)}
999
+ onkeydown={if_enter_or_space((event) => remove(option, event))}
1000
+ type="button"
1001
+ title="{removeBtnTitle} {get_label(option)}"
1002
+ class="remove"
1003
+ >
1004
+ {#if removeIcon}
1005
+ {@render removeIcon()}
1006
+ {:else}
1007
+ <Icon icon="Cross" style="width: 15px" />
1008
+ {/if}
1009
+ </button>
1010
+ {/if}
1011
+ </li>
1012
+ {/each}
1013
+ <input
1014
+ class={inputClass}
1015
+ style={inputStyle}
1016
+ bind:this={input}
1017
+ bind:value={searchText}
1018
+ {id}
1019
+ {disabled}
1020
+ {autocomplete}
1021
+ {inputmode}
1022
+ {pattern}
1023
+ placeholder={selected.length === 0 || placeholder_persistent ? placeholder_text : null}
1024
+ role="combobox"
1025
+ aria-haspopup="listbox"
1026
+ aria-expanded={open}
1027
+ aria-controls={listbox_id}
1028
+ aria-activedescendant={active_option_id}
1029
+ aria-busy={loading || load_options_loading || null}
1030
+ aria-invalid={invalid ? `true` : null}
1031
+ ondrop={() => false}
1032
+ onmouseup={open_dropdown}
1033
+ onkeydown={handle_input_keydown}
1034
+ onfocus={handle_input_focus}
1035
+ onblur={handle_input_blur}
1036
+ {onclick}
1037
+ {onkeyup}
1038
+ {onmousedown}
1039
+ {onmouseenter}
1040
+ {onmouseleave}
1041
+ {ontouchcancel}
1042
+ {ontouchend}
1043
+ {ontouchmove}
1044
+ {ontouchstart}
1045
+ {...rest}
1046
+ />
1047
+ {@render afterInput?.({
1048
+ selected,
1049
+ disabled,
1050
+ invalid,
1051
+ id,
1052
+ placeholder: placeholder_text,
1053
+ open,
1054
+ required,
1055
+ })}
1056
+ </ul>
1057
+ {#if loading}
1058
+ {#if spinner}
1059
+ {@render spinner()}
1060
+ {:else}
1061
+ <CircleSpinner />
1062
+ {/if}
1063
+ {/if}
1064
+ {#if disabled}
1065
+ {#if disabledIcon}
1066
+ {@render disabledIcon()}
1067
+ {:else}
1068
+ <Icon
1069
+ icon="Disabled"
1070
+ style="width: 14pt; margin: 0 2pt"
1071
+ data-name="disabled-icon"
1072
+ aria-disabled="true"
1073
+ />
1074
+ {/if}
1075
+ {:else if selected.length > 0}
1076
+ {#if maxSelect && (maxSelect > 1 || maxSelectMsg)}
1077
+ <Wiggle bind:wiggle angle={20}>
1078
+ <span class="max-select-msg {maxSelectMsgClass}">
1079
+ {maxSelectMsg?.(selected.length, maxSelect)}
1080
+ </span>
1081
+ </Wiggle>
1082
+ {/if}
1083
+ {#if maxSelect !== 1 && selected.length > 1}
1084
+ <button
1085
+ type="button"
1086
+ class="remove remove-all"
1087
+ title={removeAllTitle}
1088
+ onclick={remove_all}
1089
+ onkeydown={if_enter_or_space(remove_all)}
1090
+ >
1091
+ {#if removeIcon}
1092
+ {@render removeIcon()}
1093
+ {:else}
1094
+ <Icon icon="Cross" style="width: 15px" />
1095
+ {/if}
1096
+ </button>
1097
+ {/if}
1098
+ {/if}
1099
+
1100
+ <!-- only render options dropdown if options or searchText is not empty (needed to avoid briefly flashing empty dropdown) -->
1101
+ {#if (searchText && noMatchingOptionsMsg) || effective_options.length > 0 ||
1102
+ loadOptions}
1103
+ <ul
1104
+ use:portal={{ target_node: outerDiv, ...portal_params }}
1105
+ {@attach highlight_matches({
1106
+ query: searchText,
1107
+ disabled: !highlightMatches,
1108
+ fuzzy,
1109
+ css_class: `sms-search-matches`,
1110
+ // don't highlight text in the "Create this option..." message
1111
+ node_filter: (node) =>
1112
+ node?.parentElement?.closest(`li.user-msg`)
1113
+ ? NodeFilter.FILTER_REJECT
1114
+ : NodeFilter.FILTER_ACCEPT,
1115
+ })}
1116
+ id={listbox_id}
1117
+ class:hidden={!open}
1118
+ class="options {ulOptionsClass}"
1119
+ role="listbox"
1120
+ aria-multiselectable={maxSelect === null || maxSelect > 1}
1121
+ aria-expanded={open}
1122
+ aria-disabled={disabled ? `true` : null}
1123
+ bind:this={ul_options}
1124
+ style={ulOptionsStyle}
1125
+ onscroll={handle_options_scroll}
1126
+ onmousemove={() => (ignore_hover = false)}
1127
+ >
1128
+ {#if selectAllOption && effective_options.length > 0 &&
1129
+ (maxSelect === null || maxSelect > 1)}
1130
+ {@const label = typeof selectAllOption === `string` ? selectAllOption : `Select all`}
1131
+ <li
1132
+ class="select-all {liSelectAllClass}"
1133
+ onclick={select_all}
1134
+ onkeydown={if_enter_or_space(select_all)}
1135
+ role="option"
1136
+ aria-selected="false"
1137
+ tabindex="0"
1138
+ >
1139
+ {label}
1140
+ </li>
1141
+ {/if}
1142
+ {#each grouped_options as
1143
+ { group: group_name, options: group_opts, collapsed },
1144
+ group_idx
1145
+ (group_name ?? `ungrouped-${group_idx}`)
1146
+ }
1147
+ {#if group_name !== null}
1148
+ {@const { all_selected, selected_count } = group_header_state.get(group_name) ??
1149
+ { all_selected: false, selected_count: 0 }}
1150
+ {@const handle_toggle = () =>
1151
+ collapsibleGroups && toggle_group_collapsed(group_name)}
1152
+ {@const handle_group_select = (event: Event) =>
1153
+ toggle_group_selection(group_opts, collapsed, all_selected, event)}
1154
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
1155
+ <li
1156
+ class="group-header {liGroupHeaderClass}"
1157
+ class:collapsible={collapsibleGroups}
1158
+ class:sticky={stickyGroupHeaders}
1159
+ role={collapsibleGroups ? `button` : `presentation`}
1160
+ aria-expanded={collapsibleGroups ? !collapsed : undefined}
1161
+ aria-label="Group: {group_name}"
1162
+ style={liGroupHeaderStyle}
1163
+ onclick={handle_toggle}
1164
+ onkeydown={if_enter_or_space(handle_toggle)}
1165
+ tabindex={collapsibleGroups ? 0 : -1}
1166
+ >
1167
+ {#if groupHeader}
1168
+ {@render groupHeader({ group: group_name, options: group_opts, collapsed })}
1169
+ {:else}
1170
+ <span class="group-label">{group_name}</span>
1171
+ <span class="group-count">
1172
+ {#if keepSelectedInDropdown && selected_count > 0}
1173
+ ({selected_count}/{group_opts.length})
1174
+ {:else}
1175
+ ({group_opts.length})
1176
+ {/if}
1177
+ </span>
1178
+ {#if groupSelectAll && (maxSelect === null || maxSelect > 1)}
1179
+ <button
1180
+ type="button"
1181
+ class="group-select-all"
1182
+ class:deselect={all_selected}
1183
+ onclick={handle_group_select}
1184
+ onkeydown={if_enter_or_space(handle_group_select)}
1185
+ >
1186
+ {all_selected ? `Deselect all` : `Select all`}
1187
+ </button>
1188
+ {/if}
1189
+ {#if collapsibleGroups}
1190
+ <Icon
1191
+ icon={collapsed ? `ChevronRight` : `ChevronDown`}
1192
+ style="width: 12px; margin-left: auto"
1193
+ />
1194
+ {/if}
1195
+ {/if}
1196
+ </li>
1197
+ {/if}
1198
+ {#if !collapsed || !collapsibleGroups}
1199
+ {#each group_opts as
1200
+ option_item,
1201
+ local_idx
1202
+ (duplicates
1203
+ ? `${key(option_item)}-${group_idx}-${local_idx}`
1204
+ : key(option_item))
1205
+ }
1206
+ {@const flat_idx = navigable_index_map.get(option_item) ?? -1}
1207
+ {@const {
1208
+ label,
1209
+ disabled = null,
1210
+ title = null,
1211
+ selectedTitle = null,
1212
+ disabledTitle = defaultDisabledTitle,
1213
+ } = is_object(option_item) ? option_item : { label: option_item }}
1214
+ {@const active = activeIndex === flat_idx && flat_idx >= 0}
1215
+ {@const selected = is_selected(label)}
1216
+ {@const optionStyle =
1217
+ [get_style(option_item, `option`), liOptionStyle].filter(Boolean).join(
1218
+ ` `,
1219
+ ) ||
1220
+ null}
1221
+ {#if is_option_visible(flat_idx)}
1222
+ <li
1223
+ id="{internal_id}-opt-{flat_idx}"
1224
+ onclick={(event) => handle_option_interact(option_item, disabled, event)}
1225
+ title={disabled ? disabledTitle : (selected && selectedTitle) || title}
1226
+ class:selected
1227
+ class:active
1228
+ class:disabled
1229
+ class="{liOptionClass} {active ? liActiveOptionClass : ``}"
1230
+ onmouseover={() => {
1231
+ if (!disabled && !ignore_hover) activeIndex = flat_idx
1232
+ }}
1233
+ onfocus={() => {
1234
+ if (!disabled) activeIndex = flat_idx
1235
+ }}
1236
+ role="option"
1237
+ aria-selected={selected ? `true` : `false`}
1238
+ aria-posinset={flat_idx + 1}
1239
+ aria-setsize={navigable_options.length}
1240
+ style={optionStyle}
1241
+ onkeydown={if_enter_or_space((event) =>
1242
+ handle_option_interact(option_item, disabled, event)
1243
+ )}
1244
+ >
1245
+ {#if keepSelectedInDropdown === `checkboxes`}
1246
+ <input
1247
+ type="checkbox"
1248
+ class="option-checkbox"
1249
+ checked={selected}
1250
+ aria-label="Toggle {get_label(option_item)}"
1251
+ tabindex="-1"
1252
+ />
1253
+ {/if}
1254
+ {#if option}
1255
+ {@render option({
1256
+ option: option_item,
1257
+ idx: flat_idx,
1258
+ })}
1259
+ {:else if children}
1260
+ {@render children({
1261
+ option: option_item,
1262
+ idx: flat_idx,
1263
+ })}
1264
+ {:else if parseLabelsAsHtml}
1265
+ {@html get_label(option_item)}
1266
+ {:else}
1267
+ {get_label(option_item)}
1268
+ {/if}
1269
+ </li>
1270
+ {/if}
1271
+ {/each}
1272
+ {/if}
1273
+ {/each}
1274
+ {#if searchText}
1275
+ {@const text_input_is_duplicate = selected_labels.includes(searchText)}
1276
+ {@const is_dupe = !duplicates && text_input_is_duplicate && `dupe`}
1277
+ {@const can_create = Boolean(allowUserOptions && createOptionMsg) && `create`}
1278
+ {@const no_match =
1279
+ Boolean(navigable_options?.length === 0 && noMatchingOptionsMsg) &&
1280
+ `no-match`}
1281
+ {@const msgType = is_dupe || can_create || no_match}
1282
+ {@const msg = msgType && {
1283
+ dupe: duplicateOptionMsg,
1284
+ create: createOptionMsg,
1285
+ 'no-match': noMatchingOptionsMsg,
1286
+ }[msgType]}
1287
+ {@const can_add_user_option = msgType === `create` && allowUserOptions}
1288
+ {@const handle_create = (event: Event) =>
1289
+ can_add_user_option && add(searchText as Option, event)}
1290
+ {#if msg}
1291
+ <li
1292
+ onclick={handle_create}
1293
+ onkeydown={can_add_user_option ? if_enter_or_space(handle_create) : undefined}
1294
+ title={msgType === `create`
1295
+ ? createOptionMsg
1296
+ : msgType === `dupe`
1297
+ ? duplicateOptionMsg
1298
+ : ``}
1299
+ class:active={option_msg_is_active}
1300
+ onmouseover={() => !ignore_hover && (option_msg_is_active = true)}
1301
+ onfocus={() => (option_msg_is_active = true)}
1302
+ onmouseout={() => (option_msg_is_active = false)}
1303
+ onblur={() => (option_msg_is_active = false)}
1304
+ role="option"
1305
+ aria-selected="false"
1306
+ class="
1307
+ user-msg {liUserMsgClass} {option_msg_is_active
1308
+ ? liActiveUserMsgClass
1309
+ : ``}
1310
+ "
1311
+ style:cursor={{
1312
+ dupe: `not-allowed`,
1313
+ create: `pointer`,
1314
+ 'no-match': `default`,
1315
+ }[msgType]}
1316
+ >
1317
+ {#if userMsg}
1318
+ {@render userMsg({ searchText, msgType, msg })}
1319
+ {:else}
1320
+ {msg}
1321
+ {/if}
1322
+ </li>
1323
+ {/if}
1324
+ {/if}
1325
+ {#if loadOptions && load_options_loading}
1326
+ <li class="loading-more" role="status" aria-label="Loading more options">
1327
+ <CircleSpinner />
1328
+ </li>
1329
+ {/if}
1330
+ </ul>
1331
+ {/if}
1332
+ <!-- Screen reader announcements for dropdown state, option count, and selection changes -->
1333
+ <div class="sr-only" aria-live="polite" aria-atomic="true">
1334
+ {#if last_action}
1335
+ {#if last_action.type === `add`}
1336
+ {last_action.label} selected
1337
+ {:else if last_action.type === `remove`}
1338
+ {last_action.label} removed
1339
+ {:else if last_action.type === `removeAll`}
1340
+ {last_action.label} removed
1341
+ {/if}
1342
+ {:else if open}
1343
+ {matchingOptions.length} option{matchingOptions.length === 1 ? `` : `s`} available
1344
+ {/if}
1345
+ </div>
1346
+ </div>
1347
+
1348
+ <style>
1349
+ /* Screen reader only - visually hidden but accessible to assistive technology */
1350
+ .sr-only {
1351
+ position: absolute;
1352
+ width: 1px;
1353
+ height: 1px;
1354
+ padding: 0;
1355
+ margin: -1px;
1356
+ overflow: hidden;
1357
+ clip: rect(0, 0, 0, 0);
1358
+ white-space: nowrap;
1359
+ border: 0;
1360
+ }
1361
+
1362
+ :is(div.multiselect) {
1363
+ position: relative;
1364
+ align-items: center;
1365
+ display: flex;
1366
+ cursor: text;
1367
+ box-sizing: border-box;
1368
+ border: var(--sms-border, 1pt solid light-dark(lightgray, #555));
1369
+ border-radius: var(--sms-border-radius, 3pt);
1370
+ background: var(--sms-bg, light-dark(white, #1a1a1a));
1371
+ width: var(--sms-width);
1372
+ max-width: var(--sms-max-width);
1373
+ padding: var(--sms-padding, 0 3pt);
1374
+ color: var(--sms-text-color);
1375
+ font-size: var(--sms-font-size, inherit);
1376
+ min-height: var(--sms-min-height, 22pt);
1377
+ margin: var(--sms-margin);
1378
+ }
1379
+ :is(div.multiselect.open) {
1380
+ /* increase z-index when open to ensure the dropdown of one <MultiSelect />
1381
+ displays above that of another slightly below it on the page */
1382
+ z-index: var(--sms-open-z-index, 4);
1383
+ }
1384
+ :is(div.multiselect:focus-within) {
1385
+ border: var(--sms-focus-border, 1pt solid var(--sms-active-color, cornflowerblue));
1386
+ }
1387
+ :is(div.multiselect.disabled) {
1388
+ background: var(--sms-disabled-bg, light-dark(lightgray, #444));
1389
+ cursor: not-allowed;
1390
+ }
1391
+
1392
+ :is(div.multiselect > ul.selected) {
1393
+ display: flex;
1394
+ flex: 1;
1395
+ padding: 0;
1396
+ margin: 0;
1397
+ flex-wrap: wrap;
1398
+ }
1399
+ :is(div.multiselect > ul.selected > li) {
1400
+ align-items: center;
1401
+ border-radius: 3pt;
1402
+ display: flex;
1403
+ margin: 2pt;
1404
+ line-height: normal;
1405
+ transition: 0.3s;
1406
+ white-space: nowrap;
1407
+ background: var(
1408
+ --sms-selected-bg,
1409
+ light-dark(rgba(0, 0, 0, 0.15), rgba(255, 255, 255, 0.15))
1410
+ );
1411
+ padding: var(--sms-selected-li-padding, 1pt 5pt);
1412
+ color: var(--sms-selected-text-color, var(--sms-text-color));
1413
+ }
1414
+ :is(div.multiselect > ul.selected > li[draggable='true']) {
1415
+ cursor: grab;
1416
+ }
1417
+ :is(div.multiselect > ul.selected > li.active) {
1418
+ background: var(
1419
+ --sms-li-active-bg,
1420
+ var(--sms-active-color, light-dark(rgba(0, 0, 0, 0.15), rgba(255, 255, 255, 0.15)))
1421
+ );
1422
+ }
1423
+ :is(div.multiselect button) {
1424
+ border-radius: 50%;
1425
+ aspect-ratio: 1; /* ensure circle, not ellipse */
1426
+ display: flex;
1427
+ transition: 0.2s;
1428
+ color: inherit;
1429
+ background: transparent;
1430
+ border: none;
1431
+ cursor: pointer;
1432
+ outline: none;
1433
+ padding: 1pt;
1434
+ margin: 0 0 0 3pt; /* CSS reset */
1435
+ }
1436
+ :is(div.multiselect button.remove-all) {
1437
+ margin: 0 3pt;
1438
+ }
1439
+ :is(ul.selected > li button:hover, button.remove-all:hover, button:focus) {
1440
+ color: var(--sms-remove-btn-hover-color, light-dark(#0088cc, lightskyblue));
1441
+ background: var(
1442
+ --sms-remove-btn-hover-bg,
1443
+ light-dark(rgba(0, 0, 0, 0.2), rgba(255, 255, 255, 0.2))
1444
+ );
1445
+ }
1446
+
1447
+ :is(div.multiselect input) {
1448
+ margin: auto 0; /* CSS reset */
1449
+ padding: 0; /* CSS reset */
1450
+ }
1451
+ :is(div.multiselect > ul.selected > input) {
1452
+ border: none;
1453
+ outline: none;
1454
+ background: none;
1455
+ flex: 1; /* this + next line fix issue #12 https://git.io/JiDe3 */
1456
+ min-width: 2em;
1457
+ /* ensure input uses text color and not --sms-selected-text-color */
1458
+ color: var(--sms-text-color);
1459
+ font-size: inherit;
1460
+ cursor: inherit; /* needed for disabled state */
1461
+ border-radius: 0; /* reset ul.selected > li */
1462
+ }
1463
+
1464
+ /* When options are selected, placeholder is hidden in which case we minimize input width to avoid adding unnecessary width to div.multiselect */
1465
+ :is(div.multiselect > ul.selected > input:not(:placeholder-shown)) {
1466
+ min-width: 1px; /* Minimal width to remain interactive */
1467
+ }
1468
+
1469
+ /* don't wrap ::placeholder rules in :is() as it seems to be overpowered by browser defaults i.t.o. specificity */
1470
+ div.multiselect > ul.selected > input::placeholder {
1471
+ padding-left: 5pt;
1472
+ color: var(--sms-placeholder-color);
1473
+ opacity: var(--sms-placeholder-opacity);
1474
+ }
1475
+ :is(div.multiselect > input.form-control) {
1476
+ width: 2em;
1477
+ position: absolute;
1478
+ background: transparent;
1479
+ border: none;
1480
+ outline: none;
1481
+ z-index: -1;
1482
+ opacity: 0;
1483
+ pointer-events: none;
1484
+ }
1485
+
1486
+ ul.options {
1487
+ list-style: none;
1488
+ /* top, left, width, position are managed by portal when active */
1489
+ /* but provide defaults for non-portaled or initial state */
1490
+ position: absolute; /* Default, overridden by portal to fixed when open */
1491
+ top: 100%;
1492
+ left: 0;
1493
+ width: 100%;
1494
+ /* Default z-index if not portaled/overridden by portal */
1495
+ z-index: var(--sms-options-z-index, 3);
1496
+
1497
+ overflow: auto;
1498
+ transition: all
1499
+ 0.2s; /* Consider if this transition is desirable with portal positioning */
1500
+ box-sizing: border-box;
1501
+ background: var(--sms-options-bg, light-dark(#fafafa, #1a1a1a));
1502
+ max-height: var(--sms-options-max-height, 50vh);
1503
+ overscroll-behavior: var(--sms-options-overscroll, none);
1504
+ box-shadow: var(
1505
+ --sms-options-shadow,
1506
+ light-dark(0 0 14pt -8pt black, 0 0 14pt -4pt rgba(0, 0, 0, 0.8))
1507
+ );
1508
+ border: var(--sms-options-border);
1509
+ border-width: var(--sms-options-border-width);
1510
+ border-radius: var(--sms-options-border-radius, 1ex);
1511
+ padding: var(--sms-options-padding);
1512
+ margin: var(--sms-options-margin, 6pt 0 0 0);
1513
+ }
1514
+ ul.options.hidden {
1515
+ visibility: hidden;
1516
+ opacity: 0;
1517
+ transform: translateY(50px);
1518
+ pointer-events: none;
1519
+ }
1520
+ ul.options > li {
1521
+ padding: 3pt 1ex;
1522
+ cursor: pointer;
1523
+ scroll-margin: var(--sms-options-scroll-margin, 100px);
1524
+ border-left: 3px solid transparent;
1525
+ }
1526
+ ul.options .user-msg {
1527
+ /* block needed so vertical padding applies to span */
1528
+ display: block;
1529
+ padding: 3pt 2ex;
1530
+ }
1531
+ ul.options > li.selected {
1532
+ background: var(
1533
+ --sms-li-selected-plain-bg,
1534
+ light-dark(rgba(0, 123, 255, 0.1), rgba(100, 180, 255, 0.2))
1535
+ );
1536
+ border-left: var(
1537
+ --sms-li-selected-plain-border,
1538
+ 3px solid var(--sms-active-color, cornflowerblue)
1539
+ );
1540
+ }
1541
+ ul.options > li.active {
1542
+ background: var(
1543
+ --sms-li-active-bg,
1544
+ var(--sms-active-color, light-dark(rgba(0, 0, 0, 0.15), rgba(255, 255, 255, 0.15)))
1545
+ );
1546
+ }
1547
+ ul.options > li.disabled {
1548
+ cursor: not-allowed;
1549
+ background: var(--sms-li-disabled-bg, light-dark(#f5f5f6, #2a2a2a));
1550
+ color: var(--sms-li-disabled-text, light-dark(#b8b8b8, #666));
1551
+ }
1552
+ /* Checkbox styling for keepSelectedInDropdown='checkboxes' mode */
1553
+ ul.options > li > input.option-checkbox {
1554
+ width: 16px;
1555
+ height: 16px;
1556
+ margin-right: 6px;
1557
+ accent-color: var(--sms-active-color, cornflowerblue);
1558
+ }
1559
+ /* Select all option styling */
1560
+ ul.options > li.select-all {
1561
+ border-bottom: var(
1562
+ --sms-select-all-border-bottom,
1563
+ 1px solid light-dark(lightgray, #555)
1564
+ );
1565
+ font-weight: var(--sms-select-all-font-weight, 500);
1566
+ color: var(--sms-select-all-color, inherit);
1567
+ background: var(--sms-select-all-bg, transparent);
1568
+ margin-bottom: var(--sms-select-all-margin-bottom, 2pt);
1569
+ }
1570
+ ul.options > li.select-all:hover {
1571
+ background: var(
1572
+ --sms-select-all-hover-bg,
1573
+ var(
1574
+ --sms-li-active-bg,
1575
+ var(
1576
+ --sms-active-color,
1577
+ light-dark(rgba(0, 0, 0, 0.15), rgba(255, 255, 255, 0.15))
1578
+ )
1579
+ )
1580
+ );
1581
+ }
1582
+ /* Group header styling */
1583
+ ul.options > li.group-header {
1584
+ display: flex;
1585
+ align-items: center;
1586
+ font-weight: var(--sms-group-header-font-weight, 600);
1587
+ font-size: var(--sms-group-header-font-size, 0.85em);
1588
+ color: var(--sms-group-header-color, light-dark(#666, #aaa));
1589
+ background: var(--sms-group-header-bg, transparent);
1590
+ padding: var(--sms-group-header-padding, 6pt 1ex 3pt);
1591
+ cursor: default;
1592
+ border-left: none;
1593
+ text-transform: var(--sms-group-header-text-transform, uppercase);
1594
+ letter-spacing: var(--sms-group-header-letter-spacing, 0.5px);
1595
+ }
1596
+ ul.options > li.group-header:not(:first-child) {
1597
+ margin-top: var(--sms-group-header-margin-top, 4pt);
1598
+ border-top: var(--sms-group-header-border-top, 1px solid light-dark(#eee, #333));
1599
+ }
1600
+ ul.options > li.group-header.collapsible {
1601
+ cursor: pointer;
1602
+ }
1603
+ ul.options > li.group-header.collapsible:hover {
1604
+ background: var(
1605
+ --sms-group-header-hover-bg,
1606
+ light-dark(rgba(0, 0, 0, 0.05), rgba(255, 255, 255, 0.05))
1607
+ );
1608
+ }
1609
+ ul.options > li.group-header .group-label {
1610
+ flex: 1;
1611
+ }
1612
+ ul.options > li.group-header .group-count {
1613
+ opacity: 0.6;
1614
+ font-size: 0.9em;
1615
+ font-weight: normal;
1616
+ margin-left: 4pt;
1617
+ }
1618
+ /* Sticky group headers when enabled */
1619
+ ul.options > li.group-header.sticky {
1620
+ position: sticky;
1621
+ top: 0;
1622
+ z-index: 1;
1623
+ background: var(
1624
+ --sms-group-header-sticky-bg,
1625
+ var(--sms-options-bg, light-dark(#fafafa, #1a1a1a))
1626
+ );
1627
+ }
1628
+ /* Indent grouped options for visual hierarchy */
1629
+ ul.options > li:not(.group-header):not(.select-all):not(.user-msg):not(.loading-more) {
1630
+ padding-left: var(
1631
+ --sms-group-item-padding-left,
1632
+ var(--sms-group-option-indent, 1.5ex)
1633
+ );
1634
+ }
1635
+ /* Collapse/expand animation for group chevron icon */
1636
+ ul.options > li.group-header :global(svg) {
1637
+ transition: transform var(--sms-group-collapse-duration, 0.15s) ease-out;
1638
+ }
1639
+ ul.options > li.group-header button.group-select-all {
1640
+ font-size: 0.9em;
1641
+ font-weight: normal;
1642
+ text-transform: none;
1643
+ color: var(--sms-active-color, cornflowerblue);
1644
+ background: transparent;
1645
+ border: none;
1646
+ cursor: pointer;
1647
+ padding: 2pt 4pt;
1648
+ margin-left: 8pt;
1649
+ border-radius: 3pt;
1650
+ aspect-ratio: auto; /* override global button aspect-ratio: 1 */
1651
+ }
1652
+ ul.options > li.group-header button.group-select-all:hover {
1653
+ background: var(
1654
+ --sms-group-select-all-hover-bg,
1655
+ light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.1))
1656
+ );
1657
+ }
1658
+ ul.options > li.group-header button.group-select-all.deselect {
1659
+ color: var(--sms-group-deselect-color, light-dark(#c44, #f77));
1660
+ }
1661
+ :is(span.max-select-msg) {
1662
+ padding: 0 3pt;
1663
+ }
1664
+ ::highlight(sms-search-matches) {
1665
+ color: light-dark(#1a8870, mediumaquamarine);
1666
+ }
1667
+ /* Loading more indicator for infinite scrolling */
1668
+ ul.options > li.loading-more {
1669
+ display: flex;
1670
+ justify-content: center;
1671
+ align-items: center;
1672
+ padding: 8pt;
1673
+ cursor: default;
1674
+ }
1675
+ </style>