Skip to content

Commit 17916b8

Browse files
committed
update
1 parent 4a4c85a commit 17916b8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export function Root({
135135
const previousDiffFromInitial = React.useRef(0);
136136
const drawerRef = React.useRef<HTMLDivElement>(null);
137137
const drawerHeightRef = React.useRef(drawerRef.current?.getBoundingClientRect().height || 0);
138+
const drawerWidthRef = React.useRef(drawerRef.current?.getBoundingClientRect().width || 0);
138139
const initialDrawerHeight = React.useRef(0);
139140

140141
const onSnapPointChange = React.useCallback((activeSnapPointIndex: number) => {
@@ -187,6 +188,7 @@ export function Root({
187188
if (drawerRef.current && !drawerRef.current.contains(event.target as Node)) return;
188189

189190
drawerHeightRef.current = drawerRef.current?.getBoundingClientRect().height || 0;
191+
drawerWidthRef.current = drawerRef.current?.getBoundingClientRect().width || 0;
190192
setIsDragging(true);
191193
dragStartTime.current = new Date();
192194

@@ -288,9 +290,11 @@ export function Root({
288290
// We need to capture last time when drag with scroll was triggered and have a timeout between
289291
const absDraggedDistance = Math.abs(draggedDistance);
290292
const wrapper = document.querySelector('[data-vaul-drawer-wrapper]');
293+
const drawerDimension =
294+
direction === 'bottom' || direction === 'top' ? drawerHeightRef.current : drawerWidthRef.current;
291295

292296
// Calculate the percentage dragged, where 1 is the closed position
293-
let percentageDragged = absDraggedDistance / drawerHeightRef.current;
297+
let percentageDragged = absDraggedDistance / drawerDimension;
294298
const snapPointPercentageDragged = getSnapPointsPercentageDragged(absDraggedDistance, isDraggingInDirection);
295299

296300
if (snapPointPercentageDragged !== null) {

test/src/app/scrollable-with-inputs/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Drawer } from 'vaul';
55
export default function Page() {
66
return (
77
<div className="w-screen h-screen bg-white p-8 flex justify-center items-center" data-vaul-drawer-wrapper="">
8-
<Drawer.Root autoFocus={true}>
8+
<Drawer.Root>
99
<Drawer.Trigger asChild>
1010
<button>Open Drawer</button>
1111
</Drawer.Trigger>

0 commit comments

Comments
 (0)