@inglorious/ui 7.1.4 → 7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/ui",
3
- "version": "7.1.4",
3
+ "version": "7.1.5",
4
4
  "description": "A design system for Inglorious Web with render-function components and customizable themes",
5
5
  "author": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
@@ -21,6 +21,26 @@ import {
21
21
 
22
22
  const NO_FOCUSED_INDEX = -1
23
23
 
24
+ const outsideClickListeners = new Map()
25
+
26
+ function trackOutsideClick(props, el) {
27
+ const previous = outsideClickListeners.get(props.id)
28
+ if (previous) {
29
+ document.removeEventListener("click", previous)
30
+ outsideClickListeners.delete(props.id)
31
+ }
32
+
33
+ if (!el) return
34
+
35
+ const root = el.closest(".iw-combobox")
36
+ const listener = (event) => {
37
+ if (!event.composedPath().includes(root)) props.onClose?.()
38
+ }
39
+
40
+ outsideClickListeners.set(props.id, listener)
41
+ document.addEventListener("click", listener)
42
+ }
43
+
24
44
  export const Combobox = {
25
45
  /**
26
46
  * Main entrypoint for the combobox control. It renders the wrapper, label, control, and dropdown when open.
@@ -191,21 +211,7 @@ export const Combobox = {
191
211
 
192
212
  return html`<div
193
213
  class="iw-combobox-dropdown"
194
- ${ref((el) => {
195
- if (el) {
196
- setTimeout(() => {
197
- document.addEventListener(
198
- "click",
199
- (event) => {
200
- if (!el.contains(event.target)) {
201
- props.onClose?.()
202
- }
203
- },
204
- { once: true },
205
- )
206
- })
207
- }
208
- })}
214
+ ${ref((el) => trackOutsideClick(props, el))}
209
215
  >
210
216
  ${when(props.isSearchable, () => this.renderSearchInput?.(props))}
211
217
  ${when(props.isLoading, () => this.renderLoading?.(props))}