mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-26 09:33:49 +01:00
UI: Modals no longer update content and become inert while closing (#817)
This commit is contained in:
parent
3ae3f947ac
commit
648c180952
@ -1,4 +1,4 @@
|
|||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Theme } from "@mui/material";
|
import { Theme } from "@mui/material";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
@ -41,33 +41,43 @@ const useStyles = makeStyles((theme: Theme) =>
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
interface IProps {
|
interface ModalProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
sx?: SxProps<Theme>;
|
sx?: SxProps<Theme>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Modal = (props: IProps): React.ReactElement => {
|
export const Modal = ({ open, onClose, children, sx }: ModalProps): React.ReactElement => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
const [content, setContent] = useState(children);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
setContent(children);
|
||||||
|
}, [children, open]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<M
|
<M
|
||||||
disableRestoreFocus
|
disableRestoreFocus
|
||||||
disableScrollLock
|
disableScrollLock
|
||||||
disableEnforceFocus
|
disableEnforceFocus
|
||||||
disableAutoFocus
|
disableAutoFocus
|
||||||
open={props.open}
|
open={open}
|
||||||
onClose={props.onClose}
|
onClose={onClose}
|
||||||
closeAfterTransition
|
closeAfterTransition
|
||||||
className={classes.modal}
|
className={classes.modal}
|
||||||
sx={props.sx}
|
sx={sx}
|
||||||
>
|
>
|
||||||
<Fade in={props.open}>
|
<Fade in={open}>
|
||||||
<div className={classes.paper}>
|
<div
|
||||||
<IconButton className={classes.closeButton} onClick={props.onClose}>
|
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 />
|
<CloseIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Box sx={{ m: 2 }}>{props.children}</Box>
|
<Box sx={{ m: 2 }}>{content}</Box>
|
||||||
</div>
|
</div>
|
||||||
</Fade>
|
</Fade>
|
||||||
</M>
|
</M>
|
||||||
|
Loading…
Reference in New Issue
Block a user