Skip to content

Commit 3e36dec

Browse files
committed
Merge branch 'next' into feature/next-dynamic-modal
2 parents 418d7c2 + f5e48a6 commit 3e36dec

File tree

9 files changed

+73
-51
lines changed

9 files changed

+73
-51
lines changed

.github/ISSUE_TEMPLATE/-question.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,30 @@ assignees: hunterliu1003
88
---
99

1010
<!-- **IMPORTANT!**
11-
Please make sure to look for an answer to your question in our documentation and the documentation before asking a question here.
11+
Before reporting a bug, please make sure that you have read through our documentation and you think your problem is indeed an issue related to our module. -->
12+
13+
### Version
14+
15+
vue-final-modal: <!-- ex: v0.19.0 -->
16+
vue: <!-- ex: v2.6.12 -->
17+
nuxt: <!-- ex: v2.12.0 -->
18+
19+
### OS
20+
21+
Mac or Windows
22+
23+
### Reproduction Link
24+
<!--
25+
A minimal test case based on one of:
26+
- a fork of https://codesandbox.io/s/nuxtcontent-demo-l164h
27+
- a GitHub repository that can reproduce the bug
1228
-->
29+
30+
### Steps to reproduce
31+
32+
33+
### What is Expected?
34+
35+
36+
### What is actually happening?
37+

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.

