Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(menu): preserve scroll position when focusing on open #25044

Merged
merged 14 commits into from
Apr 8, 2022
Merged

Conversation

averyjohnston
Copy link
Contributor

@averyjohnston averyjohnston commented Apr 1, 2022

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

When an ion-menu is opened, the first (focusable) element inside it is auto-focused for screen readers. This causes the menu's scroll position to jump to the focused element, and only once the opening animation has finished, leading to a jarring experience.

Issue URL: Resolves #24634

What is the new behavior?

When opening the menu, the host element is focused instead of the first element. This allows focus trapping without affecting the scroll position.

Does this introduce a breaking change?

  • Yes
  • No

Other information

An alternative would be to use the preventScroll option in focusFirstDescendant:

element.focus({ preventScroll: true });

However, this isn't currently supported in Safari: https://caniuse.com/mdn-api_htmlelement_focus_options_preventscroll_parameter

Side note: I elected to write the test in Puppeteer for the sake of time, rather than migrating to Playwright.

@averyjohnston averyjohnston requested a review from a team as a code owner April 1, 2022 16:04
@github-actions github-actions bot added the package: core @ionic/core package label Apr 1, 2022
Copy link
Contributor

@liamdebeasi liamdebeasi left a comment

Choose a reason for hiding this comment

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

Great job!

core/src/components/menu/menu.tsx Outdated Show resolved Hide resolved
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.

bug: ion-menu containing an ion-accordion scrolls up every time the menu opens
3 participants