Skip to content

fix(overlays): keep focus inside modal and popover when tabbing in Chrome 157+ - #31755

Merged
thetaPC merged 2 commits into
mainfrom
FW-7959
Nov 16, 2026
Merged

thetaPC merged 2 commits into
mainfrom
FW-7959

Conversation

@thetaPC

@thetaPC thetaPC commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Issue number: internal

What is the current behavior?

In Chrome 157 and later, pressing Tab on the last focusable element of a presented ion-modal or ion-popover moves focus out of the overlay. Chrome now lets Tab move focus off the end of the page without firing a focus event, so the document focus listener that traps focus never runs. Alert, action sheet and loading are not affected because they already render focusable sentinels around their content.

What is the new behavior?

  • Modal and popover render a focusable boundary before and after their content. A boundary moves focus to the first or last focusable element, so Tab wraps without focus leaving the page.
  • Alert, action sheet and loading use the same shared boundary in place of their own sentinels, and the scoped focus trap in overlays.ts no longer wraps focus itself.
  • Boundaries are hidden while the focus trap is off (focusTrap="false", or a sheet modal below its backdropBreakpoint), so focus can still leave the overlay.
  • Shift+Tab from the alert wrapper now wraps to the last button. Previously it moved to the first button.

Does this introduce a breaking change?

  • Yes
  • No

Other information

  • Test on localhost, not the Vercel preview. The Vercel toolbar's floating button sits after the overlay and catches the Tab, which hides the bug on main.
  • Unblocks the Playwright 1.65 update in chore(deps): update playwright to v1.65.1 #31714, where the Mobile Chrome focus trap tests fail on this Chrome change.
  • In Firefox, the first Tab into a popover now lands on the native textarea inside ion-textarea instead of the ion-textarea host, which matches Chrome and Safari. The extra Firefox-only Tab in the popover textarea test was removed.
  • Checked with VoiceOver in Safari and Chrome: Tab wraps announce only the newly focused element, and the VoiceOver cursor never stops on a boundary, the same as on main.

@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ionic-framework Ready Ready Preview Nov 16, 2026 11:02pm UTC

Request Review

@github-actions github-actions Bot added the package: core @ionic/core package label Nov 14, 2026
@thetaPC
thetaPC marked this pull request as ready for review November 16, 2026 18:18
@thetaPC
thetaPC requested a review from a team as a code owner November 16, 2026 18:18
@thetaPC
thetaPC requested a review from ShaneK November 16, 2026 18:18

@ShaneK ShaneK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested and reviewed this and it looks great! 🚀

await expect(page.locator('#before')).toBeFocused();
});
});
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
});
});
test('should let focus leave a sheet modal below its backdropBreakpoint', async ({ page, pageUtils }) => {
await page.setContent(
`
<button id="before">Before</button>
<ion-modal handle="false" initial-breakpoint="0.3" backdrop-breakpoint="0.5">
<button id="first">First</button><button id="last">Last</button>
</ion-modal>
<script>
document.querySelector('ion-modal').breakpoints = [0.3, 0.5, 1];
</script>
`,
config
);
const modal = page.locator('ion-modal');
const firstButton = page.locator('#first');
await modal.evaluate((el: HTMLIonModalElement) => el.present());
// present() moves focus into the overlay a frame after it resolves
await page.waitForFunction(() => document.querySelector('ion-modal')!.contains(document.activeElement));
await firstButton.focus();
await pageUtils.pressKeys('Shift+Tab');
await expect(page.locator('#before')).toBeFocused();
// The focus trap turns back on above the backdropBreakpoint
await modal.evaluate((el: HTMLIonModalElement) => el.setCurrentBreakpoint(1));
await firstButton.focus();
await pageUtils.pressKeys('Shift+Tab');
await expect(page.locator('#last')).toBeFocused();
});

Nit: I think a test for the sheet path would be nice to have too. Below the backdropBreakpoint, the class gets toggled with classList in sheet.ts rather than through the host, and both of the existing sheet focus tests still pass with the boundaries forced visible. This one fails in all 3 browsers when the hide rule breaks, and it also checks that the trap comes back above the breakpoint. It sets handle="false" since the handle is tabbable and would grab the first Shift+Tab. Up to you though, no action required!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, added in cfb2287. I also confirmed it fails in all 3 browsers when the hide rule in modal.scss is broken. Thanks!

…point

Co-authored-by: ShaneK <561207+ShaneK@users.noreply.github.com>
@thetaPC
thetaPC added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit c0eb79e Nov 16, 2026
56 checks passed
@thetaPC
thetaPC deleted the FW-7959 branch November 16, 2026 23:34

This branch was successfully deployed

1 active deployment
Preview — cfb22872 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants