Skip to content

UI: Modals no longer update while closing #817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/ui/React/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useEffect, useState } from "react";
import { Theme } from "@mui/material";
import Box from "@mui/material/Box";
import IconButton from "@mui/material/IconButton";
Expand Down Expand Up @@ -41,33 +41,43 @@ const useStyles = makeStyles((theme: Theme) =>
}),
);

interface IProps {
interface ModalProps {
open: boolean;
onClose: () => void;
children: React.ReactNode;
sx?: SxProps<Theme>;
}

export const Modal = (props: IProps): React.ReactElement => {
export const Modal = ({ open, onClose, children, sx }: ModalProps): React.ReactElement => {
const classes = useStyles();
const [content, setContent] = useState(children);
useEffect(() => {
if (!open) return;
setContent(children);
}, [children, open]);

return (
<M
disableRestoreFocus
disableScrollLock
disableEnforceFocus
disableAutoFocus
open={props.open}
onClose={props.onClose}
open={open}
onClose={onClose}
closeAfterTransition
className={classes.modal}
sx={props.sx}
sx={sx}
>
<Fade in={props.open}>
<div className={classes.paper}>
<IconButton className={classes.closeButton} onClick={props.onClose}>
<Fade in={open}>
<div
className={classes.paper}
//@ts-expect-error inert is not supported by react types yet, this is a workaround until then. https://github.com/facebook/react/pull/24730
inert={open ? null : ""}
>
<IconButton className={classes.closeButton} onClick={onClose}>
<CloseIcon />
</IconButton>
<Box sx={{ m: 2 }}>{props.children}</Box>
<Box sx={{ m: 2 }}>{content}</Box>
</div>
</Fade>
</M>
Expand Down