@sveltia/ui 0.13.1 → 0.13.2

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.
@@ -228,6 +228,9 @@ dialog:not(.open) {
228
228
  transition-duration: 400ms;
229
229
  opacity: 0;
230
230
  }
231
+ dialog[hidden] {
232
+ transition-duration: 1ms !important;
233
+ }
231
234
  dialog:not(.active) {
232
235
  pointer-events: none !important;
233
236
  }
@@ -48,5 +48,9 @@ declare class Popup {
48
48
  * Check the position of the anchor element.
49
49
  */
50
50
  checkPosition(): void;
51
+ /**
52
+ * Hide the popup immediately (when the anchor is being hidden).
53
+ */
54
+ hideImmediately(): Promise<void>;
51
55
  }
52
56
  export {};
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable no-nested-ternary */
2
2
 
3
3
  import { generateElementId } from '@sveltia/utils/element';
4
+ import { sleep } from '@sveltia/utils/misc';
4
5
  import { get, writable } from 'svelte/store';
5
6
 
6
7
  /**
@@ -127,6 +128,18 @@ class Popup {
127
128
  }
128
129
  });
129
130
 
131
+ this.anchorElement.addEventListener('transitionstart', () => {
132
+ if (this.anchorElement.closest('.hiding, .hidden, [hidden]')) {
133
+ this.hideImmediately();
134
+ }
135
+ });
136
+
137
+ new IntersectionObserver(([entry]) => {
138
+ if (!entry.isIntersecting && get(this.open)) {
139
+ this.hideImmediately();
140
+ }
141
+ }).observe(this.anchorElement);
142
+
130
143
  // Close the popup when the backdrop, a menu item or an option is clicked
131
144
  this.popupElement.addEventListener('click', (event) => {
132
145
  event.stopPropagation();
@@ -188,6 +201,16 @@ class Popup {
188
201
  this.observer.unobserve(this.positionBaseElement);
189
202
  this.observer.observe(this.positionBaseElement);
190
203
  }
204
+
205
+ /**
206
+ * Hide the popup immediately (when the anchor is being hidden).
207
+ */
208
+ async hideImmediately() {
209
+ this.popupElement.hidden = true;
210
+ this.open.set(false);
211
+ await sleep(50);
212
+ this.popupElement.hidden = false;
213
+ }
191
214
  }
192
215
 
193
216
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "publishConfig": {