The react-select works incorrectly when I remove the react-modal component from DOM
After closing a modal I remove this one from the DOM, and after that I can't open a list by clicking to the input field. If I click to the arrow icon the list open correctly
- Click a mouse to the input field (not arrow icon)
- Choose item
- After opening the modal window click the close button
- After closing the modal window click to the input again.
Expected behaviour the list of items is appeared Actual behaviour the list of items is not appeared Live demo with steps to reproduce https://codesandbox.io/s/react-select-and-react-modal-and-deleting-modal-from-dom-pjfhp?file=/src/App.tsx Product version v3.1.0(react-selsct) v3.11.2(react-modal) Affected browser(s) Chrome 86.0.4240.111
Clicking on the drop-down icon or navigating with the keyboard after closing the modal works fine.
Clicking the component as is (not the icon) does nothing.
This is usually expected behavior if the <input> is already focused.
The problem is that the onFocus handler on the <input> itself is not being triggered by react-modal returning the focus (i.e. inputElement.focus()).
I remember that this was a React issue, but I can't remember where I saw it mentioned.
@fmva ,
Apparently the react-modal is returning focus back to the input just as @Rall3n indicated. To fix this issue, you can simply add the following prop and value to your modal: shouldReturnFocusAfterClose={false}
Here is a forked sandbox with this prop set to false and it appears to be behaving as expected.
Please let us know if you come across any discrepancies.
for some modal version, prop is returnFocusAfterClose
Thanks both @yanghoxom and @ebonow I almost lost my mind trying to figure out why the select was not opening after I closed the modal, plus I don't know why the select is marked as focused=false I guess its the input like you said and we are actually clicking on the input itself not the select. Thanks again!