Skip to content

Commit

Permalink
feat(LostFocusController): add an additional waiter
Browse files Browse the repository at this point in the history
Fixes #1155
  • Loading branch information
pdesoyres-cc committed Nov 8, 2024
1 parent 322860b commit 509524b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/controllers/lost-focus-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,28 @@ export class LostFocusController {
* @param {LitElement} host the custom element
* @param {string} selector the query selector that will select the elements we want to listen to
* @param {LostFocusCallback} callback
* @param {() => Promise<void>} [additionalWaiter]
*/
constructor(host, selector, callback) {
constructor(host, selector, callback, additionalWaiter) {
host.addController(this);
this.host = host;
this.selector = selector;
/** @type {Array<Element>} */
this.elements = [];
this.callback = callback;
this.additionalWaiter = additionalWaiter;
}

hostUpdate() {
// memorize the active element so that we are able to check if a deleted element was a parent of the focused element.
this.activeElement = findActiveElement();
}

hostUpdated() {
async hostUpdated() {
if (this.additionalWaiter) {
await this.additionalWaiter();
}

// keep the previous elements because we will want to compare with the new ones
const previousElements = this.elements;
// get the elements we are interested in
Expand Down

0 comments on commit 509524b

Please sign in to comment.