@@ -84,6 +84,7 @@ export const createSheetGesture = (
8484 let offset = 0 ;
8585 let canDismissBlocksGesture = false ;
8686 let cachedScrollEl : HTMLElement | null = null ;
87+ let cachedFooterEl : HTMLIonFooterElement | null = null ;
8788 let cachedFooterYPosition : number | null = null ;
8889 let currentFooterState : 'moving' | 'stationary' | null = null ;
8990 const canDismissMaxStep = 0.95 ;
@@ -125,33 +126,44 @@ export const createSheetGesture = (
125126 * @param footer Whether the footer is in a moving or stationary position.
126127 */
127128 const swapFooterPosition = ( newPosition : 'moving' | 'stationary' ) => {
128- const originalFooter = baseEl . querySelector ( 'ion-footer' ) as HTMLIonFooterElement | null ;
129- if ( ! originalFooter ) {
130- return ;
129+ if ( ! cachedFooterEl ) {
130+ cachedFooterEl = baseEl . querySelector ( 'ion-footer' ) as HTMLIonFooterElement | null ;
131+ if ( ! cachedFooterEl ) {
132+ return ;
133+ }
131134 }
132135
136+ const page = baseEl . querySelector ( '.ion-page' ) as HTMLElement | null ;
137+
133138 currentFooterState = newPosition ;
134139 if ( newPosition === 'stationary' ) {
135140 // Reset positioning styles to allow normal document flow
136- originalFooter . style . removeProperty ( 'position' ) ;
137- originalFooter . style . removeProperty ( 'bottom' ) ;
138- originalFooter . parentElement ?. style . removeProperty ( 'padding-bottom' ) ;
141+ cachedFooterEl . style . removeProperty ( 'position' ) ;
142+ cachedFooterEl . style . removeProperty ( 'bottom' ) ;
143+ page ?. style . removeProperty ( 'padding-bottom' ) ;
144+
145+ // Move to page
146+ console . log ( 'Moving footer to page' ) ;
147+ page ?. appendChild ( cachedFooterEl ) ;
139148 } else {
140149 // Add padding to the parent element to prevent content from being hidden
141150 // when the footer is positioned absolutely. This has to be done before we
142151 // make the footer absolutely positioned or we may accidentally cause the
143152 // sheet to scroll.
144- const footerHeight = originalFooter . clientHeight ;
145- originalFooter . parentElement ?. style . setProperty ( 'padding-bottom' , `${ footerHeight } px` ) ;
153+ const footerHeight = cachedFooterEl . clientHeight ;
154+ page ?. style . setProperty ( 'padding-bottom' , `${ footerHeight } px` ) ;
146155
147156 // Apply positioning styles to keep footer at bottom
148- originalFooter . style . setProperty ( 'position' , 'absolute' ) ;
149- originalFooter . style . setProperty ( 'bottom' , '0' ) ;
157+ cachedFooterEl . style . setProperty ( 'position' , 'absolute' ) ;
158+ cachedFooterEl . style . setProperty ( 'bottom' , '0' ) ;
150159
151160 // Also cache the footer Y position, which we use to determine if the
152161 // sheet has been moved below the footer. When that happens, we need to swap
153162 // the position back so it will collapse correctly.
154- cachedFooterYPosition = originalFooter . getBoundingClientRect ( ) . top + window . scrollY ;
163+ cachedFooterYPosition = cachedFooterEl . getBoundingClientRect ( ) . top + window . scrollY ;
164+
165+ console . log ( 'Moving footer to body' ) ;
166+ document . body . appendChild ( cachedFooterEl ) ;
155167 }
156168 } ;
157169
0 commit comments