web/elements: properly cleanup event handlers
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
9e2f165dd8
commit
92990b4ded
|
@ -64,14 +64,20 @@ export class ModalButton extends LitElement {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
firstUpdated(): void {
|
||||||
super();
|
window.addEventListener("keyup", this.keyUpHandler);
|
||||||
window.addEventListener("keyup", (e) => {
|
}
|
||||||
|
|
||||||
|
keyUpHandler = (e: KeyboardEvent) => {
|
||||||
if (e.code === "Escape") {
|
if (e.code === "Escape") {
|
||||||
this.resetForms();
|
this.resetForms();
|
||||||
this.open = false;
|
this.open = false;
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
disconnectedCallback(): void {
|
||||||
|
super.disconnectedCallback()
|
||||||
|
window.removeEventListener("keyup", this.keyUpHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
resetForms(): void {
|
resetForms(): void {
|
||||||
|
|
Reference in New Issue