@@ -140,12 +140,19 @@ export const createSheetGesture = (
140
140
// Reset positioning styles to allow normal document flow
141
141
cachedFooterEl . classList . remove ( 'modal-footer-moving' ) ;
142
142
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' ) ;
144
147
page ?. style . removeProperty ( 'padding-bottom' ) ;
145
148
146
149
// Move to page
147
150
page ?. appendChild ( cachedFooterEl ) ;
148
151
} else {
152
+ // Get both the footer and document body positions
153
+ const cachedFooterElRect = cachedFooterEl . getBoundingClientRect ( ) ;
154
+ const bodyRect = document . body . getBoundingClientRect ( ) ;
155
+
149
156
// Add padding to the parent element to prevent content from being hidden
150
157
// when the footer is positioned absolutely. This has to be done before we
151
158
// make the footer absolutely positioned or we may accidentally cause the
@@ -155,13 +162,23 @@ export const createSheetGesture = (
155
162
156
163
// Apply positioning styles to keep footer at bottom
157
164
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
158
172
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` ) ;
160
177
161
178
// Also cache the footer Y position, which we use to determine if the
162
179
// sheet has been moved below the footer. When that happens, we need to swap
163
180
// the position back so it will collapse correctly.
164
- cachedFooterYPosition = cachedFooterEl . getBoundingClientRect ( ) . top + window . scrollY ;
181
+ cachedFooterYPosition = absoluteTop ;
165
182
166
183
document . body . appendChild ( cachedFooterEl ) ;
167
184
}
@@ -482,20 +499,20 @@ export const createSheetGesture = (
482
499
contentEl . scrollY = true ;
483
500
}
484
501
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
+
485
511
return new Promise < void > ( ( resolve ) => {
486
512
animation
487
513
. onFinish (
488
514
( ) => {
489
515
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
-
499
516
/**
500
517
* Once the snapping animation completes,
501
518
* we need to reset the animation to go
0 commit comments