Et2TreeDropdown: stop constantly listening for document clicks, only listen when open

This commit is contained in:
nathan 2024-09-11 15:02:37 -06:00
parent 1b0f8683bb
commit b7160e6eaf

View File

@ -133,14 +133,11 @@ export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidg
connectedCallback()
{
super.connectedCallback();
document.addEventListener("click", this.handleDocumentClick);
}
disconnectedCallback()
{
super.disconnectedCallback();
document.removeEventListener("click", this.handleDocumentClick);
}
updated(changedProperties : PropertyValues)
@ -242,6 +239,7 @@ export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidg
return undefined;
}
document.addEventListener("click", this.handleDocumentClick);
this.open = true;
this.requestUpdate("open", false)
return this.updateComplete
@ -255,6 +253,8 @@ export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidg
return undefined;
}
document.removeEventListener("click", this.handleDocumentClick);
this.open = false;
this._popup.active = false;
this._searchNode.value = "";
@ -510,10 +510,12 @@ export class Et2TreeDropdown extends SearchMixin<Constructor<any> & Et2InputWidg
{
this._popup.active = false;
this._searchNode.value = "";
document.removeEventListener("click", this.handleDocumentClick);
}
else
{
this._popup.active = true;
document.addEventListener("click", this.handleDocumentClick);
}
this.open = this._popup.active;
this.treeOrSearch = "tree";