-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix: add predicate function to configurable focus trap and allow focus to escape sidenav #21962
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I like this approach
defer?: boolean = false; | ||
|
||
/** Predicate function that determines whether the focus trap will allow focus to escape. */ | ||
focusEscapePredicate?: (target: HTMLElement) => boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name bikesheding: WDYT about allowFocusEscape
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too attached to the name, but I wanted to have "predicate" in there since we do the same in a few other places. To me, allowFocusEscape
sounds like something you'd call on the focus trap to allow focus to escape, e.g. focusTrap.allowFocusEscape()
.
Looking at @mmalerba's issue report #21955, I'm not 100% sure that we don't want that behavior. For a sidenav with cc @stevenyxu for thoughts |
@jelbourn The weird thing is we have an API to disable the backdrop, so with that disabled it doesn't close and just feels broken |
@mmalerba what if we changed the sidenav to close on outside click instead of backdrop click? I think we do that with dialog now, right? |
I suspect there's a good number of folks disabling the backdrop so they can use it in over mode as a persistent sidenav (that's exactly what the team that brought this to my attention was doing). Making the change you suggest would break their use case. We could try to make that change, I just don't have high hopes for it being something we could easily get in. |
I'm not 100% full on all the context here, but in general you just need to either be modal and trap focus or not. |
I'd agree that if they're using it as a persistent sidenav (non-modal) then there should be no focus-trapping whatsoever. I suspect we could do a better job documenting this. |
Does it make sense to have focus trapping enabled when |
I can't speak directly to the sidenav case because I don't have experience with that widget, but in the dialog case, I would prefer not to bind focus trapping with requiring In the common case where user-provided
This can skip over critical content that sits before it. A better default to avoid skipping over content is to focus on the whole container, the standard behavior when Back closer to the problem at hand, there are four-ish cases:
|
The Here's what I propose:
|
537d65f
to
9572e3b
Compare
Adds the ability to pass in a predicate function to the `ConfigurableFocusTrap` which will determine whether focus is allowed to escape. Relates to angular#21955.
When the new `ConfigurableFocusTrap` is passed to a sidenav, it prevents focus from moving from the sidenav to the container. These changes pass in a predicate that allows for focus to escape. Fixes angular#21955.
9572e3b
to
1cc3cae
Compare
it sounds like we probably just want to close this one? |
I would be inclined to close this and take a different approach. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Split up into the following commits:
ConfigurableFocusTrap
which can be used to pass in a predicate function that will determine whether focus is allowed to escape.