Skip to content

Commit 70af202

Browse files
committed
fix: issue with css modal flash with snap drawer
1 parent 57ce77b commit 70af202

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

lib/Drawer/components/Root.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,15 @@ const drawerRef = ref<ComponentPublicInstance | null>(null);
213213
const drawerHeightRef = ref(drawerRef.value?.$el.getBoundingClientRect().height || 0);
214214
const drawerWidthRef = ref(drawerRef.value?.$el.getBoundingClientRect().width || 0);
215215
216+
216217
const {
217218
activeSnapPoint,
218219
activeSnapPointIndex,
219220
onRelease: onReleaseSnapPoints,
220221
snapPointsOffset,
221222
onDrag: onDragSnapPoints,
222223
shouldFade,
223-
getPercentageDragged: getSnapPointsPercentageDragged,
224+
getPercentageDragged: getSnapPointsPercentageDragged
224225
} = useSnapPoints({
225226
snapPoints,
226227
activeSnapPointProp: toRef(() => activeSnapPointProp) as Ref<number | string | null>,
@@ -231,6 +232,7 @@ const {
231232
onSnapPointChange,
232233
direction,
233234
snapToSequentialPoint,
235+
isOpen
234236
});
235237
236238
function onSnapPointChange(activeSnapPointIndex: number, snapPointsOffset: number[]) {

lib/Drawer/useSnapPoints.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ref, computed, onBeforeUnmount, onMounted, watchEffect } from 'vue'
1+
import { ref, computed, onBeforeUnmount, onMounted, watch } from 'vue'
22
import type { Ref, ComponentPublicInstance } from 'vue'
33

44
import { set, isVertical } from './helpers.ts';
@@ -15,6 +15,7 @@ export function useSnapPoints({
1515
onSnapPointChange,
1616
direction = 'bottom',
1717
snapToSequentialPoint,
18+
isOpen
1819
}: {
1920
activeSnapPointProp?: Ref<number | string | null>;
2021
setActiveSnapPointProp?(snapPoint: number | null | string): void;
@@ -25,8 +26,9 @@ export function useSnapPoints({
2526
onSnapPointChange(activeSnapPointIndex: number, snapPointsOffset: number[]): void;
2627
direction?: DrawerDirection;
2728
snapToSequentialPoint?: boolean;
29+
isOpen: Ref<boolean>;
2830
}) {
29-
31+
3032
const _activeSnapPoint = ref(snapPoints?.[0] ?? null)
3133

3234
const activeSnapPoint = computed({
@@ -143,17 +145,18 @@ export function useSnapPoints({
143145
activeSnapPoint.value = snapPoints?.[Math.max(newSnapPointIndex, 0)] ?? null
144146
}
145147

146-
watchEffect(() => {
148+
watch([activeSnapPoint, activeSnapPointProp, snapPointsOffset, isOpen], () => {
147149
if (activeSnapPoint.value || activeSnapPointProp?.value) {
148150
const newIndex =
149151
snapPoints?.findIndex((snapPoint) => snapPoint === activeSnapPointProp?.value || snapPoint === activeSnapPoint.value) ?? -1;
150152
if (snapPointsOffset.value && newIndex !== -1 && typeof snapPointsOffset.value[newIndex] === 'number') {
151153
snapToPoint(snapPointsOffset.value[newIndex] as number);
152154
}
153-
}
155+
}
156+
}, {
157+
immediate: true
154158
})
155159

156-
157160
function onRelease({
158161
draggedDistance,
159162
closeDrawer,

src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import NestedDrawer from './components/NestedDrawer.vue'
77

88
<template>
99
<SnapDrawer/>
10+
<!-- <DefaultDrawer/> -->
1011
</template>

src/components/SnapDrawer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const snap = ref<string | number | null>(snapPoints[0])
1717
<Drawer.Trigger class="relative flex h-10 flex-shrink-0 items-center justify-center gap-2 overflow-hidden rounded-full bg-white px-4 text-sm font-medium shadow-sm transition-all hover:bg-[#FAFAFA] dark:bg-[#161615] dark:hover:bg-[#1A1A19] dark:text-white">
1818
Open Drawer
1919
</Drawer.Trigger>
20-
<Drawer.Overlay class="fixed inset-0 bg-black/40" />
2120
<Drawer.Portal>
21+
<Drawer.Overlay class="fixed inset-0 bg-black/40" />
2222
<Drawer.Content
2323
data-testid="content"
2424
class="fixed flex flex-col bg-white border border-gray-200 border-b-none rounded-t-[10px] bottom-0 left-0 right-0 h-full max-h-[97%] mx-[-1px]"

0 commit comments

Comments
 (0)