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

The react-select works incorrectly when I remove the react-modal component from DOM

Open fmva opened this issue 6 years ago • 4 comments

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

  1. Click a mouse to the input field (not arrow icon)
  2. Choose item
  3. After opening the modal window click the close button
  4. 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

fmva avatar Oct 28 '20 04:10 fmva

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.

Rall3n avatar Oct 29 '20 07:10 Rall3n

@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.

ebonow avatar Dec 04 '20 04:12 ebonow

for some modal version, prop is returnFocusAfterClose

yanghoxom avatar May 25 '21 09:05 yanghoxom

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!

tomasamado97 avatar Oct 03 '24 17:10 tomasamado97