Close dialog when ESC key is pressed
This is the only way I was able to get it to work
mounted() {
// Close modal with 'esc' key
document.addEventListener("keydown", (e) => {
if (e.keyCode == 27) {
this.$emit('close');
}
});
},
Add @keydown.esc="dialog = false"
to v-dialog
component
<v-dialog v-model="dialog" @keydown.esc="dialog = false"></v-dialog>
data: () => ({
dialog: false
}),
Working example: https://codepen.io/anon/pen/BJOOOQ
Additionally, if using dialog as custom component then possibly we need to emit input event:
<template>
<v-dialog :value="value" @keydown.esc="$emit('input')">
...