theKashey / react-focus-lock

It is a trap! A lock for a Focus. đŸ”“
MIT License
1.27k stars 67 forks source link

returnFocus only works in some versions when using autoFocus to set initial focus #193

Closed mikekiska closed 1 year ago

mikekiska commented 2 years ago

When using autoFocus to focus an element within a <FocusLock returnFocus>...</FocusLock> focus is only returned using certain versions of react-focus-lock. Examples:

Steps to reproduce with first 2.7.1 example above:

  1. Click "show modal"
  2. Click "close modal 1"
  3. 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:

  1. Click "show modal"
  2. Click "show modal 2"
  3. Click "close modal 2"
  4. 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:

  1. Click "show modal"
  2. Click "show modal 2"
  3. Click "close all modals"
  4. 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:

theKashey commented 2 years ago

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.

stale[bot] commented 1 year ago

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.