From 0162a715ffd3afdeac535603eff5485f9c665431 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Mon, 5 May 2025 13:20:47 -0700 Subject: [PATCH] fix(modal): move footer instead of copy for sheet expandToScroll --- .../components/modal/animations/ios.enter.ts | 8 ++--- .../components/modal/animations/ios.leave.ts | 31 +++++++++++------ .../components/modal/animations/md.enter.ts | 9 +++-- .../components/modal/animations/md.leave.ts | 14 +++----- core/src/components/modal/gestures/sheet.ts | 33 +++++++++---------- .../components/modal/test/sheet/index.html | 12 +++++-- 6 files changed, 59 insertions(+), 48 deletions(-) diff --git a/core/src/components/modal/animations/ios.enter.ts b/core/src/components/modal/animations/ios.enter.ts index 3c8924f288..9b7ae00bfb 100644 --- a/core/src/components/modal/animations/ios.enter.ts +++ b/core/src/components/modal/animations/ios.enter.ts @@ -74,13 +74,11 @@ export const iosEnterAnimation = (baseEl: HTMLElement, opts: ModalAnimationOptio const ionFooterAlreadyAppended = baseEl.shadowRoot!.querySelector('ion-footer'); if (ionFooter && !ionFooterAlreadyAppended) { const footerHeight = ionFooter.clientHeight; - const clonedFooter = ionFooter.cloneNode(true) as HTMLIonFooterElement; - baseEl.shadowRoot!.appendChild(clonedFooter); - ionFooter.style.setProperty('display', 'none'); - ionFooter.setAttribute('aria-hidden', 'true'); + // Move the footer to be a direct child of the baseEl. + baseEl.shadowRoot!.appendChild(ionFooter); - // Padding is added to prevent some content from being hidden. + // Padding is added to prevent content from being hidden at the bottom. const page = baseEl.querySelector('.ion-page') as HTMLElement; page.style.setProperty('padding-bottom', `${footerHeight}px`); } diff --git a/core/src/components/modal/animations/ios.leave.ts b/core/src/components/modal/animations/ios.leave.ts index 89ba3ce842..bfd280f594 100644 --- a/core/src/components/modal/animations/ios.leave.ts +++ b/core/src/components/modal/animations/ios.leave.ts @@ -39,25 +39,36 @@ export const iosLeaveAnimation = (baseEl: HTMLElement, opts: ModalAnimationOptio return; } + const children = Array.from(baseEl.children); + children.forEach((child) => { + console.log('child', child); + if (child.hasAttribute('slot')) { + console.log('child slot', child); + // get ionPage from the baseEl.children based on `.ion-page` + const ionPage = baseEl.querySelector('.ion-page') as HTMLElement; + ionPage.appendChild(child); + } + }); + /** * If expandToScroll is disabled, we need to swap * the visibility to the original, so the footer * dismisses with the modal and doesn't stay * until the modal is removed from the DOM. */ - const ionFooter = baseEl.querySelector('ion-footer'); - if (ionFooter) { - const clonedFooter = baseEl.shadowRoot!.querySelector('ion-footer')!; + // const ionFooter = baseEl.querySelector('ion-footer'); + // if (ionFooter) { + // const clonedFooter = baseEl.shadowRoot!.querySelector('ion-footer')!; - ionFooter.style.removeProperty('display'); - ionFooter.removeAttribute('aria-hidden'); + // ionFooter.style.removeProperty('display'); + // ionFooter.removeAttribute('aria-hidden'); - clonedFooter.style.setProperty('display', 'none'); - clonedFooter.setAttribute('aria-hidden', 'true'); + // clonedFooter.style.setProperty('display', 'none'); + // clonedFooter.setAttribute('aria-hidden', 'true'); - const page = baseEl.querySelector('.ion-page') as HTMLElement; - page.style.removeProperty('padding-bottom'); - } + // const page = baseEl.querySelector('.ion-page') as HTMLElement; + // page.style.removeProperty('padding-bottom'); + // } }); if (presentingEl) { diff --git a/core/src/components/modal/animations/md.enter.ts b/core/src/components/modal/animations/md.enter.ts index fee0efc4f6..0e79a679e9 100644 --- a/core/src/components/modal/animations/md.enter.ts +++ b/core/src/components/modal/animations/md.enter.ts @@ -74,15 +74,14 @@ export const mdEnterAnimation = (baseEl: HTMLElement, opts: ModalAnimationOption * the footer twice. */ const ionFooterAlreadyAppended = baseEl.shadowRoot!.querySelector('ion-footer'); + if (ionFooter && !ionFooterAlreadyAppended) { const footerHeight = ionFooter.clientHeight; - const clonedFooter = ionFooter.cloneNode(true) as HTMLIonFooterElement; - baseEl.shadowRoot!.appendChild(clonedFooter); - ionFooter.style.setProperty('display', 'none'); - ionFooter.setAttribute('aria-hidden', 'true'); + // Move the footer to be a direct child of the baseEl. + baseEl.shadowRoot!.appendChild(ionFooter); - // Padding is added to prevent some content from being hidden. + // Padding is added to prevent content from being hidden at the bottom. const page = baseEl.querySelector('.ion-page') as HTMLElement; page.style.setProperty('padding-bottom', `${footerHeight}px`); } diff --git a/core/src/components/modal/animations/md.leave.ts b/core/src/components/modal/animations/md.leave.ts index e453e9339c..b606b891b2 100644 --- a/core/src/components/modal/animations/md.leave.ts +++ b/core/src/components/modal/animations/md.leave.ts @@ -47,16 +47,12 @@ export const mdLeaveAnimation = (baseEl: HTMLElement, opts: ModalAnimationOption */ const ionFooter = baseEl.querySelector('ion-footer'); if (ionFooter) { - const clonedFooter = baseEl.shadowRoot!.querySelector('ion-footer')!; + // Move the footer back to `.ion-page` so it can be dismissed + // with the modal. + const ionPage = baseEl.querySelector('.ion-page') as HTMLElement; + ionPage.appendChild(ionFooter); - ionFooter.style.removeProperty('display'); - ionFooter.removeAttribute('aria-hidden'); - - clonedFooter.style.setProperty('display', 'none'); - clonedFooter.setAttribute('aria-hidden', 'true'); - - const page = baseEl.querySelector('.ion-page') as HTMLElement; - page.style.removeProperty('padding-bottom'); + ionPage.style.removeProperty('padding-bottom'); } }); diff --git a/core/src/components/modal/gestures/sheet.ts b/core/src/components/modal/gestures/sheet.ts index 68df1a2eca..ab320f10b9 100644 --- a/core/src/components/modal/gestures/sheet.ts +++ b/core/src/components/modal/gestures/sheet.ts @@ -119,32 +119,31 @@ export const createSheetGesture = ( /** * Toggles the visible modal footer when `expandToScroll` is disabled. - * @param footer The footer to show. + * @param footer The footer to show. TODO: update the values to represent the latest changes. */ const swapFooterVisibility = (footer: 'original' | 'cloned') => { - const originalFooter = baseEl.querySelector('ion-footer') as HTMLIonFooterElement | null; + const baseElFooter = baseEl.shadowRoot?.querySelector('ion-footer') as HTMLIonFooterElement | null; + const ionPage = baseEl.querySelector('.ion-page') as HTMLElement; + const ionPageFooter = ionPage.querySelector('ion-footer') as HTMLIonFooterElement | null; - if (!originalFooter) { + // if original was chosen then the footer needs to be moved from + // the baseEl to the ionPage + // else the footer needs to be moved from the ionPage to the baseEl + const footerToMove = footer === 'original' ? baseElFooter : ionPageFooter; + + if (!footerToMove) { return; } - const clonedFooter = wrapperEl.nextElementSibling as HTMLIonFooterElement; - const footerToHide = footer === 'original' ? clonedFooter : originalFooter; - const footerToShow = footer === 'original' ? originalFooter : clonedFooter; - - footerToShow.style.removeProperty('display'); - footerToShow.removeAttribute('aria-hidden'); - - const page = baseEl.querySelector('.ion-page') as HTMLElement; + // Move the footer to the wrapperEl if (footer === 'original') { - page.style.removeProperty('padding-bottom'); + ionPage.style.removeProperty('padding-bottom'); + ionPage.appendChild(footerToMove); } else { - const pagePadding = footerToShow.clientHeight; - page.style.setProperty('padding-bottom', `${pagePadding}px`); + const pagePadding = footerToMove.clientHeight; + ionPage.style.setProperty('padding-bottom', `${pagePadding}px`); + baseEl.shadowRoot?.appendChild(footerToMove); } - - footerToHide.style.setProperty('display', 'none'); - footerToHide.setAttribute('aria-hidden', 'true'); }; /** diff --git a/core/src/components/modal/test/sheet/index.html b/core/src/components/modal/test/sheet/index.html index 8dacb81ffc..4f816ab2ec 100644 --- a/core/src/components/modal/test/sheet/index.html +++ b/core/src/components/modal/test/sheet/index.html @@ -190,9 +190,11 @@ ${items} - - + + Footer +

test

+ test
`; @@ -221,6 +223,12 @@ modalElement.dismiss(); }); + const footerButton = element.querySelector('ion-footer ion-button'); + footerButton.addEventListener('click', () => { + console.log('Footer button clicked'); + modalElement.dismiss(); + }); + document.body.appendChild(modalElement); return modalElement; }