theKashey / react-focus-lock

It is a trap! A lock for a Focus. 🔓
MIT License
1.27k stars 67 forks source link

Method to not lock mouseEvent focusing #176

Closed tounsoo closed 2 years ago

tounsoo commented 2 years ago

We have a use case where we want to focusLock on tabs but not on mouse click.

Here is an example where we try to make that happen but the problem we are facing is that it will require 2 clicks to focus on the outside input. Any idea on how to make this happen without requiring 2 clicks?

https://codesandbox.io/s/hardcore-gagarin-mjh4v?file=/index.js

theKashey commented 2 years ago

Not something supported out of the box.

tounsoo commented 2 years ago

@theKashey Thank you! I used the second option and created onClickOutside useEffect to handle it :D

theKashey commented 2 years ago

🙄 Is it working for you? My advice was not supported by any real experiment.

tounsoo commented 2 years ago

You can checkout the codesandbox, I updated it and made it into a FC so I can reuse it

theKashey commented 2 years ago

Amazing! Thank you @alexreardon for running into this issue, and helping @tounsoo to resolve theirs.