[Dialog] How to get the "open" state of an uncontrolled component? #1718
Unanswered
joonassandell
asked this question in
Help
Replies: 1 comment
-
Hey @joonassandell, There are many ways to achieve the same result. Whichever way you pass your props around is really up to you, I wouldn't say any of the solutions you proposed are workarounds. |
Beta Was this translation helpful? Give feedback.
0 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.
-
What is the recommended way/is there a way to get the "open" state of an uncontrolled Dialog?
I'm building a custom Dialog component and animating it with framer-motion. I've left out unnecessary parts of the code to simplify this discussion. I've extracted each part of the Dialog in our Design System library like so:
So, my question is that how can I get than
open
boolean value inDialogContent.tsx
? Is it possible to get the Dialog context somehow?If the answer is that I need to control the state (w/
const [open, setOpen] = useState(false);
applied to<DialogRoot open={open} onOpenChange={setOpen}>
), then how can I get that open prop inDialogContent.tsx
without having to apply theopen
prop to it as well? This question is more to how this component should be structured.Working solutions I've tried:
DialogRoot.tsx
andDialogContent.tsx
and apply prop for the trigger component to isolate it from the animated contents:DialogRoot.tsx
, filter children (React.children
) based on DisplayName etc. and clone (React.cloneElement
) the filtered child (<DialogContent>
) by passing the open property to it.But what I would really like to achieve is the structure like in
MyComponent.tsx
with or without controlling the open state and without applying additional props to any subcomponents. The above solutions feel like workarounds. I'm trying to keep things simple. :)Thank you, radix-ui is awesome!
Beta Was this translation helpful? Give feedback.
All reactions