mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-17 13:14:54 +00:00
Close modal with escape key
This commit is contained in:
@@ -9,6 +9,21 @@
|
||||
|
||||
<script>
|
||||
export default {
|
||||
mounted: function () {
|
||||
window.addEventListener('keydown', this.onkey)
|
||||
},
|
||||
beforeUnmount: function () {
|
||||
window.removeEventListener('keydown', this.onkey)
|
||||
},
|
||||
methods: {
|
||||
onkey(event){
|
||||
if(!this.isOpened) { return null }
|
||||
|
||||
if(event.key == 'Escape') {
|
||||
this.closeModal()
|
||||
}
|
||||
}
|
||||
},
|
||||
props: {
|
||||
isOpened: {
|
||||
type: Boolean,
|
||||
|
||||
Reference in New Issue
Block a user