From f6d91d1003b5d8b14f0c5c7e6dd0e40424916f29 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sat, 3 May 2025 14:58:32 +0200 Subject: Prevent closing modal on input selection When selection ends outside of the modal, this could lead to closing the modal. Use `onmousedown` event instead, which takes the element at the start of the selection. --- frontend/ts/src/ui/modal.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/ts/src/ui/modal.ts b/frontend/ts/src/ui/modal.ts index 2d5e275..75b3ad9 100644 --- a/frontend/ts/src/ui/modal.ts +++ b/frontend/ts/src/ui/modal.ts @@ -18,7 +18,7 @@ export function view({ header, body, onClose, className, onmount, onunmount }: P return h('div', { className: closingVar.map(isClosing => `g-Modal ${className ?? ''} ${isClosing ? 'g-Modal--Fade' : ''}`), - onclick: onClose, + onmousedown: () => onClose(), onmount: (element: Element) => { document.addEventListener('keydown', onKeyDown) if (onmount) onmount(element) @@ -30,7 +30,7 @@ export function view({ header, body, onClose, className, onmount, onunmount }: P }, h('div', { className: 'g-Modal__Content', - onclick: (e: Event) => e.stopPropagation() + onmousedown: (e: Event) => e.stopPropagation() }, h('div', { className: 'g-Modal__Header' }, -- cgit v1.2.3