Skip to content

Commit 20f5372

Browse files
committed
chore(modal): code clean up/clarification
1 parent 6780fad commit 20f5372

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

core/src/components/modal/modal.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,18 +784,19 @@ export class Modal implements ComponentInterface, OverlayInterface {
784784
this.cachedPageParent = this.getOriginalPageParent();
785785
const pageParent = this.cachedPageParent;
786786

787-
// Skip ion-app (controller modals) and pages with other content (inline modals)
787+
// Skip ion-app (controller modals) and pages with visible sibling content next to the modal
788788
if (!pageParent || pageParent.tagName === 'ION-APP') {
789789
return;
790790
}
791791

792-
const hasVisibleContent = Array.from(pageParent.children).some((child) => {
793-
if (child === this.el) return false;
794-
if (child instanceof HTMLElement && window.getComputedStyle(child).display === 'none') return false;
795-
if (child.tagName === 'TEMPLATE' || child.tagName === 'SLOT') return false;
796-
if (child.nodeType === Node.TEXT_NODE && !child.textContent?.trim()) return false;
797-
return true;
798-
});
792+
const hasVisibleContent = Array.from(pageParent.children).some(
793+
(child) =>
794+
child !== this.el &&
795+
!(child instanceof HTMLElement && window.getComputedStyle(child).display === 'none') &&
796+
child.tagName !== 'TEMPLATE' &&
797+
child.tagName !== 'SLOT' &&
798+
!(child.nodeType === Node.TEXT_NODE && !child.textContent?.trim())
799+
);
799800

800801
if (hasVisibleContent) {
801802
return;

core/src/utils/overlays.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ type OverlayWithFocusTrapProps = HTMLIonOverlayElement & {
4545
};
4646

4747
/**
48-
* Determines if the overlay's backdrop is always active (no background interaction).
48+
* Determines if the overlay's backdrop is always blocking (no background interaction).
4949
* Returns false if showBackdrop=false or backdropBreakpoint > 0.
5050
*/
51-
const isBackdropAlwaysActive = (el: OverlayWithFocusTrapProps): boolean => {
51+
const isBackdropAlwaysBlocking = (el: OverlayWithFocusTrapProps): boolean => {
5252
return el.showBackdrop !== false && !((el.backdropBreakpoint ?? 0) > 0);
5353
};
5454

@@ -555,7 +555,7 @@ export const present = async <OverlayPresentOptions>(
555555
*/
556556
const overlayEl = overlay.el as OverlayWithFocusTrapProps;
557557
const shouldTrapFocus = overlayEl.tagName !== 'ION-TOAST' && overlayEl.focusTrap !== false;
558-
const shouldLockRoot = shouldTrapFocus && isBackdropAlwaysActive(overlayEl);
558+
const shouldLockRoot = shouldTrapFocus && isBackdropAlwaysBlocking(overlayEl);
559559

560560
overlay.presented = true;
561561
overlay.willPresent.emit();
@@ -693,11 +693,11 @@ export const dismiss = async <OverlayDismissOptions>(
693693
*/
694694
const overlaysLockingRoot = presentedOverlays.filter((o) => {
695695
const el = o as OverlayWithFocusTrapProps;
696-
return el.tagName !== 'ION-TOAST' && el.focusTrap !== false && isBackdropAlwaysActive(el);
696+
return el.tagName !== 'ION-TOAST' && el.focusTrap !== false && isBackdropAlwaysBlocking(el);
697697
});
698698
const overlayEl = overlay.el as OverlayWithFocusTrapProps;
699699
const locksRoot =
700-
overlayEl.tagName !== 'ION-TOAST' && overlayEl.focusTrap !== false && isBackdropAlwaysActive(overlayEl);
700+
overlayEl.tagName !== 'ION-TOAST' && overlayEl.focusTrap !== false && isBackdropAlwaysBlocking(overlayEl);
701701

702702
/**
703703
* If this is the last visible overlay that is trapping focus

0 commit comments

Comments
 (0)