aragon / ui

🦚 UI kit for decentralized apps
https://ui.aragon.org/
MIT License
343 stars 127 forks source link

Modal: Dropdown interactions trigger a close #813

Open andy-hook opened 3 years ago

andy-hook commented 3 years ago

ezgif-2-a912c64fce8f

https://codesandbox.io/s/modal-premature-close-9mhf7?file=/src/App.js

Highly likely to be escapeOutside triggering because the dropdown popover portal is outside the modal dom tree.

bpierre commented 3 years ago

I can’t find a discussion about it, but something we’ve been wanting to implement for a long time is a layering system. A component (or hook) would get used by every component needing one of the properties of a “layer”, which would be handling things related to the focus, the escape key, clicking outside, etc. This layer component would make sure that an escape event only gets propagated to the first one (in the React tree and not the DOM). It would also provide a way to trap the focus, which is missing at the moment.

Edit: probably related to https://github.com/aragon/ui/issues/343

andy-hook commented 3 years ago

I can’t find a discussion about it, but something we’ve been wanting to implement for a long time is a layering system. A component (or hook) would get used by every component needing one of the properties of a “layer”, which would be handling things related to the focus, the escape key, clicking outside, etc. This layer component would make sure that an escape event only gets propagated to the first one (in the React tree and not the DOM). It would also provide a way to trap the focus, which is missing at the moment.

Edit: probably related to #343

đź’Ż đź’Ż totally agree, leaning on Reacts internal handling of propagation within portals would solve a lot of issues too imo.

eliobricenov commented 3 years ago

hey @andy-hook @bpierre - any steps to reproduce this?

andy-hook commented 3 years ago

Hey @eliobricenov, any component using a popover element inside a modal will trigger this behaviour, here's a simplified repro:

https://codesandbox.io/s/modal-premature-close-9mhf7?file=/src/App.js