Skip to content

Commit b8fdaf5

Browse files
committed
Merge branch 'bugfix/do-not-close-modal-when-select-text' into v3
2 parents 381d6c3 + 836deb0 commit b8fdaf5

File tree

18 files changed

+66
-28
lines changed

18 files changed

+66
-28
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- [ ] Feature
2+
- [ ] Feature review
3+
- [ ] Unit test
4+
- [ ] Unit test review
5+
- [ ] Docs
6+
- [ ] Docs review

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
## 🎉 [Documentation](https://vue-final-modal.org)
3030

31-
3231
## 🙌 [Examples](https://vue-final-modal.org/examples/liveDemo)
3332

3433
## Introduction

dist/VueFinalModal.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.esm.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/VueFinalModal.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/components/examples/basic/VDynamicModal.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<template>
2-
<vue-final-modal v-bind="$attrs" classes="modal-container" content-class="modal-content" v-on="$listeners">
2+
<vue-final-modal
3+
v-slot="{ close }"
4+
v-bind="$attrs"
5+
classes="modal-container"
6+
content-class="modal-content"
7+
v-on="$listeners"
8+
>
39
<button class="modal__close" @click="close">
410
<mdi-close></mdi-close>
511
</button>
@@ -12,12 +18,7 @@
1218

1319
<script>
1420
export default {
15-
inheritAttrs: false,
16-
methods: {
17-
close() {
18-
this.$emit('input', false)
19-
}
20-
}
21+
inheritAttrs: false
2122
}
2223
</script>
2324

docs/content/en/examples/liveDemo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ position: 9
77
version: 3
88
---
99

