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

Ability to disable the focus trap

Open chaddjohnson opened this issue 5 years ago • 11 comments

Summary:

It would be great if it was possible to disable the focus trap. This would be useful if ever needing to render the modal inline in a page.

I am building an app which lets one build a modal, and it would be useful to turn off the focus trap while in design mode.

To workaround this for now, I just layered a transparent div over the modal to make it non-interactive.

chaddjohnson avatar Feb 11 '20 21:02 chaddjohnson

@chaddjohnson I think setting shouldFocusAfterRender={false} will disable the focus trap. If you want it to still gain focus initially after opening, something like onAfterOpen={() => this.contentRef.focus()} might work.

jkillian avatar Feb 27 '20 19:02 jkillian

@JKillian Thank you. I wonder if there also is a way to disable the focus trap to enable interaction with the modal without trapping focus.

chaddjohnson avatar Feb 27 '20 19:02 chaddjohnson

@chaddjohnson I believe that shouldFocusAfterRender={false} does disable the focus trap. But not 100% sure, just what glancing at the code looked like to me!

jkillian avatar Feb 27 '20 20:02 jkillian

Having the same issue here! Would be really useful if we could! In order to make it flexible for other dialogs types!

I tried shouldFocusAfterRender={false} but doesn't stop the trapping to work. @JKillian

Vanals avatar Dec 03 '20 10:12 Vanals

Anyone? :D @chaddjohnson could you explain to me how you have overcome the obstacle? I can't see how having an overlay on top of the modal should stop the JS logic from trapping the user inside?

Thanks!

Vanals avatar Dec 14 '20 11:12 Vanals

An overlay on top prevents focus from ever entering the dialogue via click events. Keyboard tabbing into the modal may still cause focus to be trapped...I haven’t tested that.

chaddjohnson avatar Dec 14 '20 23:12 chaddjohnson

Unfortunately setting shouldFocusAfterRender={false} does not disable the focus trap.

bvellacott avatar May 21 '21 08:05 bvellacott

I've created a PR to address this issue: https://github.com/reactjs/react-modal/pull/876

bvellacott avatar May 21 '21 13:05 bvellacott

Sorry for not give attention to this issue...Can anyone explain why would be interest to let the focus scape the modal?

Once a modal is open, no other action can take place...

diasbruno avatar May 28 '21 12:05 diasbruno

@diasbruno We have a guide modal in our app. It can be viewed while using the app, but if it receives focus it needs to be closed before the user can transfer focus back to the rest of the app using the tab button. This is a major accessibility concern for us. All the other functionality of react-modal suits the use case very well.

bvellacott avatar May 31 '21 08:05 bvellacott

Please see discussion #881. It'd be nice to have some feedback on this.

diasbruno avatar Jun 02 '21 15:06 diasbruno