react-modal icon indicating copy to clipboard operation
react-modal copied to clipboard

returnFocus doesn't work in Safari and Firefox

Open alyrik opened this issue 8 years ago • 1 comments

Summary:

Focus returns as expected in Chrome. But it fails in Firefox and Safari.

Steps to reproduce:

  1. Click the button.
  2. Close modal.
  3. The button is not focused (its text should be red).

Expected behavior:

The button is focused (its text is red).

Link to example of issue:

https://codesandbox.io/s/mjy915nqp9

Additional notes:

As I see in returnFocus function, focusLaterElements array consists of <body> in Firefox and Safari instead of <button> (in Chrome).

alyrik avatar Nov 04 '18 21:11 alyrik

I want to note that this bug is not from react-modal but from safari and firefox.

It is an expected behavior from the browsers since both do not focus on button elements when you click on them using a mouse (link).

This but is not relevant if a user uses keyboard to navigate through the page. Since when tabbing the buttons are given the focus before you can press on them.

I believe there should be a fine workaround for the mouse users. However manually giving buttons focus for mouse users seems pretty hacky. I am wondering if there is a more elegant workaround.

antonk52 avatar Aug 09 '19 13:08 antonk52