Skip to content

Commit 1f9344d

Browse files
committed
fix: ensure height does not exceed window height and add missing drag event;
1 parent 2d3a3b6 commit 1f9344d

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

package.json

Lines changed: 3 additions & 2 deletions
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.0.5",
35+
"version": "1.0.6",
3636
"type": "module",
3737
"exports": {
3838
".": {
@@ -49,7 +49,8 @@
4949
"scripts": {
5050
"build": "vue-tsc -b && vite build",
5151
"build:watch": "vite build --watch",
52-
"preview": "vite preview"
52+
"preview": "vite preview",
53+
"publish": "npm run build && npm publish --access public"
5354
},
5455
"peerDependencies": {
5556
"vue": ">=3.3",

playground/vue/src/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const close = () => {
2121
<p>vue js: {{ version }}</p>
2222
</div>
2323
<BottomSheet ref="myBottomSheet">
24-
<p v-for="i in 3" :key="i">
24+
<p v-for="i in 5" :key="i">
2525
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Iste aperiam, accusamus amet veniam officiis libero necessitatibus ipsum,
2626
reprehenderit eveniet neque ad delectus fugit!
2727
</p>

src/BottomSheet.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const handleEscapeKey = (e: KeyboardEvent) => {
8282
const open = () => {
8383
if (!sheet.value) return
8484
85-
height.value = props.defaultBreakpoint ?? minSnap.value
85+
height.value = Math.min(props.defaultBreakpoint ?? minSnap.value, windowHeight.value)
8686
8787
set({
8888
height: height.value,
@@ -191,7 +191,8 @@ const handleDragEnd: Handler<'drag', PointerEvent> | undefined = () => {
191191
close()
192192
}
193193
194-
height.value = snapPoints.value[closestSnapPoint.value]
194+
height.value = Math.min(snapPoints.value[closestSnapPoint.value], windowHeight.value)
195+
195196
push('height', height.value, motionProperties, { type: 'tween', easings: 'easeInOut', bounce: 0, duration: 300 })
196197
}
197198
@@ -238,7 +239,7 @@ useGesture(
238239
}
239240
}
240241
},
241-
onDrag: ({ delta }) => {
242+
onDrag: ({ delta, direction }) => {
242243
if (!props.expandOnContentDrag) {
243244
preventScroll.value = false
244245
return
@@ -268,6 +269,8 @@ useGesture(
268269
height.value = maxSnap.value
269270
}
270271
272+
height.value = Math.min(height.value, windowHeight.value)
273+
271274
const isAtTop = sheetScroll.value!.scrollTop === 0
272275
if (snapPoints.value.length === 1) {
273276
if (delta[1] < 0 && translateY.value === 0 && isAtTop) {
@@ -282,6 +285,12 @@ useGesture(
282285
set({
283286
height: height.value,
284287
})
288+
289+
if (direction[1] > 0) {
290+
emit('dragging-down')
291+
} else if (direction[1] < 0) {
292+
emit('dragging-up')
293+
}
285294
},
286295
onDragEnd: handleDragEnd,
287296
},
@@ -297,7 +306,7 @@ watch(minHeightComputed, () => {
297306
if (snapPoints.value.length === 1) {
298307
nextTick(() => {
299308
if (snapPoints.value[0] === minHeightComputed.value) {
300-
snapToPoint(minHeightComputed.value)
309+
snapToPoint(Math.min(minHeightComputed.value, windowHeight.value))
301310
}
302311
})
303312
}

0 commit comments

Comments
 (0)