Skip to content

Commit

Permalink
refactor: avoid using stop event modifiers #111
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterliu1003 committed Jun 12, 2021
1 parent facad84 commit c500513
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dist/VueFinalModal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/VueFinalModal.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/VueFinalModal.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/VueFinalModal.umd.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions lib/VueFinalModal.vue
Expand Up @@ -40,18 +40,18 @@
role="dialog"
aria-modal="true"
tabindex="-1"
@mouseup.self.stop="onMouseupContainer"
@touchend.self.stop="onMouseupContainer"
@mousedown.self.stop="onMousedown"
@touchstart.self.stop="onMousedown"
@mouseup.self="onMouseupContainer"
@touchend.self="onMouseupContainer"
@mousedown.self="onMousedown"
@touchstart.self="onMousedown"
>
<div
ref="vfmContent"
class="vfm__content"
:class="[contentClass, { 'vfm--prevent-auto': preventClick }]"
:style="bindContentStyle"
@mousedown.self.stop="onMousedown"
@touchstart.self.stop="onMousedown"
@mousedown="onMousedown(null)"
@touchstart="onMousedown(null)"
>
<slot :params="params" :close="() => $emit('input', false)" />
<div
Expand Down Expand Up @@ -437,11 +437,11 @@ export default {
this.params = {}
},
onMousedown(e) {
this.lastMousedownEl = e.target
this.lastMousedownEl = e?.target
},
onMouseupContainer(e) {
// skip when the mousedown didn't start on the container el
if (this.lastMousedownEl !== e.target) return
onMouseupContainer() {
// skip when the lastMousedownEl didn't equal $refs.vfmContainer
if (this.lastMousedownEl !== this.$refs.vfmContainer) return
// skip when state equal 'resize:move'
if (this.state === 'resize:move') return
this.$emit('click-outside', this.createModalEvent({ type: 'click-outside' }))
Expand Down
17 changes: 14 additions & 3 deletions tests/unit/VueFinalModal.spec.js
Expand Up @@ -23,7 +23,16 @@ describe('VueFinalModal.vue', () => {
})
it('clickToClose: true', async () => {
const { wrapper } = await createOpenedModal()
wrapper.find('.vfm__container').trigger('click')
wrapper.find('.vfm__container').trigger('mousedown')
wrapper.find('.vfm__content').trigger('mouseup')
await afterTransition()
expect(wrapper.find('.vfm').isVisible()).toBe(true)
wrapper.find('.vfm__content').trigger('mousedown')
wrapper.find('.vfm__container').trigger('mouseup')
await afterTransition()
expect(wrapper.find('.vfm').isVisible()).toBe(true)
wrapper.find('.vfm__container').trigger('mousedown')
wrapper.find('.vfm__container').trigger('mouseup')
await afterTransition()
expect(wrapper.find('.vfm').isVisible()).toBe(false)
})
Expand Down Expand Up @@ -129,7 +138,8 @@ describe('VueFinalModal.vue', () => {
const { wrapper } = await createOpenedModal({
clickToClose: false
})
wrapper.find('.vfm__container').trigger('click')
wrapper.find('.vfm__container').trigger('mousedown')
wrapper.find('.vfm__container').trigger('mouseup')
await afterTransition()
expect(wrapper.find('.vfm').isVisible()).toBe(true)
})
Expand Down Expand Up @@ -429,7 +439,8 @@ describe('VueFinalModal.vue', () => {
}
}
)
wrapper.find('.vfm__container').trigger('click')
wrapper.find('.vfm__container').trigger('mousedown')
wrapper.find('.vfm__container').trigger('mouseup')
await afterTransition()
expect(clickOutside).toHaveBeenCalled()
expect(beforeOpen).toHaveBeenCalled()
Expand Down

0 comments on commit c500513

Please sign in to comment.