From 1ca2dcc233c4ffb3e924d2974b7dd243ba428447 Mon Sep 17 00:00:00 2001 From: "Achraf (abz)" Date: Thu, 10 Jun 2021 10:15:57 +0000 Subject: [PATCH] [FIX] web: Prevent quick create from closing after text selection There is a function allowing to close the quick create if we click outside the element. `RecordQuickCreate._onWindowClicked` Except that this function is triggered in a "click" event, so if we click on the quick create element and drag the mouse outside, it will detect that we are outside and close the quick create. This manipulation can happen when you want to select text with the mouse. This PR prevents this behavior by detecting when a click is from the quick create opw-2558932 closes odoo/odoo#72279 X-original-commit: 75538bf2a36aa91df8b183ac21ae99a174e1c2fa Signed-off-by: Achraf --- .../views/kanban/kanban_record_quick_create.js | 16 +++++++++++++++- .../static/tests/legacy/views/kanban_tests.js | 10 +++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/legacy/js/views/kanban/kanban_record_quick_create.js b/addons/web/static/src/legacy/js/views/kanban/kanban_record_quick_create.js index ccd0da2008f..e720691782a 100644 --- a/addons/web/static/src/legacy/js/views/kanban/kanban_record_quick_create.js +++ b/addons/web/static/src/legacy/js/views/kanban/kanban_record_quick_create.js @@ -21,7 +21,9 @@ var RecordQuickCreate = Widget.extend({ 'click .o_kanban_add': '_onAddClicked', 'click .o_kanban_edit': '_onEditClicked', 'click .o_kanban_cancel': '_onCancelClicked', + 'mousedown': '_onMouseDown', }, + mouseDownInside: false, /** * @override @@ -255,6 +257,9 @@ var RecordQuickCreate = Widget.extend({ * @param {MouseEvent} ev */ _onWindowClicked: function (ev) { + var mouseDownInside = this.mouseDownInside; + + this.mouseDownInside = false; // ignore clicks if the quick create is not in the dom if (!document.contains(this.el)) { return; @@ -288,12 +293,21 @@ var RecordQuickCreate = Widget.extend({ } // ignore clicks if target is inside the quick create - if (this.el.contains(ev.target) || this.el === ev.target) { + if (this.el.contains(ev.target) || this.el === ev.target || mouseDownInside) { return; } this.cancel(); }, + /** + * Detects if the click is originally from the quick create + * + * @private + * @param {MouseEvent} ev + */ + _onMouseDown: function(ev){ + this.mouseDownInside = true; + } }); return RecordQuickCreate; diff --git a/addons/web/static/tests/legacy/views/kanban_tests.js b/addons/web/static/tests/legacy/views/kanban_tests.js index 83a30b36c44..37892a2b853 100644 --- a/addons/web/static/tests/legacy/views/kanban_tests.js +++ b/addons/web/static/tests/legacy/views/kanban_tests.js @@ -936,7 +936,7 @@ QUnit.module('Views', { }); QUnit.test('quick create record: cancel and validate without using the buttons', async function (assert) { - assert.expect(8); + assert.expect(9); var nbRecords = 4; var kanban = await createView({ @@ -972,6 +972,14 @@ QUnit.module('Views', { assert.containsNone(kanban, '.o_kanban_quick_create', "the quick create should be destroyed when the user clicks outside"); + // click to input and drag the mouse outside, should not cancel the quick creation + await testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); + $quickCreate = kanban.$('.o_kanban_quick_create'); + await testUtils.dom.triggerMouseEvent($quickCreate.find('input'), 'mousedown'); + await testUtils.dom.click(kanban.$('.o_kanban_group .o_kanban_record:first').first()); + assert.containsOnce(kanban, '.o_kanban_quick_create', + "the quick create should not have been destroyed after clicking outside"); + // click to really add an element await testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first()); $quickCreate = kanban.$('.o_kanban_quick_create');