@dorsk/tsumikit 0.18.2 → 0.18.4
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';
|
|
@@ -43,9 +43,13 @@
|
|
|
43
43
|
function select(id: string, focus = false) {
|
|
44
44
|
if (tabs.find((t) => t.id === id)?.disabled) return;
|
|
45
45
|
value = id;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
queueMicrotask(() => {
|
|
47
|
+
const el = listEl?.querySelector<HTMLButtonElement>(`#${baseId}-tab-${id}`);
|
|
48
|
+
// The list scrolls when it is too narrow, so keyboard selection has to
|
|
49
|
+
// bring the tab back into view or it moves somewhere unseen.
|
|
50
|
+
el?.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
51
|
+
if (focus) el?.focus();
|
|
52
|
+
});
|
|
49
53
|
}
|
|
50
54
|
// Step to the next non-disabled tab in a direction, wrapping around.
|
|
51
55
|
function step(from: number, dir: 1 | -1): number {
|
|
@@ -99,9 +103,13 @@
|
|
|
99
103
|
display: flex;
|
|
100
104
|
gap: var(--sp-1);
|
|
101
105
|
border-bottom: 1px solid var(--border);
|
|
106
|
+
overflow-x: auto;
|
|
107
|
+
scrollbar-width: thin;
|
|
102
108
|
}
|
|
103
109
|
.tab {
|
|
104
110
|
display: inline-flex;
|
|
111
|
+
flex: 0 0 auto;
|
|
112
|
+
white-space: nowrap;
|
|
105
113
|
align-items: center;
|
|
106
114
|
gap: var(--sp-2);
|
|
107
115
|
padding: var(--sp-2) var(--sp-3);
|
package/package.json
CHANGED