@@ -140,12 +140,19 @@ export const createSheetGesture = (
140140 // Reset positioning styles to allow normal document flow
141141 cachedFooterEl . classList . remove ( 'modal-footer-moving' ) ;
142142 cachedFooterEl . style . removeProperty ( 'position' ) ;
143- cachedFooterEl . style . removeProperty ( 'bottom' ) ;
143+ cachedFooterEl . style . removeProperty ( 'width' ) ;
144+ cachedFooterEl . style . removeProperty ( 'height' ) ;
145+ cachedFooterEl . style . removeProperty ( 'top' ) ;
146+ cachedFooterEl . style . removeProperty ( 'left' ) ;
144147 page ?. style . removeProperty ( 'padding-bottom' ) ;
145148
146149 // Move to page
147150 page ?. appendChild ( cachedFooterEl ) ;
148151 } else {
152+ // Get both the footer and document body positions
153+ const cachedFooterElRect = cachedFooterEl . getBoundingClientRect ( ) ;
154+ const bodyRect = document . body . getBoundingClientRect ( ) ;
155+
149156 // Add padding to the parent element to prevent content from being hidden
150157 // when the footer is positioned absolutely. This has to be done before we
151158 // make the footer absolutely positioned or we may accidentally cause the
@@ -155,13 +162,23 @@ export const createSheetGesture = (
155162
156163 // Apply positioning styles to keep footer at bottom
157164 cachedFooterEl . classList . add ( 'modal-footer-moving' ) ;
165+
166+ // Calculate absolute position relative to body
167+ // We need to subtract the body's offsetTop to get true position within document.body
168+ const absoluteTop = cachedFooterElRect . top - bodyRect . top ;
169+ const absoluteLeft = cachedFooterElRect . left - bodyRect . left ;
170+
171+ // Capture the footer's current dimensions and hard code them during the drag
158172 cachedFooterEl . style . setProperty ( 'position' , 'absolute' ) ;
159- cachedFooterEl . style . setProperty ( 'bottom' , '0' ) ;
173+ cachedFooterEl . style . setProperty ( 'width' , `${ cachedFooterEl . clientWidth } px` ) ;
174+ cachedFooterEl . style . setProperty ( 'height' , `${ cachedFooterEl . clientHeight } px` ) ;
175+ cachedFooterEl . style . setProperty ( 'top' , `${ absoluteTop } px` ) ;
176+ cachedFooterEl . style . setProperty ( 'left' , `${ absoluteLeft } px` ) ;
160177
161178 // Also cache the footer Y position, which we use to determine if the
162179 // sheet has been moved below the footer. When that happens, we need to swap
163180 // the position back so it will collapse correctly.
164- cachedFooterYPosition = cachedFooterEl . getBoundingClientRect ( ) . top + window . scrollY ;
181+ cachedFooterYPosition = absoluteTop ;
165182
166183 document . body . appendChild ( cachedFooterEl ) ;
167184 }
@@ -482,20 +499,20 @@ export const createSheetGesture = (
482499 contentEl . scrollY = true ;
483500 }
484501
502+ /**
503+ * If expandToScroll is disabled, we need to swap
504+ * the footer position to stationary so that it
505+ * will act as it would by default
506+ */
507+ if ( ! expandToScroll ) {
508+ swapFooterPosition ( 'stationary' ) ;
509+ }
510+
485511 return new Promise < void > ( ( resolve ) => {
486512 animation
487513 . onFinish (
488514 ( ) => {
489515 if ( shouldRemainOpen ) {
490- /**
491- * If expandToScroll is disabled, we need to swap
492- * the footer position to stationary so that it
493- * will act as it would by default
494- */
495- if ( ! expandToScroll ) {
496- swapFooterPosition ( 'stationary' ) ;
497- }
498-
499516 /**
500517 * Once the snapping animation completes,
501518 * we need to reset the animation to go
0 commit comments