Skip to content

Commit d17434e

Browse files
committed
feat: prevent scroll during drag on header and footer;
1 parent 97b7d2a commit d17434e

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"url": "https://github.com/megaarmos/vue-spring-bottom-sheet/issues"
3333
},
3434
"private": false,
35-
"version": "1.2.4",
35+
"version": "1.2.5",
3636
"type": "module",
3737
"exports": {
3838
".": {

src/BottomSheet.vue

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,11 @@ const backdropClick = () => {
153153
if (props.canBackdropClose) close()
154154
}
155155
156-
// Scroll prevention handler
156+
function handleTouchMove(event: TouchEvent) {
157+
preventScroll.value = true
158+
handleSheetScroll(event)
159+
}
160+
157161
function handleSheetScroll(event: TouchEvent) {
158162
if (preventScroll.value) {
159163
event.preventDefault()
@@ -235,13 +239,15 @@ const handleDragEnd: Handler<'drag', PointerEvent> | undefined = () => {
235239
})
236240
}
237241
242+
const handleDragStart = () => {
243+
height.value = sheetHeight.value
244+
translateY.value = motionValues.value.y!.get()
245+
stopMotion()
246+
}
247+
238248
useGesture(
239249
{
240-
onDragStart: () => {
241-
height.value = sheetHeight.value
242-
translateY.value = motionValues.value.y!.get()
243-
stopMotion()
244-
},
250+
onDragStart: handleDragStart,
245251
onDrag: handleDrag,
246252
onDragEnd: handleDragEnd,
247253
},
@@ -253,11 +259,7 @@ useGesture(
253259
254260
useGesture(
255261
{
256-
onDragStart: () => {
257-
height.value = sheetHeight.value
258-
translateY.value = motionValues.value.y!.get()
259-
stopMotion()
260-
},
262+
onDragStart: handleDragStart,
261263
onDrag: handleDrag,
262264
onDragEnd: handleDragEnd,
263265
},
@@ -424,7 +426,7 @@ defineExpose({ open, close, snapToPoint })
424426
data-vsbs-sheet
425427
tabindex="-1"
426428
>
427-
<div ref="sheetHeader" data-vsbs-header>
429+
<div ref="sheetHeader" data-vsbs-header @touchmove="handleTouchMove">
428430
<slot name="header" />
429431
</div>
430432

@@ -436,7 +438,7 @@ defineExpose({ open, close, snapToPoint })
436438
</div>
437439
</div>
438440

439-
<div ref="sheetFooter" data-vsbs-footer>
441+
<div ref="sheetFooter" data-vsbs-footer @touchmove="handleTouchMove">
440442
<slot name="footer" />
441443
</div>
442444
</div>

0 commit comments

Comments
 (0)