File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments