Skip to content

Commit 0e28fb9

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/js-yaml-4.1.1
2 parents 2c07d53 + 00ed02f commit 0e28fb9

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

frontend/src/views/Shop.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,16 @@ export default {
232232
code: null,
233233
}
234234
},
235+
beforeUnmount() {
236+
document.removeEventListener('keydown', this.handleEscKey)
237+
},
235238
methods: {
236239
openModal(product) {
237240
this.product = product
238241
this.modalOpen = true
242+
// Remove first to prevent duplicate event listeners
243+
document.removeEventListener('keydown', this.handleEscKey)
244+
document.addEventListener('keydown', this.handleEscKey)
239245
},
240246
closeModal() {
241247
this.product = null
@@ -246,6 +252,12 @@ export default {
246252
this.purchaseSuccess = false
247253
this.code = null
248254
this.purchaseMode = 'myself'
255+
document.removeEventListener('keydown', this.handleEscKey)
256+
},
257+
handleEscKey(event) {
258+
if (event.key === 'Escape' && this.modalOpen) {
259+
this.closeModal()
260+
}
249261
},
250262
async purchase() {
251263
this.loading = true

0 commit comments

Comments
 (0)