Et2Email: More work on actions

- Add Escape closes suggestions
- Better respect preference to close suggestions after selecting
- Fix another lost focus
This commit is contained in:
nathan 2023-12-14 11:16:01 -07:00
parent c306c267ba
commit 61a2c97198

View File

@ -808,18 +808,17 @@ export class Et2Email extends Et2InputWidget(LitElement) implements SearchMixinI
const value = (<string>this.currentOption.value).replaceAll("___", " "); const value = (<string>this.currentOption.value).replaceAll("___", " ");
if(this.currentOption && ["ArrowRight", " ", ...Et2Email.TAG_BREAK].includes(event.key) && this.addAddress(value)) if(this.currentOption && ["ArrowRight", " ", ...Et2Email.TAG_BREAK].includes(event.key) && this.addAddress(value))
{ {
event.preventDefault();
this._search.value = "";
this.open = false;
if(this._close_on_select) if(this._close_on_select)
{ {
this.blur(); this.open = false;
} }
else
{
this._search.focus(); this._search.focus();
} this._search.value = "";
if(event.key !== "Tab")
{
event.stopPropagation(); event.stopPropagation();
event.preventDefault();
}
return; return;
} }
// Navigate options // Navigate options
@ -861,6 +860,11 @@ export class Et2Email extends Et2InputWidget(LitElement) implements SearchMixinI
this.setCurrentOption(suggestions[newIndex]); this.setCurrentOption(suggestions[newIndex]);
} }
else if(["Escape"])
{
this.open = false;
this._search.focus();
}
} }
/** /**
@ -870,24 +874,19 @@ export class Et2Email extends Et2InputWidget(LitElement) implements SearchMixinI
handleSuggestionsMouseUp(event : MouseEvent) handleSuggestionsMouseUp(event : MouseEvent)
{ {
const value = ((<SlOption>event.target).value).replaceAll("___", " "); const value = ((<SlOption>event.target).value).replaceAll("___", " ");
this.value.push(value); this.addAddress(value);
this.open = false;
this._search.value = ""; this._search.value = "";
this._search.focus();
this.requestUpdate("value"); this.requestUpdate("value");
if(this._close_on_select) if(this._close_on_select)
{ {
this.blur(); this.open = false;
}
else
{
this._search.focus();
} }
} }
handleTagChange(event) handleTagChange(event)
{ {
// Need to update our value, or it will just redo the tag with the old value // Need to update our value, or it will just redo the tag with the old value
debugger;
if(event.originalValue && this.value.indexOf(event.originalValue)) if(event.originalValue && this.value.indexOf(event.originalValue))
{ {
let index = this.value.indexOf(event.originalValue); let index = this.value.indexOf(event.originalValue);
@ -897,7 +896,6 @@ export class Et2Email extends Et2InputWidget(LitElement) implements SearchMixinI
if(event.target.current) if(event.target.current)
{ {
this.setCurrentTag(event.target); this.setCurrentTag(event.target);
;
} }
} }