Skip to content

Commit c906ea5

Browse files
committed
fix: remove document listener on keydown after closing modal
1 parent 08c03c5 commit c906ea5

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

_build/js/src/ui/localChat/modalHeader.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,15 @@ export const buildModalHeader = () => {
9191
});
9292
});
9393

94-
document.addEventListener('keydown', (e) => {
94+
const onKeyDown = (e: KeyboardEvent) => {
9595
if (e.key === 'Escape') {
9696
e.preventDefault();
9797
closeModal();
98+
document.removeEventListener('keydown', onKeyDown);
9899
}
99-
});
100+
};
101+
102+
document.addEventListener('keydown', onKeyDown);
100103

101104
globalState.modal.closeModalBtn = closeModalBtn;
102105

0 commit comments

Comments
 (0)