Skip to content

Commit

Permalink
fix(a11y): destroy listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Jun 23, 2024
1 parent 8d5ad54 commit 497f742
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion abstract/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { startKeyUX, hiddenKeyUX, jumpKeyUX, focusGroupKeyUX, pressKeyUX } from
* @implements {MinimalWindow}
*/
class ScopedMinimalWindow {
/** @private */
/**
* @private
* @type {Map<Function, (event: Event) => void>}
*/
_listeners = new Map();

/**
Expand Down Expand Up @@ -50,6 +53,7 @@ class ScopedMinimalWindow {
if (wrappedListener) {
window.removeEventListener(type, wrappedListener);
}
this._listeners.delete(listener);
}

get document() {
Expand All @@ -67,6 +71,11 @@ class ScopedMinimalWindow {

destroy() {
this._scope = [];
this._listeners.forEach((listener, originalListener) => {
window.removeEventListener('keydown', listener);
window.removeEventListener('keyup', listener);
this._listeners.delete(originalListener);
});
}
}

Expand Down

0 comments on commit 497f742

Please sign in to comment.