@@ -135,6 +135,7 @@ export function Root({
135
135
const previousDiffFromInitial = React . useRef ( 0 ) ;
136
136
const drawerRef = React . useRef < HTMLDivElement > ( null ) ;
137
137
const drawerHeightRef = React . useRef ( drawerRef . current ?. getBoundingClientRect ( ) . height || 0 ) ;
138
+ const drawerWidthRef = React . useRef ( drawerRef . current ?. getBoundingClientRect ( ) . width || 0 ) ;
138
139
const initialDrawerHeight = React . useRef ( 0 ) ;
139
140
140
141
const onSnapPointChange = React . useCallback ( ( activeSnapPointIndex : number ) => {
@@ -187,6 +188,7 @@ export function Root({
187
188
if ( drawerRef . current && ! drawerRef . current . contains ( event . target as Node ) ) return ;
188
189
189
190
drawerHeightRef . current = drawerRef . current ?. getBoundingClientRect ( ) . height || 0 ;
191
+ drawerWidthRef . current = drawerRef . current ?. getBoundingClientRect ( ) . width || 0 ;
190
192
setIsDragging ( true ) ;
191
193
dragStartTime . current = new Date ( ) ;
192
194
@@ -288,9 +290,11 @@ export function Root({
288
290
// We need to capture last time when drag with scroll was triggered and have a timeout between
289
291
const absDraggedDistance = Math . abs ( draggedDistance ) ;
290
292
const wrapper = document . querySelector ( '[data-vaul-drawer-wrapper]' ) ;
293
+ const drawerDimension =
294
+ direction === 'bottom' || direction === 'top' ? drawerHeightRef . current : drawerWidthRef . current ;
291
295
292
296
// Calculate the percentage dragged, where 1 is the closed position
293
- let percentageDragged = absDraggedDistance / drawerHeightRef . current ;
297
+ let percentageDragged = absDraggedDistance / drawerDimension ;
294
298
const snapPointPercentageDragged = getSnapPointsPercentageDragged ( absDraggedDistance , isDraggingInDirection ) ;
295
299
296
300
if ( snapPointPercentageDragged !== null ) {
0 commit comments