Skip to content

Commit 4052a86

Browse files
committed
feat(modal): implement footer visibility swap for scrollAtEdge handling
1 parent 59dd5b0 commit 4052a86

File tree

1 file changed

+35
-14
lines changed
  • core/src/components/modal/gestures

1 file changed

+35
-14
lines changed

core/src/components/modal/gestures/sheet.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,33 @@ export const createSheetGesture = (
116116
baseEl.classList.add(FOCUS_TRAP_DISABLE_CLASS);
117117
};
118118

119+
120+
/**
121+
* Used when `scrollAtEdge` is disabled.
122+
* Changes the footer that is currently visible
123+
* @param footer - The footer to show
124+
*/
125+
const swapFooterVisibility = (footer: 'original' | 'cloned') => {
126+
const footerToHide = footer === 'original' ?
127+
wrapperEl.nextElementSibling as HTMLIonFooterElement :
128+
baseEl.querySelector('ion-footer') as HTMLIonFooterElement;
129+
const footerToShow = footer === 'original' ?
130+
baseEl.querySelector('ion-footer') as HTMLIonFooterElement :
131+
wrapperEl.nextElementSibling as HTMLIonFooterElement;
132+
133+
const pagePadding =
134+
footer === 'original' ? 0 : footerToShow.clientHeight;
135+
136+
footerToShow.style.removeProperty('display');
137+
footerToShow.removeAttribute('aria-hidden');
138+
139+
const page = baseEl.querySelector('.ion-page') as HTMLElement;
140+
page.style.setProperty('padding-bottom', `${pagePadding}px`);
141+
142+
footerToHide.style.setProperty('display', 'none');
143+
footerToHide.setAttribute('aria-hidden', 'true');
144+
}
145+
119146
/**
120147
* After the entering animation completes,
121148
* we need to set the animation to go from
@@ -202,6 +229,10 @@ export const createSheetGesture = (
202229
*/
203230
canDismissBlocksGesture = baseEl.canDismiss !== undefined && baseEl.canDismiss !== true && minBreakpoint === 0;
204231

232+
if (!scrollAtEdge) {
233+
swapFooterVisibility('original')
234+
}
235+
205236
/**
206237
* If we are pulling down, then it is possible we are pulling on the content.
207238
* We do not want scrolling to happen at the same time as the gesture.
@@ -361,23 +392,13 @@ export const createSheetGesture = (
361392
*/
362393
gesture.enable(false);
363394

395+
if (!scrollAtEdge && shouldRemainOpen) {
396+
swapFooterVisibility('cloned');
397+
}
398+
364399
if (shouldPreventDismiss) {
365400
handleCanDismiss(baseEl, animation);
366401
} else if (!shouldRemainOpen) {
367-
if (!scrollAtEdge) {
368-
const clonedFooter = wrapperEl.nextElementSibling as HTMLIonFooterElement;
369-
// get the original footer, which is a child of
370-
const originalFooter = baseEl.querySelector('ion-footer') as HTMLIonFooterElement;
371-
// hide the cloned footer
372-
clonedFooter.style.setProperty('display', 'none');
373-
// add the aria-hidden attribute to the cloned footer
374-
clonedFooter.setAttribute('aria-hidden', 'true');
375-
// display the original footer, remove the inline style display: none
376-
originalFooter.style.removeProperty('display');
377-
// remove the aria-hidden attribute
378-
originalFooter.removeAttribute('aria-hidden');
379-
}
380-
381402
onDismiss();
382403
}
383404

0 commit comments

Comments
 (0)