@dorsk/tsumikit 0.18.2 → 0.18.3
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.
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// would overflow. (CSS anchor positioning would replace the JS here once it
|
|
9
9
|
// ships beyond Chromium; the popover semantics above are the hard part and
|
|
10
10
|
// are broadly supported today.)
|
|
11
|
-
import type
|
|
11
|
+
import { tick, type Snippet } from 'svelte';
|
|
12
12
|
import { place } from '../../floating';
|
|
13
13
|
|
|
14
14
|
type Placement = 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end';
|
|
@@ -67,13 +67,22 @@
|
|
|
67
67
|
const id = `pop-${Math.random().toString(36).slice(2, 8)}`;
|
|
68
68
|
let triggerEl = $state<HTMLButtonElement | null>(null);
|
|
69
69
|
let panelEl = $state<HTMLDivElement | null>(null);
|
|
70
|
+
// Panel content is mounted only after the first open, then kept alive so
|
|
71
|
+
// reopening is instant. The panel element itself always renders — the native
|
|
72
|
+
// `popovertarget` wiring needs its id present in the DOM at all times.
|
|
73
|
+
let opened = $state(false);
|
|
70
74
|
|
|
71
75
|
function reposition() {
|
|
72
76
|
if (triggerEl && panelEl) place(triggerEl, panelEl, placement, gap);
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
function onToggle(e: ToggleEvent) {
|
|
79
|
+
async function onToggle(e: ToggleEvent) {
|
|
76
80
|
if (e.newState === 'open') {
|
|
81
|
+
const firstOpen = !opened;
|
|
82
|
+
opened = true;
|
|
83
|
+
// On the first open the content snippet mounts this tick; measure the
|
|
84
|
+
// panel only once it has, so placement accounts for its real size.
|
|
85
|
+
if (firstOpen) await tick();
|
|
77
86
|
reposition();
|
|
78
87
|
addEventListener('scroll', reposition, true);
|
|
79
88
|
addEventListener('resize', reposition);
|
|
@@ -121,7 +130,9 @@
|
|
|
121
130
|
aria-label={label}
|
|
122
131
|
ontoggle={onToggle}
|
|
123
132
|
>
|
|
124
|
-
{
|
|
133
|
+
{#if opened}
|
|
134
|
+
{@render children()}
|
|
135
|
+
{/if}
|
|
125
136
|
</div>
|
|
126
137
|
|
|
127
138
|
<style>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
2
|
type Placement = 'bottom-start' | 'bottom-end' | 'top-start' | 'top-end';
|
|
3
3
|
type TriggerVariant = 'default' | 'primary' | 'ghost' | 'danger';
|
|
4
4
|
type TriggerTone = 'none' | 'accent' | 'success' | 'info' | 'warn' | 'danger';
|
package/package.json
CHANGED