@wentools/overlay 0.1.2 → 0.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/popover.svelte +15 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wentools/overlay",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Svelte 5 popover, dropdown menu, and tooltip components with CSS custom property theming",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -226,8 +226,6 @@ Perfect for: building custom popover patterns, tooltips, custom dropdowns.
226
226
  }
227
227
 
228
228
  const handleClickOutside = (event: MouseEvent) => {
229
- if (!open || !closeOnClickOutside) return
230
-
231
229
  const target = event.target as Node
232
230
  if (
233
231
  popoverElement &&
@@ -239,6 +237,21 @@ Perfect for: building custom popover patterns, tooltips, custom dropdowns.
239
237
  }
240
238
  }
241
239
 
240
+ // Defer adding the click-outside listener by one frame after opening, so a
241
+ // programmatic open from pointerdown isn't closed by the click from the same tap
242
+ $effect(() => {
243
+ if (!open || !closeOnClickOutside) return
244
+
245
+ const rafId = requestAnimationFrame(() => {
246
+ document.addEventListener('click', handleClickOutside)
247
+ })
248
+
249
+ return () => {
250
+ cancelAnimationFrame(rafId)
251
+ document.removeEventListener('click', handleClickOutside)
252
+ }
253
+ })
254
+
242
255
  const handleKeydown = (event: KeyboardEvent) => {
243
256
  if (!open || !closeOnEscape) return
244
257
 
@@ -260,11 +273,6 @@ Perfect for: building custom popover patterns, tooltips, custom dropdowns.
260
273
  onMount(() => {
261
274
  const cleanup: (() => void)[] = []
262
275
 
263
- if (closeOnClickOutside) {
264
- document.addEventListener('click', handleClickOutside)
265
- cleanup.push(() => document.removeEventListener('click', handleClickOutside))
266
- }
267
-
268
276
  if (closeOnEscape) {
269
277
  document.addEventListener('keydown', handleKeydown)
270
278
  cleanup.push(() => document.removeEventListener('keydown', handleKeydown))