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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple modals and returnFocus #68

Closed
andraaspar opened this issue Jun 12, 2019 · 15 comments
Closed

Multiple modals and returnFocus #68

andraaspar opened this issue Jun 12, 2019 · 15 comments
Assignees

Comments

@andraaspar
Copy link

andraaspar commented Jun 12, 2019

Focus is not returned with multiple <FocusLock>s.

Sample CRA project: https://github.com/andraaspar/react-focus-lock-stack-missing

To reproduce:

  1. Click ‘Open modal 1’
  2. On the modal, click ‘Open modal 2’
  3. On the 2nd modal, click ‘X2’ → Focus is set to ‘Open modal 2’ instead of ‘X1’
  4. On the modal, click ‘X1’ → Focus is not returned to ‘Open modal 1’
@theKashey
Copy link
Owner

Just in time ;)

@andraaspar
Copy link
Author

I'm sorry? I'm not quite sure what you mean?

I tried to make it easy to reproduce. Did it make sense? Is it in scope for this library, or is it not?

@theKashey
Copy link
Owner

I mean that you created the issue just in time, when this package is under my attention.

@theKashey
Copy link
Owner

So - that's funny.

  • focus is returned when Lock is deactivated
  • when a new Lock is going active the old one ... got deactivated
  • it returns focus
  • and the new one read the "initial focus", not the one it was a moment ago...

@theKashey theKashey self-assigned this Jun 14, 2019
@theKashey theKashey added the bug label Jun 14, 2019
@andraaspar
Copy link
Author

@theKashey: Thank you for looking into it.

@theKashey
Copy link
Owner

Issue resolved in v2.0.0. No API changes, except raising minimal React version to 16.8.
I hope that's not a deal breaker for you.

@andraaspar
Copy link
Author

@theKashey: Thanks a lot for the quick fix! It works great!

@Haraldson
Copy link

Haraldson commented Mar 9, 2020

I’m experiencing this now, with 2.2.1. The ‘inner’ modal returns focus correctly to its trigger element in the ‘outer’ modal, but the ‘outer’ modal is unable to return focus to its trigger element on the page.

I also tried downgrading to 2.0.0 in case any regressions had been introduced since, unfortunately with no luck.

@theKashey
Copy link
Owner

Sounds like it's not working properly in deeply nested cases.

@theKashey theKashey reopened this Mar 9, 2020
@Haraldson
Copy link

To provide a bit more context to my use-case: My modals aren’t really structurally nested, they are both portaled to the same DOM element and become siblings, but virtually they are, indeed, nested.

@Haraldson
Copy link

Actually, you can probably just close this issue again. Perhaps there could be a hint about this behavior in dev environments, but basically what happened is that I disable my initial trigger when it’s clicked so that it appears a certain way through the overlay. When the modal closes the button gets enabled again, but a timing issue (Framer Motion’s <AnimatePresence>) prevents it from being ready in time to receive focus.

@theKashey
Copy link
Owner

But are you able to resolve the issue, or focus-lock should add some timeout support to the return focus logic?

@Haraldson
Copy link

It’s not super easy to solve it with the current tools provided with focus-lock, so maybe it would be a good idea to somehow have it trigger on an event, or after a timeout as you suggest.

@theKashey
Copy link
Owner

Sure. This might also resolve another issue with a too-fast move focus inside - theKashey/react-focus-on#36

@stale
Copy link

stale bot commented Apr 30, 2023

This issue has been marked as "stale" because there has been no activity for 2 months. If you have any new information or would like to continue the discussion, please feel free to do so. If this issue got buried among other tasks, maybe this message will reignite the conversation. Otherwise, this issue will be closed in 7 days. Thank you for your contributions so far.

@stale stale bot added the state label Apr 30, 2023
@stale stale bot closed this as completed May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants