diff --git a/ui/lib/src/view/dialog.ts b/ui/lib/src/view/dialog.ts index 508d6ece9c257..6af1a71985470 100644 --- a/ui/lib/src/view/dialog.ts +++ b/ui/lib/src/view/dialog.ts @@ -85,9 +85,7 @@ export async function domDialog(o: DomDialogOpts): Promise { (o.parent ?? document.body).appendChild(dialog); const wrapper = new DialogWrapper(dialog, view, o, false); - if (o.show) return wrapper.show(); - - return wrapper; + return o.show ? wrapper.show() : wrapper; } export function snabDialog(o: SnabDialogOpts): VNode { @@ -165,10 +163,7 @@ class DialogWrapper implements Dialog { const justThen = Date.now(); const cancelOnInterval = (e: PointerEvent) => { if (!this.dialog.isConnected) console.trace('likely zombie dialog. Always Be Close()ing'); - if (Date.now() - justThen < 200) return; - const r = dialog.getBoundingClientRect(); - if (e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom) - this.close('cancel'); + if (Date.now() - justThen >= 200 && !dialog.contains(e.target as Node | null)) this.close('cancel'); }; this.observer.observe(document.body, { childList: true, subtree: true }); document.body.style.setProperty('---viewport-height', `${window.innerHeight}px`); @@ -176,7 +171,7 @@ class DialogWrapper implements Dialog { this.dialogEvents.addListener(dialog, 'cancel', e => { if (o.noClickAway && o.noCloseButton && o.class !== 'alert') return e.preventDefault(); - if (!this.returnValue) this.returnValue = 'cancel'; + this.returnValue ||= 'cancel'; }); this.dialogEvents.addListener(dialog, 'close', this.onRemove); if (!o.noCloseButton)