From ef97eaf9876bcf1712d4a6bfb91307875b0034ac Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Tue, 31 Oct 2023 10:31:41 +0100 Subject: [PATCH] [FIX] web: drag and drop: allow pointer down blur If one edits an input value in a dialog and click on the dialog header, the blur event is prevented because the dialog is draggable and the pointer down native behaviour is prevented by the draggable hook builder. This can cause data losses or the dialog content to not be render correctly. For instance, this happens with the debug input of the domain selector dialog. We fix that by triggering the blur event programatically. closes odoo/odoo#140436 Signed-off-by: Julien Mougenot (jum) --- addons/web/static/src/core/utils/draggable_hook_builder.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/core/utils/draggable_hook_builder.js b/addons/web/static/src/core/utils/draggable_hook_builder.js index b7362cdb99e..aec03668919 100644 --- a/addons/web/static/src/core/utils/draggable_hook_builder.js +++ b/addons/web/static/src/core/utils/draggable_hook_builder.js @@ -517,7 +517,7 @@ export function makeDraggableHook(hookParams) { return ( !ctx.tolerance || Math.hypot(pointer.x - initialPosition.x, pointer.y - initialPosition.y) >= - ctx.tolerance + ctx.tolerance ); }; @@ -693,6 +693,9 @@ export function makeDraggableHook(hookParams) { // https://bugzilla.mozilla.org/show_bug.cgi?id=1352061 // https://bugzilla.mozilla.org/show_bug.cgi?id=339293 safePrevent(ev); + if (document.activeElement && !document.activeElement.contains(ev.target)) { + document.activeElement.blur(); + } const { currentTarget, pointerId, target } = ev; ctx.current.initialPosition = { ...ctx.pointer }; @@ -989,7 +992,7 @@ export function makeDraggableHook(hookParams) { // be fired. Note that we DO NOT want to prevent touchstart // events since they're responsible of the native swipe // scrolling. - addListener(el, "touchstart", () => {}, { + addListener(el, "touchstart", () => { }, { passive: false, noAddedStyle: true, });