Skip to content

Commit 8ac92ec

Browse files
committed
fix: fixed closing usign esc when has many modal
1 parent 5609f28 commit 8ac92ec

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

src/App.vue

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@
2525
</modal-vue>
2626
<button @click="open" class="button">Click Here</button>
2727

28+
<modal-vue
29+
name="modal2"
30+
:headerOptions="{
31+
title: 'Delete?'
32+
}"
33+
:footerOptions="{
34+
btn1OnClick: () => hell(),
35+
justify: 'flex-start',
36+
}"
37+
:darkMode="false"
38+
@on-close="handleClose2"
39+
>
40+
<div>content</div>
41+
</modal-vue>
42+
<button @click="open2" class="button">Click Here 2</button>
43+
2844
<p v-for="i in 10" :key="i">scroll up</p>
2945
</div>
3046
</template>
@@ -53,6 +69,14 @@ export default {
5369
this.isVisible = true;
5470
this.$vm2.open("modal1");
5571
},
72+
handleClose2() {
73+
this.isVisible = false;
74+
this.$vm2.close("modal2");
75+
},
76+
open2() {
77+
this.isVisible = true;
78+
this.$vm2.open("modal2");
79+
},
5680
},
5781
};
5882
</script>

src/components/Container.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<template>
22
<div
33
class="vm2_wrapper vm2__animate-opacity"
4-
id="vm2__cover_wrapper"
4+
:id="`vm2__cover_wrapper_${name}`"
55
v-show="visible"
66
:class="{ 'vm2__animate-show': blockVisible, 'vm2--dark': darkMode }"
77
:style="{ backgroundColor: wrapperBg }"
88
>
99
<div class="vm2_modal-dialog vm2_settings">
1010
<div
1111
class="vm2_modal-content"
12-
id="vm2_box"
12+
:id="`vm2_box_${name}`"
1313
:style="{ backgroundColor: modalBgColor, color: fontColor }"
1414
>
1515
<withHeader v-if="!noHeader" @on-icon-click="handleClose" :props="{...headerOptions}">
@@ -147,24 +147,24 @@ export default {
147147
mounted() {
148148
// this.blockVisible = !this.visible;
149149
const vm = this;
150-
document.getElementById("vm2__cover_wrapper").onclick = function (e) {
151-
if (!document.getElementById("vm2_box").contains(e.target)) {
150+
document.getElementById(`vm2__cover_wrapper_${vm.name}`).onclick = function (e) {
151+
if (!document.getElementById(`vm2_box_${vm.name}`).contains(e.target)) {
152152
// alert("You clicked outside");
153-
if (document.getElementById("vm2__cover_wrapper").contains(e.target)) {
153+
if (document.getElementById(`vm2__cover_wrapper_${vm.name}`).contains(e.target)) {
154154
// alert("Here");
155155
vm.handleClose();
156156
}
157157
}
158158
};
159-
document.onkeyup = function (e) {
159+
document.addEventListener('keyup', e => {
160160
e = e || window.event;
161161
if (e.keyCode == 27) {
162-
// alert(`Esc key pr/zessed. ${vm.visible}`);
162+
// alert(`Esc key pr/zessed. ${vm.visible} ${vm.name}`);
163163
if (vm.visible == true) {
164164
vm.handleClose();
165165
}
166-
}
167-
};
166+
}
167+
})
168168
},
169169
};
170170
</script>

0 commit comments

Comments
 (0)