lib/VueFinalModal.vue

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@
4141
tabindex="-1"
4242
@click.self="onClickContainer"
4343
>
44-
<div
45-
ref="vfmContent"
46-
class="vfm__content"
47-
:class="[contentClass, { 'vfm--prevent-auto': preventClick }]"
48-
:style="contentStyle"
49-
>
44+
<div class="vfm__content" :class="[contentClass, { 'vfm--prevent-auto': preventClick }]" :style="contentStyle">
5045
<slot :params="params" />
5146
</div>
5247
</div>
@@ -105,7 +100,6 @@ export default {
105100
setup(props, { emit }) {
106101
const uid = Symbol('vfm')
107102
const root = ref(null)
108-
const vfmContent = ref(null)
109103
const vfmContainer = ref(null)
110104
111105
const $vfm = inject(props.options.key)
@@ -195,7 +189,7 @@ export default {
195189
})
196190
onBeforeUnmount(() => {
197191
close()
198-
props.lockScroll && enableBodyScroll(vfmContent)
192+
props.lockScroll && enableBodyScroll(vfmContainer.value)
199193
root?.value?.remove()
200194
201195
let index = $vfm.modals.findIndex(vm => vm.uid === uid)
@@ -207,7 +201,6 @@ export default {
207201
props,
208202
emit,
209203
vfmContainer,
210-
vfmContent,
211204
getAttachElement,
212205
modalStackIndex,
213206
visibility,
@@ -278,11 +271,11 @@ export default {
278271
function handleLockScroll() {
279272
if (props.modelValue) {
280273
if (props.lockScroll) {
281-
disableBodyScroll(vfmContent, {
274+
disableBodyScroll(vfmContainer.value, {
282275
reserveScrollBarGap: true
283276
})
284277
} else {
285-
enableBodyScroll(vfmContent)
278+
enableBodyScroll(vfmContainer.value)
286279
}
287280
}
288281
}
@@ -347,7 +340,7 @@ export default {
347340
function afterModalLeave() {
348341
modalTransitionState.value = TransitionState.Leave
349342
modalStackIndex.value = null
350-
props.lockScroll && enableBodyScroll(vfmContent)
343+
props.lockScroll && enableBodyScroll(vfmContainer.value)
351344
352345
let stopEvent = false
353346
const event = createModalEvent({
@@ -402,7 +395,6 @@ export default {
402395
}
403396
return {
404397
root,
405-
vfmContent,
406398
vfmContainer,
407399
visible,
408400
visibility,

lib/utils/bodyScrollLock.js

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,47 @@ const isIosDevice =
2222

2323
let locks = []
2424
let documentListenerAdded = false
25+
let clientY = 0
2526
let initialClientY = -1
2627
let previousBodyOverflowSetting
2728
let previousBodyPaddingRight
2829

29-
// returns true if `el` should be allowed to receive touchmove events.
30-
const allowTouchMove = el =>
31-
locks.some(lock => {
32-
if (lock.options.allowTouchMove && lock.options.allowTouchMove(el)) {
33-
return true
34-
}
30+
const hasScrollbar = el => {
31+
if (!el || el.nodeType !== Node.ELEMENT_NODE) return false
3532

36-
return false
33+
const style = window.getComputedStyle(el)
34+
return ['auto', 'scroll'].includes(style.overflowY) && el.scrollHeight > el.clientHeight
35+
}
36+
37+
const shouldScroll = (el, delta) => {
38+
if (el.scrollTop === 0 && delta < 0) return false
39+
if (el.scrollTop + el.clientHeight + delta >= el.scrollHeight && delta > 0) return false
40+
return true
41+
}
42+
43+
const composedPath = el => {
44+
const path = []
45+
while (el) {
46+
path.push(el)
47+
if (el.classList.contains('vfm')) return path
48+
el = el.parentElement
49+
}
50+
return path
51+
}
52+
53+
const hasAnyScrollableEl = (el, delta) => {
54+
let hasAnyScrollableEl = false
55+
const path = composedPath(el)
56+
path.forEach(el => {
57+
if (hasScrollbar(el) && shouldScroll(el, delta)) {
58+
hasAnyScrollableEl = true
59+
}
3760
})
61+
return hasAnyScrollableEl
62+
}
63+
64+
// returns true if `el` should be allowed to receive touchmove events.
65+
const allowTouchMove = el => locks.some(() => hasAnyScrollableEl(el, -clientY))
3866

3967
const preventDefault = rawEvent => {
4068
const e = rawEvent || window.event
@@ -95,7 +123,7 @@ const isTargetElementTotallyScrolled = targetElement =>
95123
targetElement ? targetElement.scrollHeight - targetElement.scrollTop <= targetElement.clientHeight : false
96124

97125
const handleScroll = (event, targetElement) => {
98-
const clientY = event.targetTouches[0].clientY - initialClientY
126+
clientY = event.targetTouches[0].clientY - initialClientY
99127

100128
if (allowTouchMove(event.target)) {
101129
return false
@@ -160,27 +188,6 @@ export const disableBodyScroll = (targetElement, options) => {
160188
}
161189
}
162190

163-
export const clearAllBodyScrollLocks = () => {
164-
if (isIosDevice) {
165-
// Clear all locks ontouchstart/ontouchmove handlers, and the references.
166-
locks.forEach(lock => {
167-
lock.targetElement.ontouchstart = null
168-
lock.targetElement.ontouchmove = null
169-
})
170-
171-
if (documentListenerAdded) {
172-
document.removeEventListener('touchmove', preventDefault, hasPassiveEvents ? { passive: false } : undefined)
173-
documentListenerAdded = false
174-
}
175-
// Reset initial clientY.
176-
initialClientY = -1
177-
} else {
178-
restoreOverflowSetting()
179-
}
180-
181-
locks = []
182-
}
183-
184191
export const enableBodyScroll = targetElement => {
185192
if (!targetElement) {
186193
// eslint-disable-next-line no-console

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-final-modal",
3-
"version": "1.8.5",
3+
"version": "1.8.6",
44
"description": "Vue Final Modal is a renderless, stackable, detachable and lightweight modal component.",
55
"private": false,
66
"main": "dist/VueFinalModal.umd.js",

types/index.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ interface VueFinalModalInfo {
2020
uid: symbol
2121
name: string
2222
emit: SetupContext<EmitsOptions>
23-
vfmContent: Ref<HTMLDivElement>
2423
getAttachElement(): false | HTMLElement
2524
modalStackIndex: Ref<number | null>
2625
visibility: {
@@ -77,8 +76,7 @@ interface DynamicModalData extends DynamicModalOptions {
7776
}
7877

7978
export interface VueFinalModalComponent extends ComponentPublicInstance {
80-
vfmContainer: HTMLDivElement,
81-
vfmContent: HTMLDivElement
79+
vfmContainer: HTMLDivElement
8280
}
8381

8482

0 commit comments

Comments
 (0)