From c05932c261097734c6b62d698eca6781c2f33229 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 15 Sep 2023 17:42:09 -0400 Subject: [PATCH] fix(striker-ui): prioritize parent open state in Dialog --- striker-ui/components/Dialog/Dialog.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/striker-ui/components/Dialog/Dialog.tsx b/striker-ui/components/Dialog/Dialog.tsx index 285a7d90..b080dea9 100644 --- a/striker-ui/components/Dialog/Dialog.tsx +++ b/striker-ui/components/Dialog/Dialog.tsx @@ -29,7 +29,9 @@ const Dialog: ForwardRefExoticComponent< } = props; const { - open: externalOpen = false, + // Do not initialize the external open state because we need it to + // determine whether the dialog is controlled or uncontrolled. + open: externalOpen, PaperProps: paperProps = {}, ...restDialogProps } = dialogProps; @@ -39,8 +41,8 @@ const Dialog: ForwardRefExoticComponent< const [controlOpen, setControlOpen] = useState(openInitially); const open = useMemo( - () => (ref ? controlOpen : externalOpen), - [controlOpen, externalOpen, ref], + () => externalOpen ?? controlOpen, + [controlOpen, externalOpen], ); const children = useMemo(