Fix focussed select does not close when it loses focus

Mail reply moves focus from To: to body, and To dropdown stayed open
This commit is contained in:
nathan 2023-05-09 14:04:02 -06:00
parent db8bd9dcc3
commit 3e1b1e56dc
2 changed files with 29 additions and 2 deletions

View File

@ -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

View File

@ -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);
}
}