mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-23 15:41:33 +00:00
Escape key closes down modal
This commit is contained in:
@@ -8,7 +8,22 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { onBeforeUnmount } from 'vue';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
setup({closeModal}){
|
||||||
|
let onKeydown = (event) => {
|
||||||
|
if(event.key == 'Escape') {
|
||||||
|
closeModal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('keydown', onKeydown)
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener('keydown', onKeydown)
|
||||||
|
})
|
||||||
|
},
|
||||||
props: {
|
props: {
|
||||||
closeModal: {
|
closeModal: {
|
||||||
type: Function,
|
type: Function,
|
||||||
|
|||||||
Reference in New Issue
Block a user