Merge pull request #1721 from s-r-x/fix/modal-overlay-mouseup
fix: modal backdrop click
This commit is contained in:
@@ -1,6 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<transition name="modal" appear @leave="onTransitionLeaveStart">
|
<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-wrapper">
|
||||||
<div class="modal-container">
|
<div class="modal-container">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
@@ -36,6 +43,7 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
stackId: Math.random(),
|
stackId: Math.random(),
|
||||||
|
shouldCloseOnBackdropClick: true,
|
||||||
// when transition doesn't fire on unmount, we should manually remove the modal from DOM
|
// 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)
|
// (for example, when the parent component of this modal gets destroyed)
|
||||||
shouldCleanupDomOnUnmount: true,
|
shouldCleanupDomOnUnmount: true,
|
||||||
@@ -64,10 +72,21 @@ export default {
|
|||||||
close() {
|
close() {
|
||||||
this.$emit("close")
|
this.$emit("close")
|
||||||
},
|
},
|
||||||
onBackdropClick({ target }) {
|
onBackdropMouseDown({ target }) {
|
||||||
if (!target?.closest(".modal-container")) {
|
this.shouldCloseOnBackdropClick =
|
||||||
|
!this.checkIfTargetInsideModalContent(target)
|
||||||
|
},
|
||||||
|
onBackdropMouseUp({ target }) {
|
||||||
|
if (
|
||||||
|
this.shouldCloseOnBackdropClick &&
|
||||||
|
!this.checkIfTargetInsideModalContent(target)
|
||||||
|
) {
|
||||||
this.close()
|
this.close()
|
||||||
}
|
}
|
||||||
|
this.shouldCloseOnBackdropClick = true
|
||||||
|
},
|
||||||
|
checkIfTargetInsideModalContent($target) {
|
||||||
|
return $target?.closest(".modal-container")
|
||||||
},
|
},
|
||||||
onKeyDown(e) {
|
onKeyDown(e) {
|
||||||
if (e.key === "Escape" && this.stackId === stack.peek()) {
|
if (e.key === "Escape" && this.stackId === stack.peek()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user