add keyup to close modal

This commit is contained in:
Jiiks 2018-02-04 14:19:12 +02:00
parent 230e9e6560
commit 18926dd58a
2 changed files with 15 additions and 0 deletions

View File

@ -40,6 +40,7 @@
hideSettings() { this.active = false },
toggleSettings() { this.active = !this.active },
keyupListener(e) {
if (document.getElementsByClassName('bd-backdrop').length) return;
if (this.active && e.which === 27) return this.hideSettings();
if (!e.metaKey && !e.ctrlKey || e.key !== 'b') return;
this.toggleSettings();

View File

@ -44,6 +44,20 @@
return {
scrolled: false
};
},
beforeMount() {
window.addEventListener('keyup', this.keyupListener);
},
destroyed() {
window.removeEventListener('keyup', this.keyupListener);
},
methods: {
keyupListener(e) {
console.log('key up!');
if (e.which === 27) {
this.close();
}
}
}
}
</script>