10-
<basic-options></basic-options>
10+
<basic-options></basic-options>

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@nuxt/content-theme-docs": "0.10.0",
1313
"nuxt": "^2.14.12",
14-
"vue-final-modal": "^2.3.1"
14+
"vue-final-modal": "^2.3.2"
1515
},
1616
"devDependencies": {
1717
"@nuxtjs/google-analytics": "^2.4.0",

docs/static/preview.png

636 Bytes
Loading

docs/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10608,10 +10608,10 @@ vue-client-only@^2.0.0:
1060810608
resolved "https://registry.yarnpkg.com/vue-client-only/-/vue-client-only-2.0.0.tgz#ddad8d675ee02c761a14229f0e440e219de1da1c"
1060910609
integrity sha512-arhk1wtWAfLsJyxGMoEYhoBowM87/i6HLSG2LH/03Yog6i2d9JEN1peMP0Ceis+/n9DxdenGYZZTxbPPJyHciA==
1061010610

10611-
vue-final-modal@^2.3.1:
10612-
version "2.3.1"
10613-
resolved "https://registry.yarnpkg.com/vue-final-modal/-/vue-final-modal-2.3.1.tgz#d2c88359b29c40371c6f05abe45e8163cdbce43c"
10614-
integrity sha512-IiV202PnW22Dt+Dp1krpGt3BMe6c/HmtVSNQuPwDA31vpbiHj5rmA1R25uKzN6WNqHW/Dw4lVuYVL4ei6EjW1w==
10611+
vue-final-modal@^2.3.2:
10612+
version "2.3.2"
10613+
resolved "https://registry.yarnpkg.com/vue-final-modal/-/vue-final-modal-2.3.2.tgz#df3974104bbea2d5632fdea58e80e390a1255953"
10614+
integrity sha512-W/A49pkMjua3Ktfo2qPoxmDme5rD01SbtVM0XjHmwYXU6x7BbkgKcqQQz7GAyALklM3D244QY3f+CuhcMWZbLQ==
1061510615
dependencies:
1061610616
vue "^2.6.12"
1061710617

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
<div id="app"></div>
1111
<script type="module" src="/src/main.js"></script>
1212
</body>
13-
</html>
13+
</html>

example/src/components/basic/BasicOptions.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ const initData = () => ({
209209
attachTo: '#attach',
210210
focusRetain: true,
211211
focusTrap: false,
212-
focusTrap: false,
213212
drag: false,
214213
fitParent: true,
215214
keepChangedStyle: false,

lib/VueFinalModal.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@
3939
role="dialog"
4040
aria-modal="true"
4141
tabindex="-1"
42-
@click.self="onClickContainer"
42+
@mouseup.self="onMouseupContainer"
43+
@mousedown.self="onMousedown"
4344
>
4445
<div
4546
ref="vfmContent"
4647
class="vfm__content"
4748
:class="[contentClass, { 'vfm--prevent-auto': preventClick }]"
4849
:style="bindContentStyle"
50+
@mousedown="onMousedown(null)"
4951
>
5052
<slot :params="params" :close="() => $emit('update:modelValue')" />
5153
<div
@@ -198,6 +200,8 @@ export default {
198200
const params = ref({})
199201
const dragResizeStyle = ref({})
200202
const _state = ref(null)
203+
const lastMousedownEl = ref(null)
204+
201205
let resolveToggle = noop
202206
let rejectToggle = noop
203207
@@ -497,7 +501,12 @@ export default {
497501
if (stopEvent) return
498502
params.value = {}
499503
}
500-
function onClickContainer() {
504+
function onMousedown(e) {
505+
lastMousedownEl.value = e?.target
506+
}
507+
function onMouseupContainer() {
508+
// skip when the lastMousedownEl didn't equal vfmContainer
509+
if (lastMousedownEl.value !== vfmContainer.value) return
501510
// skip when state equal 'resize:move'
502511
if (_state.value === 'resize:move') return
503512
emit('click-outside', createModalEvent({ type: 'click-outside' }))
@@ -655,7 +664,7 @@ export default {
655664
if (state === STATE_RESIZE) {
656665
resetBodyCursor && resetBodyCursor()
657666
}
658-
// Excute onClickContainer before trigger emitState
667+
// Excute onMouseupContainer before trigger emitState
659668
setTimeout(() => {
660669
emitState(e, state, 'end')
661670
})
@@ -757,7 +766,8 @@ export default {
757766
afterModalEnter,
758767
beforeModalLeave,
759768
afterModalLeave,
760-
onClickContainer,
769+
onMousedown,
770+
onMouseupContainer,
761771
onEsc
762772
}
763773
}

tests/unit/VueFinalModal.spec.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ describe('VueFinalModal.vue', () => {
2525
})
2626
it('clickToClose: true', async () => {
2727
const { wrapper } = await createOpenedModal()
28-
wrapper.find('.vfm__container').trigger('click')
28+
wrapper.find('.vfm__container').trigger('mousedown')
29+
wrapper.find('.vfm__content').trigger('mouseup')
30+
await afterTransition()
31+
expect(wrapper.find('.vfm').isVisible()).toBe(true)
32+
wrapper.find('.vfm__content').trigger('mousedown')
33+
wrapper.find('.vfm__container').trigger('mouseup')
34+
await afterTransition()
35+
expect(wrapper.find('.vfm').isVisible()).toBe(true)
36+
wrapper.find('.vfm__container').trigger('mousedown')
37+
wrapper.find('.vfm__container').trigger('mouseup')
2938
await afterTransition()
3039
expect(wrapper.find('.vfm').isVisible()).toBe(false)
3140
wrapper.unmount()
@@ -145,7 +154,8 @@ describe('VueFinalModal.vue', () => {
145154
const { wrapper } = await createOpenedModal({
146155
clickToClose: false
147156
})
148-
wrapper.find('.vfm__container').trigger('click')
157+
wrapper.find('.vfm__container').trigger('mousedown')
158+
wrapper.find('.vfm__container').trigger('mouseup')
149159
await afterTransition()
150160
expect(wrapper.find('.vfm').isVisible()).toBe(true)
151161
wrapper.unmount()
@@ -199,6 +209,18 @@ describe('VueFinalModal.vue', () => {
199209
expect(wrapper.vm.$el.parentNode === elem).toBe(true)
200210
wrapper.unmount()
201211
})
212+
it('attach: wrong querySelector', async () => {
213+
global.console.warn = jest.fn()
214+
const spy = jest.spyOn(global.console, 'warn')
215+
const attach = '.selector-not-exist-in-dom'
216+
const { wrapper } = await createClosedModal({
217+
attach
218+
})
219+
wrapper.setProps({ modelValue: true })
220+
await afterTransition()
221+
expect(spy).toHaveBeenCalledTimes(1)
222+
expect(spy.mock.calls[0][0]).toContain(attach)
223+
})
202224
it('focusRetain: false', async () => {
203225
const { wrapper } = await createOpenedModal({
204226
focusRetain: false
@@ -385,7 +407,8 @@ describe('VueFinalModal.vue', () => {
385407
}
386408
}
387409
)
388-
wrapper.find('.vfm__container').trigger('click')
410+
wrapper.find('.vfm__container').trigger('mousedown')
411+
wrapper.find('.vfm__container').trigger('mouseup')
389412
await afterTransition()
390413
expect(clickOutside).toHaveBeenCalled()
391414
expect(beforeOpen).toHaveBeenCalled()

vetur/tags.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
],
3636
"description": ""
3737
}
38-
}
38+
}

0 commit comments

Comments
 (0)