@wentools/overlay 0.1.4 → 0.1.5

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 +12 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wentools/overlay",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Svelte 5 popover, dropdown menu, and tooltip components with CSS custom property theming",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -237,18 +237,23 @@ Perfect for: building custom popover patterns, tooltips, custom dropdowns.
237
237
  }
238
238
  }
239
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
240
+ // Ignore clicks shortly after opening so a programmatic open from pointerdown
241
+ // isn't closed by the click from the same tap. On touch devices, pointerdown
242
+ // and the compatibility click fire in separate browser tasks, so rAF-based
243
+ // deferral isn't sufficient — a time-based guard is needed instead.
242
244
  $effect(() => {
243
245
  if (!open || !closeOnClickOutside) return
244
246
 
245
- const rafId = requestAnimationFrame(() => {
246
- document.addEventListener('click', handleClickOutside)
247
- })
247
+ const openedAt = performance.now()
248
+ const guardedHandler = (event: MouseEvent) => {
249
+ if (performance.now() - openedAt < 300) return
250
+ handleClickOutside(event)
251
+ }
252
+
253
+ document.addEventListener('click', guardedHandler)
248
254
 
249
255
  return () => {
250
- cancelAnimationFrame(rafId)
251
- document.removeEventListener('click', handleClickOutside)
256
+ document.removeEventListener('click', guardedHandler)
252
257
  }
253
258
  })
254
259