@r2digisolutions/components 0.14.12 → 0.14.13
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.
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
let popoverEl = $state<HTMLDivElement | null>(null);
|
|
71
71
|
let inputEl = $state<HTMLInputElement | null>(null);
|
|
72
72
|
let highlighted = $state(0);
|
|
73
|
+
let openingGesture = $state(false);
|
|
73
74
|
let childEntries = $state<{ id: number; value: string; disabled: boolean; label: string }[]>([]);
|
|
74
75
|
let nextChildId = 0;
|
|
75
76
|
const uid = $props.id();
|
|
@@ -163,6 +164,21 @@
|
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
|
|
167
|
+
function onDocPointerDown(event: PointerEvent) {
|
|
168
|
+
if (!open || openingGesture) return;
|
|
169
|
+
const target = event.target;
|
|
170
|
+
if (!(target instanceof Node)) return;
|
|
171
|
+
if (rootEl?.contains(target) || popoverEl?.contains(target)) return;
|
|
172
|
+
setOpen(false);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function markOpeningGesture() {
|
|
176
|
+
openingGesture = true;
|
|
177
|
+
queueMicrotask(() => {
|
|
178
|
+
openingGesture = false;
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
166
182
|
function onPopoverClose() {
|
|
167
183
|
if (selected) query = selected.label;
|
|
168
184
|
else if (!creatable) query = '';
|
|
@@ -194,6 +210,7 @@
|
|
|
194
210
|
|
|
195
211
|
function setOpen(next: boolean) {
|
|
196
212
|
if (disabled) return;
|
|
213
|
+
if (next) markOpeningGesture();
|
|
197
214
|
open = next;
|
|
198
215
|
if (next) {
|
|
199
216
|
highlighted = 0;
|
|
@@ -307,11 +324,17 @@
|
|
|
307
324
|
|
|
308
325
|
const offScroll = on(window, 'scroll', reposition, { capture: true, passive: true });
|
|
309
326
|
const offResize = on(window, 'resize', reposition);
|
|
327
|
+
// Defer past the opening click — same gesture must not count as outside.
|
|
328
|
+
const timer = window.setTimeout(() => {
|
|
329
|
+
document.addEventListener('pointerdown', onDocPointerDown, true);
|
|
330
|
+
}, 0);
|
|
310
331
|
|
|
311
332
|
return () => {
|
|
312
333
|
cancelAnimationFrame(frame);
|
|
313
334
|
offScroll();
|
|
314
335
|
offResize();
|
|
336
|
+
window.clearTimeout(timer);
|
|
337
|
+
document.removeEventListener('pointerdown', onDocPointerDown, true);
|
|
315
338
|
};
|
|
316
339
|
});
|
|
317
340
|
|
|
@@ -407,17 +430,16 @@
|
|
|
407
430
|
<div
|
|
408
431
|
bind:this={popoverEl}
|
|
409
432
|
id={listboxId}
|
|
410
|
-
popover="
|
|
433
|
+
popover="manual"
|
|
411
434
|
role="listbox"
|
|
412
435
|
onbeforetoggle={handleBeforeToggle}
|
|
413
436
|
ontoggle={handleToggle}
|
|
414
437
|
class="combobox-popover inset-auto m-0 overflow-y-auto rounded-xl border border-border bg-surface-elevated p-1.5 shadow-xl outline-none"
|
|
415
438
|
>
|
|
416
|
-
{#if
|
|
417
|
-
{
|
|
418
|
-
|
|
419
|
-
{
|
|
420
|
-
{#each items as item, index (itemKey(item))}
|
|
439
|
+
{#if !hasRows}
|
|
440
|
+
<div class="px-3 py-2.5 text-xs text-muted text-center">{emptyText}</div>
|
|
441
|
+
{:else}
|
|
442
|
+
{#each items as item, index (itemKey(item))}
|
|
421
443
|
{#if item.kind === 'create'}
|
|
422
444
|
<ComboboxItem
|
|
423
445
|
value={COMBOBOX_CREATE_KEY}
|
|
@@ -465,7 +487,6 @@
|
|
|
465
487
|
{/each}
|
|
466
488
|
{@render children?.()}
|
|
467
489
|
{/if}
|
|
468
|
-
{/if}
|
|
469
490
|
</div>
|
|
470
491
|
</div>
|
|
471
492
|
|