Prevent Scrolling back when focus on close #38079
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This Pull Request is a suggestion to prevent scrolling back to the trigger element on closing off-canvas, all while keeping the behavior of focusing the element unchanged for accessibility. This modification is simply done by adding the
preventScroll: true
object to thethis.focus()
method.Motivation & Context
This PR comes as a better solution for the issue: #38070 . Another PR #38076 is suggested but it solves the issue by completely disabling the focus of the trigger element when the user scrolls. Yet, it is important to focus the trigger element for accessibility.
Type of changes
Checklist
npm run lint
)Live previews
I created a codepen link to preview the changes:
https://codepen.io/ChellyAhmed/pen/VwGLdbR
Related issues
Closes #38070