From 3e1b1e56dcfcf85fbd9a46019965bfa413d990d2 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 9 May 2023 14:04:02 -0600 Subject: [PATCH] Fix focussed select does not close when it loses focus Mail reply moves focus from To: to body, and To dropdown stayed open --- api/js/etemplate/Et2Select/Et2Select.ts | 20 ++++++++++++++++++++ mail/js/app.js | 11 +++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2Select.ts b/api/js/etemplate/Et2Select/Et2Select.ts index bbf23e8ae4..eaa7021f82 100644 --- a/api/js/etemplate/Et2Select/Et2Select.ts +++ b/api/js/etemplate/Et2Select/Et2Select.ts @@ -713,6 +713,15 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect) return tag; } + blur() + { + if(typeof super.blur == "function") + { + super.blur(); + } + this.dropdown.hide(); + } + private handleTagRemove(event : CustomEvent, option) { event.stopPropagation(); @@ -758,6 +767,17 @@ export class Et2Select extends Et2WithSearchMixin(Et2WidgetWithSelect) } } + private et2HandleBlur(event : Event) + { + if(typeof super.et2HandleBlur === "function") + { + super.et2HandleBlur(event); + } + console.log("Blur event"); + + this.dropdown?.hide(); + } + /** * Always close the dropdown if an option is clicked, even if multiple=true. This differs from SlSelect, * which leaves the dropdown open for multiple=true diff --git a/mail/js/app.js b/mail/js/app.js index 45b049fa1f..65223c5562 100644 --- a/mail/js/app.js +++ b/mail/js/app.js @@ -400,6 +400,11 @@ app.classes.mail = AppJS.extend( var content = this.et2.getArrayMgr('content').data; if (to && to.get_value() && to.get_value().length > 0) { + if (typeof to.blur == "function") + { + // html area changes focus as part of its init, make sure it doesn't re-focus to + to.blur(); + } if (content.is_plain) { // focus @@ -407,9 +412,11 @@ app.classes.mail = AppJS.extend( // get the cursor to the top of the textarea if (typeof plainText.getDOMNode().setSelectionRange !='undefined' && !jQuery(plainText.getDOMNode()).is(":hidden")) { - setTimeout(function(){ - plainText.getDOMNode().setSelectionRange(0,0) + setTimeout(function () + { + plainText.getDOMNode().setSelectionRange(0, 0) plainText.focus(); + plainText.shadowRoot.querySelector("textarea").scrollTop = 0; }, 2000); } }