Fix all modals closing on escape key press

This commit is contained in:
Samuel Elliott 2018-07-08 13:52:29 +01:00
parent 98a7a71b87
commit aff89371e6
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
2 changed files with 7 additions and 12 deletions

View File

@ -47,9 +47,12 @@
Events.on('bd-refresh-modals', this.eventListener = () => {
this.$forceUpdate();
});
window.addEventListener('keyup', this.keyupListener);
},
destroyed() {
if (this.eventListener) Events.off('bd-refresh-modals', this.eventListener);
window.removeEventListener('keyup', this.keyupListener);
},
methods: {
closeModal(modal) {
@ -57,6 +60,10 @@
},
downscale(index, times) {
return 1 - ((this.modals.stack.filter(m => !m.closing).length - index) * times);
},
keyupListener(e) {
if (this.modals.stack.length && e.which === 27)
this.modals.closeLast(e.shiftKey);
}
}
}

View File

@ -47,18 +47,6 @@
return {
scrolled: false
};
},
beforeMount() {
window.addEventListener('keyup', this.keyupListener);
},
destroyed() {
window.removeEventListener('keyup', this.keyupListener);
},
methods: {
keyupListener(e) {
if (e.which === 27)
this.$emit('close', false, e);
}
}
}
</script>