Skip to content

Commit 96830ae

Browse files
authored
feat(modal): Add support for reserveScrollBarGap prop (#376)
* feat(modal): implement reserveScrollBarGap props * feat(docs): add docs for reserveScrollBarGap * fix(modal): fix missing bracket
1 parent 24d22cb commit 96830ae

File tree

6 files changed

+32
-1
lines changed

6 files changed

+32
-1
lines changed

docs/components/content/Playground.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const getInitialValues = () => ({
1212
escToClose: true,
1313
background: 'non-interactive',
1414
lockScroll: true,
15+
reserveScrollBarGap: true,
1516
swipeToClose: 'none',
1617
})
1718
@@ -71,6 +72,9 @@ function reset() {
7172
<h3>lockScroll:</h3>
7273
<label> <input v-model="options.lockScroll" type="checkbox"> </label>
7374

75+
<h3>reserveScrollBarGap:</h3>
76+
<label> <input v-model="options.reserveScrollBarGap" type="checkbox"> </label>
77+
7478
<h3>swipeToClose: </h3>
7579
<div class="flex flex-col">
7680
<label v-for="value in ['none', 'up', 'right', 'down', 'left']" :key="value" :for="value">
@@ -100,6 +104,7 @@ function reset() {
100104
:esc-to-close="options.escToClose"
101105
:background="options.background"
102106
:lock-scroll="options.lockScroll"
107+
:reserve-scroll-bar-gap="options.reserveScrollBarGap"
103108
:swipe-to-close="options.swipeToClose"
104109
class="flex justify-center items-center"
105110
content-class="max-w-xl mx-4 p-4 bg-white dark:bg-gray-900 border dark:border-gray-700 rounded-lg space-y-2"

docs/content/3.api/1.components/1.vue-final-modal.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ Lock body scroll or not when the modal is opened.
177177
- TS: `PropType<boolean>`{lang=ts}
178178
- Default: `true`{lang=ts}
179179

180+
### reserveScrollBarGap
181+
182+
Creates a padding-right when scroll is locked to prevent the page from jumping.
183+
- Type:
184+
- JS: `Boolean`{lang=ts}
185+
- TS: `PropType<boolean>`{lang=ts}
186+
- Default: `true`{lang=ts}
187+
180188
### zIndexFn
181189

182190
Define how to increase the zIndex when there are nested modals.

docs/content/4.use-cases/1.playground.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ head.title: 'Playground | Examples'
2424
escToClose: true,
2525
background: 'non-interactive',
2626
lockScroll: true,
27+
reserveScrollBarGap: true,
2728
swipeToClose: 'none',
2829
})
2930
@@ -83,6 +84,9 @@ head.title: 'Playground | Examples'
8384
<h3>lockScroll:</h3>
8485
<label> <input v-model="options.lockScroll" type="checkbox"> </label>
8586
87+
<h3>reserveScrollBarGap:</h3>
88+
<label> <input v-model="options.reserveScrollBarGap" type="checkbox"> </label>
89+
8690
<h3>swipeToClose: </h3>
8791
<div class="flex flex-col">
8892
<label v-for="value in ['none', 'up', 'right', 'down', 'left']" :key="value" :for="value">
@@ -112,6 +116,7 @@ head.title: 'Playground | Examples'
112116
:esc-to-close="options.escToClose"
113117
:background="options.background"
114118
:lock-scroll="options.lockScroll"
119+
:reserve-scroll-bar-gap="options.reserveScrollBarGap"
115120
:swipe-to-close="options.swipeToClose"
116121
class="flex justify-center items-center"
117122
content-class="max-w-xl mx-4 p-4 bg-white dark:bg-gray-900 border dark:border-gray-700 rounded-lg space-y-2"

packages/vue-final-modal/src/components/CoreModal/CoreModalProps.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ export const coreModalProps = {
153153
type: Boolean as PropType<boolean>,
154154
default: true,
155155
},
156+
/**
157+
* @description Creates a padding-right when scroll is locked to prevent the page from jumping
158+
* @default `true`
159+
*/
160+
reserveScrollBarGap: {
161+
type: Boolean as PropType<boolean>,
162+
default: true,
163+
},
156164
/**
157165
* @description Define how to increase the zIndex when there are nested modals
158166
* @default `({ index }) => 1000 + 2 * index`

packages/vue-final-modal/src/components/CoreModal/useBodyScrollLock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export function useLockScroll(props: InstanceType<typeof CoreModal>['$props'], o
262262
return
263263
props.lockScroll && _lockScrollEl
264264
&& disableBodyScroll(_lockScrollEl, {
265-
reserveScrollBarGap: true,
265+
reserveScrollBarGap: props.reserveScrollBarGap,
266266
allowTouchMove: (el) => {
267267
while (el && el !== document.body) {
268268
if (el.getAttribute('vfm-scroll-lock-ignore') !== null)

viteplay/src/components/VueFinalModal/Basic.example.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const modal2 = useModal({
5454
5555
const show = ref(false)
5656
const lockScroll = ref(false)
57+
const reserveScrollBarGap = ref(false)
5758
const theModalId = Symbol('theModalId')
5859
5960
function beforeOpen() {
@@ -73,6 +74,9 @@ function clickOutside() {
7374
<button @click="lockScroll = !lockScroll">
7475
toggle lockScroll: {{ lockScroll }}
7576
</button>
77+
<button @click="reserveScrollBarGap = !reserveScrollBarGap">
78+
toggle reserveScrollBarGap: {{ reserveScrollBarGap }}
79+
</button>
7680
<button @click="show = !show">
7781
open vfm
7882
</button>
@@ -95,6 +99,7 @@ function clickOutside() {
9599
class="test-vfm"
96100
:teleport-to="false"
97101
:lock-scroll="lockScroll"
102+
:reserve-scroll-bar-gap="reserveScrollBarGap"
98103
display-directive="show"
99104
:click-to-close="true"
100105
content-transition="vfm-fade"

0 commit comments

Comments
 (0)