@@ -10,23 +10,24 @@ const MDBCollapse: React.FC<CollapseProps> = ({
1010 id,
1111 navbar,
1212 tag : Tag ,
13+ collapseRef,
1314 style,
1415 ...props
1516} ) : JSX . Element => {
1617 const [ showCollapse , setShowCollapse ] = useState < boolean | undefined > ( false ) ;
1718 const [ showCollapseString , setShowCollapseString ] = useState < string | undefined > ( '' ) ;
1819 const [ statement , setStatement ] = useState ( false ) ;
1920 const [ collapseHeight , setCollapseHeight ] = useState < string | number | undefined > ( undefined ) ;
20- const [ transition , setTransition ] = useState ( false ) ;
21-
2221 const classes = clsx (
23- transition ? 'collapsing' : 'collapse' ,
24- ! transition && ( showCollapse || statement ) && 'show' ,
22+ 'collapsing' ,
23+ 'collapse' ,
24+ ( showCollapse || statement ) && 'show' ,
2525 navbar && 'navbar-collapse' ,
2626 center && 'justify-content-center' ,
2727 className
2828 ) ;
29- const refCollapse = useRef < HTMLElement > ( null ) ;
29+ const collapseEl = useRef < HTMLElement > ( null ) ;
30+ const refCollapse = collapseRef ? collapseRef : collapseEl ;
3031
3132 const handleResize = useCallback ( ( ) => {
3233 if ( showCollapse || statement ) {
@@ -38,7 +39,7 @@ const MDBCollapse: React.FC<CollapseProps> = ({
3839 if ( collapseHeight === undefined && ( showCollapse || statement ) ) {
3940 setCollapseHeight ( refCollapse ?. current ?. scrollHeight ) ;
4041 }
41- } , [ collapseHeight , showCollapse , statement ] ) ;
42+ } , [ collapseHeight , showCollapse , statement , refCollapse ] ) ;
4243
4344 useEffect ( ( ) => {
4445 if ( typeof show === 'string' ) {
@@ -48,17 +49,17 @@ const MDBCollapse: React.FC<CollapseProps> = ({
4849 setShowCollapse ( show ) ;
4950 }
5051
51- if ( statement || showCollapse ) {
52- setTransition ( true ) ;
53- }
52+ // if (statement || showCollapse) {
53+ // setTransition(true);
54+ // }
5455
55- const timer = setTimeout ( ( ) => {
56- setTransition ( false ) ;
57- } , 350 ) ;
56+ // const timer = setTimeout(() => {
57+ // setTransition(false);
58+ // }, 350);
5859
59- return ( ) => {
60- clearTimeout ( timer ) ;
61- } ;
60+ // return () => {
61+ // clearTimeout(timer);
62+ // };
6263 } , [ show , showCollapse , id , showCollapseString , statement ] ) ;
6364
6465 useEffect ( ( ) => {
@@ -67,7 +68,7 @@ const MDBCollapse: React.FC<CollapseProps> = ({
6768 } else {
6869 setCollapseHeight ( 0 ) ;
6970 }
70- } , [ showCollapse , statement ] ) ;
71+ } , [ showCollapse , statement , refCollapse ] ) ;
7172
7273 useEffect ( ( ) => {
7374 window . addEventListener ( 'resize' , handleResize ) ;
0 commit comments