react-focus-lock
react-focus-lock copied to clipboard
returnFocus only works in some versions when using autoFocus to set initial focus
When using autoFocus to focus an element within a <FocusLock returnFocus>...</FocusLock> focus is only returned using certain versions of react-focus-lock. Examples:
- 2.5.2 - This is the latest version that will return focus when using
autoFocus - 2.7.1 - Focus is not returned in this version when using
autoFocus - 2.7.1 - Without
autoFocusfocus is returned in this version
Steps to reproduce with first 2.7.1 example above:
- Click "show modal"
- Click "close modal 1"
- Focus should have been returned to the "show modal" button. The button will be red if it has focus.
A second test with 2 modals:
- Click "show modal"
- Click "show modal 2"
- Click "close modal 2"
- Focus should have been returned to the "show modal 2" button. The button will be red if it has focus.
A third test with 2 modals:
- Click "show modal"
- Click "show modal 2"
- Click "close all modals"
- Focus should have been returned to the "show modal" button. The button will be red if it has focus.
This may be related to these issues:
Just to confirm - this logic became a little complicated. One of the reasons why returnFocus also accepts a function - to handle focus/return/autofocus race conditions.
Probably it's time to really review how this moment works.
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.