I usually wrap Reach's Dialog https://reach.tech/dialog so things like focus, esc, scroll, etc. are all handled out of the box. It's a controlled component that uses a div and Portal rather than a dialog
tag
this post was submitted on 11 Sep 2023
3 points (100.0% liked)
React
926 readers
1 users here now
A community for discussing anything related to the React UI framework and it's ecosystem.
Wormhole
Icon base by Skoll under CC BY 3.0 with modifications to add a gradient
founded 1 year ago
MODERATORS
Personally I use controlled, I typically create my own custom components that wrap a Dialog compoenent. These custom components will have props for thing such as the message to display, title, whether to show it or not, and an onClose callback. The onClose callback will be emitted from the custom component, which you can code to get called regardless of what method the user uses to close the dialog, then the parent component would simply toggle the boolean state of the custom dialog.