theKashey / react-focus-on

🎯 Solution for WAI ARIA compatible modal dialogs or full-screen tasks, you were looking for
MIT License
333 stars 14 forks source link

How to preventDefault? #59

Closed TwisterMc closed 2 years ago

TwisterMc commented 2 years ago

I have FocusOn up and running. When I click outside of the focused area, it's running onClickOutside and also clicking on the item in the background. Typically I'd just add something like e.preventDefault(); but that's not working. How do I get it to close FocusOn, but not also click something in the background?

theKashey commented 2 years ago

There are two ways:

theKashey commented 2 years ago

The other possible way is to use some "shadow" element (it can be a pseudo element) 'consuming' clicks. So you will not be able to click on something you should not be able to click.

TwisterMc commented 2 years ago

I've tried the first option and it still clicks through. Wasn't sure if there was something special about this plugin or that I was missing something obvious. Guess I'll look into that shadow element.

TwisterMc commented 2 years ago

Well, I guess I was doing something stupid as it works now. Thanks!