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
[Modal] Better focus management #15450
Comments
|
There is still a problem with portaled content, which should be also wrapped with |
@theKashey Thanks for caring about the problem! I have benchmarked a lot of different UI libraries regarding focus handling. Very little are handling the focus correctly. I hope that #14545 solves it. I have also benchmarked a lot of correct implementations, a few of them are listed in #13702 (comment).
Thank you for the confirmation. I was planning on making TrapFocus public post v4, but I wanted to stress test the implementation first. Let's keep track of the bundle size: #15453.
I have implemented the logic with this constraint in mind. I trust these implementations for caring about the details, they don't allow it, I don't think that we should either:
Do you have an example? I have taken your codesandbox and updated it with v4.0.0-alpha.8. It's good: https://codesandbox.io/s/2zm2qzl6jp.
+4kb is a problem for us. Material-UI has these points of interests:
|
It's more about technical constraints - old behaviour is only possible if the modal is the last element on the page. That's usually just (was) not possible.
Let's imagine you will use something non-MUI based. Anyway - that's easy to fix - just add "react" To mitigate another problem with tabbing from address bar - #13702 (comment) - just add one more export const hiddenGuard = {
width: '1px',
height: '0px',
padding: 0,
overflow: 'hidden',
position: 'fixed', // <-- that's the trick
top: '1px',
left: '1px',
}; |
@theKashey The focus shouldn't move to the address bar. It goes against the accessibility guide: https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal. But it seems people disagree on this point: Accessible Modal Dialogs -- A11ycasts #19. It could be an opt-in prop.
Our modal has an intermediary step where the focus moves to the Modal container. It was a tradeoff to win 1kB gzipped. I would be happy to revisit it.
I'm sorry. Could you provide a more detailed issue reproduction? I don't understand the problem you are trying to solve. Let's go back to the codesandbox provided in
I have updated it to use v4.0.0-beta.8: https://codesandbox.io/s/w7wmvnlxp7. Do you see an issue?
|
As I mentioned in the Modal PR - just add one more sentinel with
Yeah, that's a tricky part. You might list all nodes between
The issue is possible only if you are using non-MUI components. I've added |
What happens with focus(in|out) listeners on those nodes? Or would a dispatch of a focus event imply that activeElement has changed i.e. it wouldn't fire to many focus events? |
No event would be dispatched if they are not focusable. |
I have lost the flow of this issue. Do we still have a specific problem so solve for this one? |
AFAIK - waiting for React Flare. |
Apologies for commenting on a dead thread, but this is the only place I've really found a reference to this issue. Is there going to be further discussion about the modal itself being focused when tabbing? I'm working on a site, and this issue was raised during 508 testing. If it's impossible to "skip" the modal itself when tabbing, is there some way to visually indicate that the modal itself is in focus? I've tried adding outlines to every generated class with no luck. Would you happen to have any recommendations for implementing the "tabbable" library? I'm implementing a Dialog component, and here's the element that's active when the modal is in focus. |
Current(master) focus-management is broken for shift+tab, while forward tapping is also working not as expected, as long as you may leave a modal, and got into browser address line, which is good, but should be impossible.
A new
TrapFocus
implementation also does not seems to be correct, especially due to the absence ofRootRef
, used to discover nested portals (like here - https://nk7zmp3900.codesandbox.io/)Expected Behavior 🤔
Current Behavior 😯
TrapFocus
would probably fix it, but might introduce other issues.Steps to Reproduce 🕹
See an example with 3 buttons inside a modal - https://codesandbox.io/s/j1ll74o3v9
Context 🔦
Sorry, I have a professional deformation :) I've invested too much time in focus management, and all focus-related problems are visible to me.
Proposed solution
Replace
TrapFocus
by react-focus-lock, which would handle all edge cases including Portals. There is only one downside of it - +4kb.The text was updated successfully, but these errors were encountered: