Skip to content

Commit ff9755a

Browse files
committed
Lexical: Fixed modals closing on clicks starting from within modals
Specifically on chromium browsers. Firefox was fine before. Changes tested across both.
1 parent bb76d14 commit ff9755a

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

resources/js/wysiwyg/ui/framework/modals.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,23 @@ export class EditorFormModal extends EditorContainerUiElement {
7272

7373
const wrapper = el('div', {class: 'editor-modal-wrapper'}, [modal]);
7474

75+
// Handle clicks but only when not started from within the modal
76+
let mouseDownInModal = false;
77+
modal.addEventListener('mousedown', () => {
78+
mouseDownInModal = true;
79+
});
80+
wrapper.addEventListener('mouseup', () => {
81+
window.setTimeout(() => {
82+
mouseDownInModal = false;
83+
}, 10);
84+
});
7585
wrapper.addEventListener('click', event => {
76-
if (event.target && !modal.contains(event.target as HTMLElement)) {
86+
if (!mouseDownInModal) {
7787
this.hide();
7888
}
7989
});
8090

91+
// Handle escape key press
8192
wrapper.addEventListener('keydown', event => {
8293
if (event.key === 'Escape') {
8394
this.hide();

0 commit comments

Comments
 (0)