Skip to content

fix: stop the modal docs page from scrolling to the embedded example - #5837

Open
samuelmbabhazi wants to merge 1 commit into
canonical:mainfrom
samuelmbabhazi:fix/modal-docs-autoscroll
Open

fix: stop the modal docs page from scrolling to the embedded example#5837
samuelmbabhazi wants to merge 1 commit into
canonical:mainfrom
samuelmbabhazi:fix/modal-docs-autoscroll

Conversation

@samuelmbabhazi

Copy link
Copy Markdown

Done

  • Focus elements inside the modal example with preventScroll, so the documentation page no longer scrolls down to the "With footer" example on load. The standalone examples keep focusing the open modal on load, which is the accessibility behaviour that must stay (WCAG SC 2.4.3), and the focus trap and Escape handling are unchanged

Fixes #5119

QA

  • Open /docs/patterns/modal in Firefox: the page stays at the top instead of scrolling to the close button of the "With footer" example
  • Open /docs/examples/patterns/modal/footer/ directly: the close button of the open modal is focused on load, as before
  • Press Tab repeatedly inside that example: focus cycles between the three modal buttons and never leaves the modal; Escape closes it and returns focus to the "Show modal" button
  • Same checks in Chrome, where the scroll never happened, behave as before

Verified in headless Firefox 153 and Chromium 151 against a local build: before the change the documentation page loads scrolled 1166px down with the iframe's close button focused, after it the page loads at 0px with the same element focused inside the example.

preventScroll is ignored by browsers that predate it, which simply leaves them with today's behaviour.

Check if PR is ready for release

  • Bug 🐛 label (I cannot set labels on this repository)
  • No Vanilla SCSS or macro change, so no version bump and no releases.yml entry: this only touches the documentation example script

The modal example focuses its first control when it opens, and Firefox
scrolls the documentation page down to that element when the example is
embedded. Focusing with preventScroll keeps the accessibility behaviour
of the standalone examples while leaving the documentation page at the
top.
@webteam-app

Copy link
Copy Markdown

samuelmbabhazi is not a collaborator of the repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modal component documentation page: Unexpected autoscroll/focus

2 participants