From c09e713c6af76e4e2e456118022652378d6cb5dd Mon Sep 17 00:00:00 2001 From: Massi-X Date: Tue, 19 Nov 2024 00:44:54 +0100 Subject: [PATCH 1/2] Distinguish between mouseup and mousedown This prevents the dropdown from closing when the user starts a selection (mousedown) within the input and ends it (mouseup) outside of the input --- src/parts/events.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/parts/events.js b/src/parts/events.js index 6b6d5951..8f675447 100644 --- a/src/parts/events.js +++ b/src/parts/events.js @@ -125,7 +125,13 @@ export default { cb: _CB.onFocusBlur.bind(this) }, { - type: 'click', + type: 'mousedown', + target: document, + cb: _CB.onClickAnywhere.bind(this), + useCapture: true + }, + { + type: 'mouseup', target: document, cb: _CB.onClickAnywhere.bind(this), useCapture: true @@ -720,7 +726,7 @@ export default { this.state.hasFocus = false // do not hide the dropdown if a click was initiated within it and that dropdown belongs to this Tagify instance - if( e.target.closest('.tagify__dropdown') && e.target.closest('.tagify__dropdown').__tagify != this ) + if( e.type != 'mouseup' && (e.target.closest('.tagify__dropdown') && e.target.closest('.tagify__dropdown').__tagify != this) ) this.dropdown.hide() } }, From a22880f922ed14cb63989b190281e0b617a2f544 Mon Sep 17 00:00:00 2001 From: Massi-X Date: Tue, 19 Nov 2024 00:48:48 +0100 Subject: [PATCH 2/2] Fixes previous commit mouseup event isn't really needed and was causing focus loss when clicking a suggestion --- src/parts/events.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/parts/events.js b/src/parts/events.js index 8f675447..b1fff319 100644 --- a/src/parts/events.js +++ b/src/parts/events.js @@ -130,12 +130,6 @@ export default { cb: _CB.onClickAnywhere.bind(this), useCapture: true }, - { - type: 'mouseup', - target: document, - cb: _CB.onClickAnywhere.bind(this), - useCapture: true - }, ] for( e of this.listeners.global ) @@ -726,7 +720,7 @@ export default { this.state.hasFocus = false // do not hide the dropdown if a click was initiated within it and that dropdown belongs to this Tagify instance - if( e.type != 'mouseup' && (e.target.closest('.tagify__dropdown') && e.target.closest('.tagify__dropdown').__tagify != this) ) + if( e.target.closest('.tagify__dropdown') && e.target.closest('.tagify__dropdown').__tagify != this ) this.dropdown.hide() } },