Skip to content

Commit c055476

Browse files
committed
remove body-lock-scroll
1 parent 0f1a0e1 commit c055476

File tree

5 files changed

+23
-26
lines changed

5 files changed

+23
-26
lines changed

docs/content/en/properties.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Default transition:
7878
- Type: `Boolean`
7979
- Default: `true`
8080

81-
`vue-final-modal` use [body-lock-scroll](https://www.npmjs.com/package/body-scroll-lock) to disabled the scrolling of body while the modal is displayed.
81+
Disabled the scrolling of body while the modal is displayed.
8282

8383
## `hideOverlay`
8484

lib/VueFinalModal.vue

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
>
4444
<div
4545
ref="vfmContent"
46-
body-scroll-lock-ignore
4746
class="vfm__content vfm--cursor-auto"
4847
:class="[contentClass, { 'vfm--prevent-auto': preventClick }]"
4948
@click.stop
@@ -56,7 +55,7 @@
5655
</template>
5756

5857
<script>
59-
import { disableBodyScroll, enableBodyScroll } from 'body-scroll-lock'
58+
import { setStyle, removeStyle } from './dom.js'
6059
6160
let modalStack = []
6261
@@ -173,7 +172,6 @@ export default {
173172
.forEach((vm, index) => {
174173
if (vm.getAttachElement() === target) {
175174
// if vm and this have the same attach element
176-
enableBodyScroll(vm.$refs.vfmContent)
177175
vm.modalStackIndex = index
178176
vm.visibility.overlay = false
179177
}
@@ -186,8 +184,6 @@ export default {
186184
} else if (target !== false) {
187185
console.warn('Unable to locate target '.concat(this.attach))
188186
}
189-
} else {
190-
this.lockScroll && enableBodyScroll(this.$refs.vfmContent)
191187
}
192188
},
193189
close() {
@@ -203,7 +199,7 @@ export default {
203199
!$_vm.hideOverlay && ($_vm.visibility.overlay = true)
204200
} else {
205201
// If the closed modal is the last one
206-
this.lockScroll && enableBodyScroll(this.$refs.vfmContent)
202+
this.lockScroll && removeStyle(document.body, 'overflow')
207203
}
208204
this.startTransitionLeave()
209205
},
@@ -218,17 +214,8 @@ export default {
218214
handleLockScroll() {
219215
if (this.value) {
220216
this.lockScroll
221-
? disableBodyScroll(this.$refs.vfmContent, {
222-
allowTouchMove: el => {
223-
while (el && el !== document.body) {
224-
if (el.getAttribute('body-scroll-lock-ignore') !== null) {
225-
return true
226-
}
227-
el = el.parentElement
228-
}
229-
}
230-
})
231-
: enableBodyScroll(this.$refs.vfmContent)
217+
? setStyle(document.body, 'overflow', 'hidden')
218+
: removeStyle(document.body, 'overflow')
232219
}
233220
},
234221
getAttachElement() {

lib/dom.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Stolen from bootstrap vue
2+
3+
// Determine if an element is an HTML element
4+
export const isElement = el => !!(el && el.nodeType === Node.ELEMENT_NODE)
5+
6+
// Set an style property on an element
7+
export const setStyle = (el, prop, value) => {
8+
if (prop && isElement(el)) {
9+
el.style[prop] = value
10+
}
11+
}
12+
13+
// Remove an style property from an element
14+
export const removeStyle = (el, prop) => {
15+
if (prop && isElement(el)) {
16+
el.style[prop] = ''
17+
}
18+
}

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
"rollup-plugin-vue": "^5.1.9",
4242
"vue-template-compiler": "^2.6.11"
4343
},
44-
"dependencies": {
45-
"body-scroll-lock": "^3.0.3"
46-
},
4744
"gitHooks": {
4845
"pre-commit": "lint-staged"
4946
},

yarn.lock

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,11 +1949,6 @@ [email protected]:
19491949
raw-body "2.4.0"
19501950
type-is "~1.6.17"
19511951

1952-
body-scroll-lock@^3.0.3:
1953-
version "3.1.5"
1954-
resolved "https://registry.yarnpkg.com/body-scroll-lock/-/body-scroll-lock-3.1.5.tgz#c1392d9217ed2c3e237fee1e910f6cdd80b7aaec"
1955-
integrity sha512-Yi1Xaml0EvNA0OYWxXiYNqY24AfWkbA6w5vxE7GWxtKfzIbZM+Qw+aSmkgsbWzbHiy/RCSkUZBplVxTA+E4jJg==
1956-
19571952
bonjour@^3.5.0:
19581953
version "3.5.0"
19591954
resolved "https://registry.yarnpkg.com/bonjour/-/bonjour-3.5.0.tgz#8e890a183d8ee9a2393b3844c691a42bcf7bc9f5"

0 commit comments

Comments
 (0)