davidtheclark / react-aria-modal

A fully accessible React modal built according WAI-ARIA Authoring Practices
http://davidtheclark.github.io/react-aria-modal/demo/
MIT License
1.03k stars 96 forks source link

[feature] When modal is rendered into a certain node, `esc` should close the modal when it's pressed within that node #62

Open everdimension opened 6 years ago

everdimension commented 6 years ago

This might be optional behavior. Perhaps even a separate option altogether.

Something like a rootNode prop, maybe?

davidtheclark commented 6 years ago

@everdimension: Can you please give a more concrete example of this use case?

everdimension commented 6 years ago

What do you mean?

I just wish to optionally make it so that the esc press which originated outside the modal container wouldn't close the modal.

davidtheclark commented 6 years ago

What do you mean?

I'm just trying to understand the use case here because it's not obvious to me.

How do you hit escape outside the modal — did you turn off the focus trap? If so, and it doesn't appear like a modal on top of everything, I'm wondering what the modal provides for you.

everdimension commented 6 years ago

Use-case: application is integrated within another application, but not within an iframe.

In this case the modal will be on top of everything within the integrated app, but the surroundings might still be available and interactive. I didn't think about how focus trap would allow you to go outside, though. But maybe this should be allowed, too, if the user, say, clicks somewhere outside.

davidtheclark commented 6 years ago

Ah, weird. I think it might be perfectly fine to attach the escape listener to the underlay instead of the document. That should solve things for you, right?

everdimension commented 6 years ago

Yeah, or better yet, we might just check inside the checkDocumentKeyDown handler whether the target is a child of the underlay.

davidtheclark commented 6 years ago

Yep, @everdimension, that sounds like a good plan. PR welcome.