@@ -4,7 +4,25 @@ import type { RippleProps } from './types';
44import  MDBBtn  from  '../../components/Button/Button' ; 
55import  MDBRippleWave  from  './RippleWave/RippleWave' ; 
66
7- const  MDBRipple : React . FC < RippleProps >  =  
7+ const  useCombinedRefs  =  ( ...refs : any )  =>  { 
8+   const  targetRef  =  React . useRef ( ) 
9+ 
10+   React . useEffect ( ( )  =>  { 
11+     refs . forEach ( ( ref : any )  =>  { 
12+       if  ( ! ref )  return 
13+ 
14+       if  ( typeof  ref  ===  'function' )  { 
15+         ref ( targetRef . current ) 
16+       }  else  { 
17+         ref . current  =  targetRef . current 
18+       } 
19+     } ) 
20+   } ,  [ refs ] ) 
21+ 
22+   return  targetRef 
23+ } 
24+ 
25+ const  MDBRipple : React . FC < RippleProps >  =  React . forwardRef < HTMLAllCollection ,  RippleProps > ( 
826  ( 
927    { 
1028      className, 
@@ -16,12 +34,13 @@ const MDBRipple: React.FC<RippleProps> =
1634      rippleColor, 
1735      children, 
1836      onClick, 
19-       rippleRef, 
2037      ...props 
21-     } 
38+     } , 
39+     ref 
2240  )  =>  { 
23-     const  rippleEl  =  useRef ( null ) ; 
24-     const  rippleReference  =  rippleRef  ? rippleRef  : rippleEl ; 
41+     const  rippleRef  =  useRef ( null ) ; 
42+     const  combinedRef  =  useCombinedRefs ( ref ,  rippleRef ) ; 
43+ 
2544    const  GRADIENT  = 
2645      'rgba({{color}}, 0.2) 0, rgba({{color}}, 0.3) 40%, rgba({{color}}, 0.4) 50%, rgba({{color}}, 0.5) 60%, rgba({{color}}, 0) 70%' ; 
2746
@@ -161,7 +180,9 @@ const MDBRipple: React.FC<RippleProps> =
161180    } ; 
162181
163182    const  getStyles  =  ( e : any )  =>  { 
164-       const  itemRect  =  rippleReference . current . getBoundingClientRect ( ) ; 
183+       // eslint-disable-next-line 
184+       // @ts -ignore 
185+       const  itemRect  =  combinedRef . current ?. getBoundingClientRect ( ) ; 
165186
166187      const  offsetX  =  e . clientX  -  itemRect . left ; 
167188      const  offsetY  =  e . clientY  -  itemRect . top ; 
@@ -221,14 +242,15 @@ const MDBRipple: React.FC<RippleProps> =
221242    } ,  [ rippleDuration ,  rippleStyles ] ) ; 
222243
223244    return  ( 
224-       < Tag  className = { classes }  onClick = { ( e : any )  =>  handleClick ( e ) }  ref = { rippleReference }  { ...props } > 
245+       < Tag  className = { classes }  onClick = { ( e : any )  =>  handleClick ( e ) }  ref = { combinedRef }  { ...props } > 
225246        { children } 
226247        { rippleStyles . map ( ( item ,  i )  =>  ( 
227248          < MDBRippleWave  key = { i }  style = { item } > </ MDBRippleWave > 
228249        ) ) } 
229250      </ Tag > 
230251    ) ; 
231-   } ; 
252+   } 
253+ ) ; 
232254
233255MDBRipple . defaultProps  =  {  rippleTag : 'div' ,  rippleDuration : 500 ,  rippleRadius : 0 ,  rippleColor : 'dark'  } ; 
234256
0 commit comments