@@ -6,32 +6,26 @@ import elementAcceptingRef from '@mui/utils/elementAcceptingRef';
66import getReactElementRef from '@mui/utils/getReactElementRef' ;
77import { Transition } from 'react-transition-group' ;
88import { useTheme } from '../zero-styled' ;
9- import { getTransitionProps , reflow } from '../transitions/utils' ;
9+ import {
10+ normalizedTransitionCallback ,
11+ getTransitionProps ,
12+ getTransitionChildStyle ,
13+ reflow ,
14+ } from '../transitions/utils' ;
1015import useForkRef from '../utils/useForkRef' ;
1116
1217function getScale ( value ) {
1318 return `scale(${ value } , ${ value ** 2 } )` ;
1419}
1520
1621const styles = {
17- entering : {
18- opacity : 1 ,
19- transform : getScale ( 1 ) ,
20- } ,
21- entered : {
22- opacity : 1 ,
23- transform : 'none' ,
24- } ,
22+ entering : { opacity : 1 , transform : getScale ( 1 ) } ,
23+ entered : { opacity : 1 , transform : 'none' } ,
24+ exiting : { opacity : 0 , transform : getScale ( 0.75 ) } ,
25+ exited : { opacity : 0 , transform : getScale ( 0.75 ) } ,
2526} ;
2627
27- /*
28- TODO v6: remove
29- Conditionally apply a workaround for the CSS transition bug in Safari 15.4 / WebKit browsers.
30- */
31- const isWebKit154 =
32- typeof navigator !== 'undefined' &&
33- / ^ ( (? ! c h r o m e | a n d r o i d ) .) * ( s a f a r i | m o b i l e ) / i. test ( navigator . userAgent ) &&
34- / ( o s | v e r s i o n \/ ) 1 5 ( .| _ ) 4 / i. test ( navigator . userAgent ) ;
28+ const hiddenStyles = { opacity : 0 , transform : getScale ( 0.75 ) , visibility : 'hidden' } ;
3529
3630/**
3731 * The Grow transition is used by the [Tooltip](/material-ui/react-tooltip/) and
@@ -53,8 +47,6 @@ const Grow = React.forwardRef(function Grow(props, ref) {
5347 onExiting,
5448 style,
5549 timeout = 'auto' ,
56- // eslint-disable-next-line react/prop-types
57- TransitionComponent = Transition ,
5850 ...other
5951 } = props ;
6052 const timer = useTimeout ( ) ;
@@ -64,22 +56,9 @@ const Grow = React.forwardRef(function Grow(props, ref) {
6456 const nodeRef = React . useRef ( null ) ;
6557 const handleRef = useForkRef ( nodeRef , getReactElementRef ( children ) , ref ) ;
6658
67- const normalizedTransitionCallback = ( callback ) => ( maybeIsAppearing ) => {
68- if ( callback ) {
69- const node = nodeRef . current ;
70-
71- // onEnterXxx and onExitXxx callbacks have a different arguments.length value.
72- if ( maybeIsAppearing === undefined ) {
73- callback ( node ) ;
74- } else {
75- callback ( node , maybeIsAppearing ) ;
76- }
77- }
78- } ;
79-
80- const handleEntering = normalizedTransitionCallback ( onEntering ) ;
59+ const handleEntering = normalizedTransitionCallback ( nodeRef , onEntering ) ;
8160
82- const handleEnter = normalizedTransitionCallback ( ( node , isAppearing ) => {
61+ const handleEnter = normalizedTransitionCallback ( nodeRef , ( node , isAppearing ) => {
8362 reflow ( node ) ; // So the animation always start from the start.
8463
8564 const {
@@ -107,7 +86,7 @@ const Grow = React.forwardRef(function Grow(props, ref) {
10786 delay,
10887 } ) ,
10988 theme . transitions . create ( 'transform' , {
110- duration : isWebKit154 ? duration : duration * 0.666 ,
89+ duration : duration * 0.666 ,
11190 delay,
11291 easing : transitionTimingFunction ,
11392 } ) ,
@@ -118,11 +97,11 @@ const Grow = React.forwardRef(function Grow(props, ref) {
11897 }
11998 } ) ;
12099
121- const handleEntered = normalizedTransitionCallback ( onEntered ) ;
100+ const handleEntered = normalizedTransitionCallback ( nodeRef , onEntered ) ;
122101
123- const handleExiting = normalizedTransitionCallback ( onExiting ) ;
102+ const handleExiting = normalizedTransitionCallback ( nodeRef , onExiting ) ;
124103
125- const handleExit = normalizedTransitionCallback ( ( node ) => {
104+ const handleExit = normalizedTransitionCallback ( nodeRef , ( node ) => {
126105 const {
127106 duration : transitionDuration ,
128107 delay,
@@ -148,8 +127,8 @@ const Grow = React.forwardRef(function Grow(props, ref) {
148127 delay,
149128 } ) ,
150129 theme . transitions . create ( 'transform' , {
151- duration : isWebKit154 ? duration : duration * 0.666 ,
152- delay : isWebKit154 ? delay : delay || duration * 0.333 ,
130+ duration : duration * 0.666 ,
131+ delay : delay || duration * 0.333 ,
153132 easing : transitionTimingFunction ,
154133 } ) ,
155134 ] . join ( ',' ) ;
@@ -162,7 +141,13 @@ const Grow = React.forwardRef(function Grow(props, ref) {
162141 }
163142 } ) ;
164143
165- const handleExited = normalizedTransitionCallback ( onExited ) ;
144+ const handleExited = normalizedTransitionCallback ( nodeRef , ( node ) => {
145+ node . style . transition = '' ;
146+
147+ if ( onExited ) {
148+ onExited ( node ) ;
149+ }
150+ } ) ;
166151
167152 const handleAddEndListener = ( next ) => {
168153 if ( timeout === 'auto' ) {
@@ -175,7 +160,7 @@ const Grow = React.forwardRef(function Grow(props, ref) {
175160 } ;
176161
177162 return (
178- < TransitionComponent
163+ < Transition
179164 appear = { appear }
180165 in = { inProp }
181166 nodeRef = { nodeRef }
@@ -191,20 +176,22 @@ const Grow = React.forwardRef(function Grow(props, ref) {
191176 >
192177 { /* Ensure "ownerState" is not forwarded to the child DOM element when a direct HTML element is used. This avoids unexpected behavior since "ownerState" is intended for internal styling, component props and not as a DOM attribute. */ }
193178 { ( state , { ownerState, ...restChildProps } ) => {
179+ const childStyle = getTransitionChildStyle (
180+ state ,
181+ inProp ,
182+ styles ,
183+ hiddenStyles ,
184+ style ,
185+ children . props . style ,
186+ ) ;
187+
194188 return React . cloneElement ( children , {
195- style : {
196- opacity : 0 ,
197- transform : getScale ( 0.75 ) ,
198- visibility : state === 'exited' && ! inProp ? 'hidden' : undefined ,
199- ...styles [ state ] ,
200- ...style ,
201- ...children . props . style ,
202- } ,
189+ style : childStyle ,
203190 ref : handleRef ,
204191 ...restChildProps ,
205192 } ) ;
206193 } }
207- </ TransitionComponent >
194+ </ Transition >
208195 ) ;
209196} ) ;
210197
0 commit comments