fix(striker-ui): prioritize parent open state in Dialog

main
Tsu-ba-me 1 year ago
parent e8fe92321e
commit c05932c261
  1. 8
      striker-ui/components/Dialog/Dialog.tsx

@ -29,7 +29,9 @@ const Dialog: ForwardRefExoticComponent<
} = props; } = props;
const { 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 = {}, PaperProps: paperProps = {},
...restDialogProps ...restDialogProps
} = dialogProps; } = dialogProps;
@ -39,8 +41,8 @@ const Dialog: ForwardRefExoticComponent<
const [controlOpen, setControlOpen] = useState<boolean>(openInitially); const [controlOpen, setControlOpen] = useState<boolean>(openInitially);
const open = useMemo<boolean>( const open = useMemo<boolean>(
() => (ref ? controlOpen : externalOpen), () => externalOpen ?? controlOpen,
[controlOpen, externalOpen, ref], [controlOpen, externalOpen],
); );
const children = useMemo<ReactNode>( const children = useMemo<ReactNode>(

Loading…
Cancel
Save