fix(overlays): correctly re-add root to accessibility tree (#28183)

Issue number: resolves #28180

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

When presenting an overlay, we remove the root (usually
`ion-router-outlet`) from the accessibility tree. This makes it so you
cannot accidentally focus elements behind the overlay. When dismissing
an overlay we re-add the root to the accessibility tree. However, we
fail to consider if there are multiple presented overlays. For example,
if you present a modal, then an alert, then dismiss the alert, then the
root is re-added to the accessibility tree even though the modal is
still presented.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- The root is now re-added to the accessibility tree only if it is the
last presented overlay.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: `7.4.1-dev.11694783260.13da477f`
This commit is contained in:
Liam DeBeasi
2023-09-19 10:46:14 -04:00
committed by GitHub
parent 4e0b522728
commit 81714d45bd
3 changed files with 92 additions and 11 deletions

View File

@ -6,7 +6,7 @@ import { GESTURE_CONTROLLER } from '@utils/gesture';
import type { Attributes } from '@utils/helpers';
import { inheritAriaAttributes, assert, clamp, isEndSide as isEnd } from '@utils/helpers';
import { menuController } from '@utils/menu-controller';
import { getOverlay } from '@utils/overlays';
import { getPresentedOverlay } from '@utils/overlays';
import { config } from '../../global/config';
import { getIonMode } from '../../global/ionic-global';
@ -59,7 +59,7 @@ export class Menu implements ComponentInterface, MenuI {
* open does not contain this ion-menu, then ion-menu's
* focus trapping should not run.
*/
const lastOverlay = getOverlay(document);
const lastOverlay = getPresentedOverlay(document);
if (lastOverlay && !lastOverlay.contains(this.el)) {
return;
}