@wentools/overlay 0.1.4 → 0.1.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wentools/overlay",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Svelte 5 popover, dropdown menu, and tooltip components with CSS custom property theming",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -39,6 +39,10 @@ Perfect for: context menus, action menus, navigation dropdowns.
39
39
  offset?: number
40
40
  /** Maximum width of dropdown content */
41
41
  maxWidth?: string
42
+ /** Minimum width of dropdown content. Unset by default, so the menu
43
+ * shrink-wraps to its widest item. Set this (e.g. '14rem') to floor the
44
+ * width on larger screens where a thin menu of short labels looks dinky. */
45
+ minWidth?: string
42
46
  /** CSS class for styling the dropdown */
43
47
  class?: string
44
48
  /** Whether the dropdown is disabled */
@@ -57,6 +61,7 @@ Perfect for: context menus, action menus, navigation dropdowns.
57
61
  position = 'bottom-start',
58
62
  offset = 4,
59
63
  maxWidth = '60ch',
64
+ minWidth,
60
65
  class: className = '',
61
66
  disabled = false,
62
67
  initialFocusIndex = 0,
@@ -201,6 +206,7 @@ Perfect for: context menus, action menus, navigation dropdowns.
201
206
  bind:this={menuElement}
202
207
  class="dropdown-menu-content"
203
208
  style:max-width={maxWidth}
209
+ style:min-width={minWidth}
204
210
  role="menu"
205
211
  onfocus={handleItemFocus}
206
212
  >
@@ -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