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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modal] Scroll changes when focus from browser URL bar #14895

Closed
2 tasks done
mctep opened this issue Mar 15, 2019 · 8 comments
Closed
2 tasks done

[Modal] Scroll changes when focus from browser URL bar #14895

mctep opened this issue Mar 15, 2019 · 8 comments
Labels
component: modal This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@mctep
Copy link
Contributor

mctep commented Mar 15, 2019

  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 馃

When any modal is open the window scroll position should not never change.

Current Behavior 馃槸

When any modal is open we could change scroll by focus through browser address bar.

Steps to Reproduce 馃暪

Link: https://jp6q69qqkv.codesandbox.io/

  1. Scroll to the bottom to hide the "Focusable Button"
  2. Open Dialog through the "Super Secret Button"
  3. Focus to the browser address bar
  4. Press Tab

Context 馃敠

When we focus to window (through Tab press in address bar) Chrome tries to find the first (or the last if we press Shift+Tab) focusable element on the page and focus it. If this element is not in viewport Chrome scrolls the page to this element.

Example source code: https://codesandbox.io/s/8n9wj3vo60

According to: #13702 (comment)

Your Environment 馃寧

Tech Version
Material-UI v4.0.0-alpha.8
React
Browser Chrome
TypeScript
etc.
@oliviertassinari oliviertassinari added accessibility a11y component: modal This is the name of the generic UI component, not the React module! labels Mar 16, 2019
@oliviertassinari
Copy link
Member

@mctep
Copy link
Contributor Author

mctep commented Mar 16, 2019

No. Looks like all projects are affected by the issue.
I have made this trick for my company UI library.

@mctep
Copy link
Contributor Author

mctep commented Mar 16, 2019

Hm... If just tabidex="0" is added to body element the issue is gone for w3.org sample and Material UI.
Focus event listener also could be added to body in TrapFocus I think.

@oliviertassinari
Copy link
Member

@theKashey has proposed a simple logic to change the behavior in #15450 (comment).
@mctep Do you have any resource on why it should behave this way?

@oliviertassinari oliviertassinari added new feature New feature or request and removed accessibility a11y labels Apr 24, 2019
@mctep
Copy link
Contributor Author

mctep commented Apr 24, 2019

@oliviertassinari Do you mean fixed hidden sentinels in the body? I have no resources (and have not found any), it is just an idea. @theKashey proposed the right thing. I think it is the simplest workaround to prevent page from scrolling. At least I do not see the easier solution.

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 24, 2019

I was wondering if the page scrolling to the top wasn't a good thing. It's what happens when no modal is open. But, once you close the Modal, the focus goes back to the previously activeElement, the page is gonna scroll a second time. I think that we should avoid it, changing the behavior is probably a good idea. You have suggested the usage of a tab index attribute on the body element. However, it will probably harm the Skip-nav link. I would rather avoid any global side effect like this.

@mctep
Copy link
Contributor Author

mctep commented Apr 24, 2019

I meant to add tabIndex to the body while any modal is open.
Looks like the skip nav link should not be accessible while any modal is open. So we should remove tabIndex from body on modal closing.

However it was a bad idea because by this way we could not detect focus direction. When we press Shift + Tab from the URL bar we should focus to the last element in the Modal. It is possible only when we have two sentinels in the body element as the first child and as the last child.

@mctep
Copy link
Contributor Author

mctep commented Apr 24, 2019

In the other hand detecting the last focusable element in the opened modal is non-trivial task. So case with Shift + Tab could be ignored. So I do not see big difference between body + tabindex and fixed hidden sentinel ways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: modal This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants