Skip to content

Commit 46e4311

Browse files
committed
Remove event listener on container on stop
1 parent 89998aa commit 46e4311

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Virtual.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export class Virtual {
205205
#spokenPhraseLog: string[] = [];
206206
#treeCache: AccessibilityNode[] | null = null;
207207
#disconnectDOMObserver: (() => void) | null = null;
208+
#boundHandleFocusChange: ((event: Event) => Promise<void>) | null = null;
208209

209210
#checkContainer() {
210211
if (!this.#container) {
@@ -601,7 +602,9 @@ export class Virtual {
601602
return;
602603
}
603604

604-
this.#container.addEventListener("focusin", this.#handleFocusChange.bind(this));
605+
this.#boundHandleFocusChange = this.#handleFocusChange.bind(this);
606+
607+
this.#container.addEventListener("focusin", this.#boundHandleFocusChange);
605608

606609
this.#updateState(tree[0]);
607610

@@ -631,6 +634,7 @@ export class Virtual {
631634
*/
632635
async stop() {
633636
this.#disconnectDOMObserver?.();
637+
this.#container?.removeEventListener("focusin", this.#boundHandleFocusChange);
634638
this.#invalidateTreeCache();
635639

636640
if (this.#cursor) {
@@ -642,7 +646,7 @@ export class Virtual {
642646
this.#container = null;
643647
this.#itemTextLog = [];
644648
this.#spokenPhraseLog = [];
645-
649+
this.#boundHandleFocusChange = null;
646650
return;
647651
}
648652

0 commit comments

Comments
 (0)