-
Notifications
You must be signed in to change notification settings - Fork 112
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
feat: if not active, don't try focusing #101
Conversation
Fixing issue where deactivation of focus trap could happen before attempting to focus something again on a delay.
@cgood92 Thanks for this PR. Sorry it's taken so (very) long to have someone look at it. The repo fell out of maintenance for the better part of the last 12 months, and I've just taken over a couple of months ago, and trying to catch-up. Thanks for the sandbox. I forked it at https://codesandbox.io/s/hopeful-field-2i9fr in order to update the As best I can tell, after staring at this for a long while, is that it's actually related to what focus-trap/focus-trap-react#54 is trying to fix, which is essentially a double-deactivation loop with the focus trap that happens when Unfortunately, the fix to |
@@ -301,6 +301,7 @@ function focusTrap(element, userOptions) { | |||
} | |||
|
|||
function tryFocus(node) { | |||
if (!state.active) return; |
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.
The fix you're proposing here seems right, but I don't like that we're checking for the activate state in tryFocus()
. I think the fix belongs more in the timeout related to the delayed focus on activation, at line 145, just before calling tryFocus()
.
tryFocus()
itself doesn't need to be concerned about state.
And with newer options in focus-trap
, I thought the new delayInitialFocus
option set to false
might help since your description makes it sound like that's basically the problem (because you say the trap is deactivated by the time the initial focus is set), but that didn't help either. Maybe I misinterpreted something there.
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.
@cgood92 Since you're around... any thoughts on this one?
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.
You know, there was a reason for this, but I honestly can't remember a thing about it. I'll close this PR, as it may be irrelevant.
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.
Cool, thanks!
Fixing issue where deactivation of focus trap could happen before attempting to focus something again on a delay.
This will fix a problem we are having. Here is a replication of that problem: https://codesandbox.io/s/upbeat-mendel-kbdzw .