react-focus-lock icon indicating copy to clipboard operation
react-focus-lock copied to clipboard

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

Open mikekiska opened this issue 3 years ago • 1 comments
trafficstars

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:

mikekiska avatar Jan 14 '22 20:01 mikekiska

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.

theKashey avatar Jan 16 '22 23:01 theKashey

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[bot] avatar Apr 30 '23 12:04 stale[bot]