Skip to content

Commit df96686

Browse files
committed
feat(modal): added footer visibility swap based on scrollAtEdge in leave animations.
1 parent f4cf4c1 commit df96686

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

core/src/components/modal/animations/ios.leave.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const createLeaveAnimation = () => {
1919
* iOS Modal Leave Animation
2020
*/
2121
export const iosLeaveAnimation = (baseEl: HTMLElement, opts: ModalAnimationOptions, duration = 500): Animation => {
22-
const { presentingEl, currentBreakpoint } = opts;
22+
const { presentingEl, currentBreakpoint, scrollAtEdge } = opts;
2323
const root = getElementRoot(baseEl);
2424
const { wrapperAnimation, backdropAnimation } =
2525
currentBreakpoint !== undefined ? createSheetLeaveAnimation(opts) : createLeaveAnimation();
@@ -32,7 +32,33 @@ export const iosLeaveAnimation = (baseEl: HTMLElement, opts: ModalAnimationOptio
3232
.addElement(baseEl)
3333
.easing('cubic-bezier(0.32,0.72,0,1)')
3434
.duration(duration)
35-
.addAnimation(wrapperAnimation);
35+
.addAnimation(wrapperAnimation)
36+
.beforeAddWrite(() => {
37+
if (scrollAtEdge) {
38+
// Scroll can only be done when the modal is fully expanded.
39+
return;
40+
}
41+
42+
/**
43+
* If scrollAtEdge is disabled, we need toß swap
44+
* the visibility to the original, so the footer
45+
* dismisses with the modal and doesn't stay
46+
* until the modal is removed from the DOM.
47+
*/
48+
const ionFooter = baseEl.querySelector('ion-footer');
49+
if (ionFooter) {
50+
const clonedFooter = baseEl.shadowRoot!.querySelector('ion-footer')!;
51+
52+
ionFooter.style.removeProperty('display');
53+
ionFooter.removeAttribute('aria-hidden');
54+
55+
clonedFooter.style.setProperty('display', 'none');
56+
clonedFooter.setAttribute('aria-hidden', 'true');
57+
58+
const page = baseEl.querySelector('.ion-page') as HTMLElement;
59+
page.style.setProperty('padding-bottom', `0`);
60+
}
61+
});
3662

3763
if (presentingEl) {
3864
const isMobile = window.innerWidth < 768;

core/src/components/modal/animations/md.leave.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const createLeaveAnimation = () => {
2121
* Md Modal Leave Animation
2222
*/
2323
export const mdLeaveAnimation = (baseEl: HTMLElement, opts: ModalAnimationOptions): Animation => {
24-
const { currentBreakpoint } = opts;
24+
const { currentBreakpoint, scrollAtEdge } = opts;
2525
const root = getElementRoot(baseEl);
2626
const { wrapperAnimation, backdropAnimation } =
2727
currentBreakpoint !== undefined ? createSheetLeaveAnimation(opts) : createLeaveAnimation();
@@ -32,7 +32,33 @@ export const mdLeaveAnimation = (baseEl: HTMLElement, opts: ModalAnimationOption
3232
const baseAnimation = createAnimation()
3333
.easing('cubic-bezier(0.47,0,0.745,0.715)')
3434
.duration(200)
35-
.addAnimation([backdropAnimation, wrapperAnimation]);
35+
.addAnimation([backdropAnimation, wrapperAnimation])
36+
.beforeAddWrite(() => {
37+
if (scrollAtEdge) {
38+
// Scroll can only be done when the modal is fully expanded.
39+
return;
40+
}
41+
42+
/**
43+
* If scrollAtEdge is disabled, we need to swap
44+
* the visibility to the original, so the footer
45+
* dismisses with the modal and doesn't stay
46+
* until the modal is removed from the DOM.
47+
*/
48+
const ionFooter = baseEl.querySelector('ion-footer');
49+
if (ionFooter) {
50+
const clonedFooter = baseEl.shadowRoot!.querySelector('ion-footer')!;
51+
52+
ionFooter.style.removeProperty('display');
53+
ionFooter.removeAttribute('aria-hidden');
54+
55+
clonedFooter.style.setProperty('display', 'none');
56+
clonedFooter.setAttribute('aria-hidden', 'true');
57+
58+
const page = baseEl.querySelector('.ion-page') as HTMLElement;
59+
page.style.setProperty('padding-bottom', `0`);
60+
}
61+
});
3662

3763
return baseAnimation;
3864
};

core/src/components/modal/modal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ export class Modal implements ComponentInterface, OverlayInterface {
792792
presentingEl: presentingElement,
793793
currentBreakpoint: this.currentBreakpoint ?? this.initialBreakpoint,
794794
backdropBreakpoint: this.backdropBreakpoint,
795+
scrollAtEdge: this.scrollAtEdge,
795796
}
796797
);
797798

0 commit comments

Comments
 (0)