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

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

Open everdimension opened this issue 7 years ago • 7 comments

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

Something like a rootNode prop, maybe?

everdimension avatar Mar 28 '18 12:03 everdimension

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

davidtheclark avatar Mar 31 '18 17:03 davidtheclark

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.

everdimension avatar Apr 01 '18 09:04 everdimension

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.

davidtheclark avatar Apr 01 '18 14:04 davidtheclark

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.

everdimension avatar Apr 01 '18 18:04 everdimension

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?

davidtheclark avatar Apr 01 '18 19:04 davidtheclark

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

everdimension avatar Apr 02 '18 09:04 everdimension

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

davidtheclark avatar Apr 08 '18 00:04 davidtheclark