Skip to content

Commit 8dcb218

Browse files
authored
Merge pull request bootstrap-vue#132 from Magnum5234/fix-modal-key-listener
remove event listener on destruction
2 parents f96a3a8 + 7342ddb commit 8dcb218

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

components/modal.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ export default {
9191
if (this.closeOnBackdrop && e.target.id && e.target.id === this.id) {
9292
this.hide();
9393
}
94+
},
95+
pressedButton(e) {
96+
// support for esc key press
97+
const key = e.which || e.keyCode;
98+
if (key === 27) { // 27 is esc
99+
this.hide();
100+
}
94101
}
95102
},
96103
created() {
@@ -99,16 +106,11 @@ export default {
99106
hub.$on('hide::modal', id => id === this.id && this.hide());
100107
},
101108
mounted() {
102-
// support for esc key press
103-
document.addEventListener('keydown', e => {
104-
const key = e.which || e.keyCode;
105-
if (key === 27) { // 27 is esc
106-
this.hide();
107-
}
108-
});
109+
document.addEventListener('keydown', this.pressedButton);
109110
},
110111
destroyed() {
111112
clearTimeout(this._modalAnimation);
113+
document.removeEventListener('keydown', this.pressedButton);
112114
}
113115
};
114116

0 commit comments

Comments
 (0)