Skip to content

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

fix: do not close modal if mousedown event was on the content but mouseup on the backdrop

s-r-xc3411ba0cf32
diff --git a/components/smart/Modal.vue b/components/smart/Modal.vue
index bb4ba26f3..1758d8701 100644
--- a/components/smart/Modal.vue
+++ b/components/smart/Modal.vue
@@ -1,6 +1,13 @@
<template>
<transition name="modal" appear @leave="onTransitionLeaveStart">
- <div ref="modal" class="modal-backdrop" @click="onBackdropClick">
+ <div
+ ref="modal"
+ class="modal-backdrop"
+ @touchstart="onBackdropMouseDown"
+ @touchend="onBackdropMouseUp"
+ @mouseup="onBackdropMouseUp"
+ @mousedown="onBackdropMouseDown"
+ >
<div class="modal-wrapper">
<div class="modal-container">
<div class="modal-header">
@@ -36,6 +43,7 @@ export default {
data() {
return {
stackId: Math.random(),
+ shouldCloseOnBackdropClick: true,
// when transition doesn't fire on unmount, we should manually remove the modal from DOM
// (for example, when the parent component of this modal gets destroyed)
shouldCleanupDomOnUnmount: true,
@@ -64,10 +72,21 @@ export default {
close() {
this.$emit("close")
},
- onBackdropClick({ target }) {
- if (!target?.closest(".modal-container")) {
+ onBackdropMouseDown({ target }) {
+ this.shouldCloseOnBackdropClick =
+ !this.checkIfTargetInsideModalContent(target)
+ },
+ onBackdropMouseUp({ target }) {
+ if (
+ this.shouldCloseOnBackdropClick &&
+ !this.checkIfTargetInsideModalContent(target)
+ ) {
this.close()
}
+ this.shouldCloseOnBackdropClick = true
+ },
+ checkIfTargetInsideModalContent($target) {
+ return $target?.closest(".modal-container")
},
onKeyDown(e) {
if (e.key === "Escape" && this.stackId === stack.peek()) {