Description
Summary:
When the modal is closed it focuses on the last focused input field/button. This is unexpected and not clearly documented. I had a button that was only visible when focusing on a particular element using a CSS transform. Focusing on the input field caused it's container to scroll to the button which caused the CSS transform to hide the button on focus.
Steps to reproduce:
- Code for react modal component is used by a stateful component that will open model.
- In same stateful component have another component that uses a CSS transition on hover to show a button to open the modal.
- On hover to view the button click on the button and the modal will open.
- Closing the modal will cause the hidden button to always be displayed.
- Hovering over the component will cause the button to be hidden.
With example
- Go to https://codesandbox.io/s/74x8ynqr6q
- Hover over the box with the red border
- Click on the button to open react modal
- Close the modal
Results: The CSS transformation is no longer in its original state. The focus is now placed on the button which caused the container to scroll to the button. Hovering over it hides the button and reveals whatever is below. In my case there was nothing below the buttons.
Expected behavior:
Modal will close without restoring focus on last focused input field / button.
Link to example of issue:
https://codesandbox.io/s/74x8ynqr6q
Additional notes:
When I hover over the menu the visible icon scrolls out of view and a button to open a modal scrolls into view. When clicking on the button it brings up the react-modal. When the react modal is closed the icon is no longer visible though the button to open the modal is visible. The CSS transformation now shows nothing when hovering over the menu.
ReactModal is placing focus on the hidden button causing the view of the menu to focus on the wrong thing in it's initial state.