Implementing a nested modal/drawer pattern #8500
Unanswered
neefrehman
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Sorry for the quick response, but had a thought.
I can see the argument for onOpenChange still being called though, maybe we could consider. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm currently working on implementing a nested drawer or modal pattern in our application, to allow for more incremental disclosures of information. Some examples of things close to what I'm trying to achieve are this shadcn-compatible nested dialog, or nested drawers in Vaul. It needs to support an arbitrary level of nested (though in reality it will mostly cap out at 3)
My current approach uses context that we can nest, and a minimal version of it can be seen here: https://codesandbox.io/p/devbox/strange-sunset-l37q3n
This works when triggering modal open and close events using
onOpenChange
, though I've highlighted a suboptimality relating to the fact thatModal
'sonOpenChange
may not work, forcing us to ensure that we also instrument events correctly onDialogTrigger
. Where this approach doesn't work, however, is where we want to set the initial open state ourselves. If we wanted to display a pre-opened pair of nested modals (for example, on page load and driven by URL search param state), thenonOpenChange
won't fire for the second modal since it's open state starts withtrue
. This breaks the interaction in quite an annoying way. I'm wondering if anyone has any tips to get around this, and build nested modal interactions that handle initial open state gracefully?Beta Was this translation helpful? Give feedback.
All reactions