1
- import React , { forwardRef , memo , useCallback , useContext , useEffect , useMemo , useRef , useState } from 'react' ;
1
+ import React , { forwardRef , memo , useCallback , useContext , useEffect , useMemo , useRef } from 'react' ;
2
2
import cls from 'classnames' ;
3
3
import { ChevronDownIcon , ChevronUpIcon } from 'tdesign-icons-react' ;
4
4
import type { StyledProps } from '../common' ;
@@ -42,27 +42,7 @@ const CollapsePanel = forwardRef<HTMLDivElement, CollapsePanelProps>((originProp
42
42
[ parent , value , disabled ] ,
43
43
) ;
44
44
45
- const bodyRef = useRef < HTMLDivElement > ( null ) ;
46
45
const headRef = useRef < HTMLDivElement > ( null ) ;
47
- const [ wrapperHeight , setWrapperHeight ] = useState ( '' ) ;
48
-
49
- useEffect ( ( ) => {
50
- const updatePanelState = ( ) => {
51
- if ( ! headRef . current || ! bodyRef . current ) {
52
- return ;
53
- }
54
- const headHeight = headRef . current . getBoundingClientRect ( ) . height ;
55
- if ( ! isActive ) {
56
- setWrapperHeight ( `${ headHeight } px` ) ;
57
- return ;
58
- }
59
- const bodyHeight = bodyRef . current . getBoundingClientRect ( ) . height ;
60
- const height = headHeight + bodyHeight ;
61
- setWrapperHeight ( `${ height } px` ) ;
62
- } ;
63
-
64
- updatePanelState ( ) ;
65
- } , [ isActive ] ) ;
66
46
67
47
useEffect ( ( ) => {
68
48
if ( parent ?. defaultExpandAll ) {
@@ -89,11 +69,7 @@ const CollapsePanel = forwardRef<HTMLDivElement, CollapsePanelProps>((originProp
89
69
// 当前面板处理折叠状态时,是否销毁面板内容
90
70
if ( props . destroyOnCollapse && ! isActive ) return null ;
91
71
92
- return (
93
- < div ref = { bodyRef } className = { `${ collapsePanelClass } __content` } >
94
- { panelContent }
95
- </ div >
96
- ) ;
72
+ return < div className = { `${ collapsePanelClass } __content` } > { panelContent } </ div > ;
97
73
} ;
98
74
99
75
return (
@@ -107,7 +83,6 @@ const CollapsePanel = forwardRef<HTMLDivElement, CollapsePanelProps>((originProp
107
83
[ className ] : className ,
108
84
} ) }
109
85
style = { {
110
- height : wrapperHeight ,
111
86
...style ,
112
87
} }
113
88
>
@@ -122,7 +97,9 @@ const CollapsePanel = forwardRef<HTMLDivElement, CollapsePanelProps>((originProp
122
97
rightIcon = { renderRightIcon ( ) }
123
98
/>
124
99
</ div >
125
- < PanelContent />
100
+ < div className = { `${ collapsePanelClass } __body` } style = { { gridTemplateRows : isActive ? '1fr' : '0fr' } } >
101
+ < div className = { `${ collapsePanelClass } __inner` } > { PanelContent ( ) } </ div >
102
+ </ div >
126
103
</ div >
127
104
) ;
128
105
} ) ;
0 commit comments