-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[docs] Fix modal transition demos #36137
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,32 +7,42 @@ import Typography from '@mui/material/Typography'; | |
import { useSpring, animated } from '@react-spring/web'; | ||
|
||
interface FadeProps { | ||
children?: React.ReactElement; | ||
in: boolean; | ||
onEnter?: () => {}; | ||
onExited?: () => {}; | ||
children: React.ReactElement; | ||
in?: boolean; | ||
onClick?: any; | ||
onEnter?: (node: HTMLElement, isAppearing: boolean) => void; | ||
onExited?: (node: HTMLElement, isAppearing: boolean) => void; | ||
ownerState?: any; | ||
} | ||
|
||
const Fade = React.forwardRef<HTMLDivElement, FadeProps>(function Fade(props, ref) { | ||
const { in: open, children, onEnter, onExited, ...other } = props; | ||
const { | ||
children, | ||
in: open, | ||
onClick, | ||
onEnter, | ||
onExited, | ||
ownerState, | ||
...other | ||
} = props; | ||
const style = useSpring({ | ||
from: { opacity: 0 }, | ||
to: { opacity: open ? 1 : 0 }, | ||
onStart: () => { | ||
if (open && onEnter) { | ||
onEnter(); | ||
onEnter(null as any, true); | ||
} | ||
}, | ||
onRest: () => { | ||
if (!open && onExited) { | ||
onExited(); | ||
onExited(null as any, true); | ||
} | ||
}, | ||
}); | ||
|
||
return ( | ||
<animated.div ref={ref} style={style} {...other}> | ||
{children} | ||
{React.cloneElement(children, { onClick })} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the click needs to be registered on the element that is position fixed to work. |
||
</animated.div> | ||
); | ||
}); | ||
|
@@ -63,9 +73,11 @@ export default function SpringModal() { | |
open={open} | ||
onClose={handleClose} | ||
closeAfterTransition | ||
BackdropComponent={Backdrop} | ||
BackdropProps={{ | ||
timeout: 500, | ||
slots={{ backdrop: Backdrop }} | ||
slotProps={{ | ||
backdrop: { | ||
TransitionComponent: Fade, | ||
}, | ||
Comment on lines
+76
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a consistent animation, use the Fade component for both the modal body and modal backdrop. |
||
}} | ||
> | ||
<Fade in={open}> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UX is broken if we disable the backdrop.
I suspect this prop is here because we wanted to test that it was behaving correctly.