Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ui/lib/src/view/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ export async function domDialog(o: DomDialogOpts): Promise<Dialog> {
(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 {
Expand Down Expand Up @@ -167,7 +165,10 @@ class DialogWrapper implements Dialog {
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)
if (
(e.clientX < r.left || e.clientX > r.right || e.clientY < r.top || e.clientY > r.bottom) &&
!dialog.contains(e.target as Node | null) // close button could be positioned outside the dialog
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need the X/Y position checks then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ornicar Tested on Chrome & Safari (Mac) and it seems fine to remove them. I don't know enough about modal dialogs to be sure there aren't any edge cases where it'd make a difference though. @jonbgamble any thoughts on this?

)
this.close('cancel');
};
this.observer.observe(document.body, { childList: true, subtree: true });
Expand All @@ -176,7 +177,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)
Expand Down