@@ -74,18 +74,21 @@ export const SubMenu = React.forwardRef(function <Tag extends TagType = 'a'>(
74
74
} ;
75
75
const popupRef = React . useRef < OverlayTriggerRef > ( null ) ;
76
76
const refNode = React . useRef < HTMLElement | null > ( ) ;
77
- const currentHeight = React . useRef < number > ( 0 ) ;
78
77
const elementSource = React . useRef < EventTarget | null > ( ) ;
79
78
const [ isOpen , setIsOpen ] = useState ( ! ! overlayProps . isOpen ) ;
80
79
const { height, setContextHeight, ele } = useContext ( ThemeContext ) ;
81
80
82
81
React . useEffect ( ( ) => {
83
82
if ( refNode . current && refNode . current . style && ele === elementSource . current ) {
84
- const currentHeight = refNode . current ! . style . height ;
85
- if ( height + 'px' === currentHeight ) return ;
86
- refNode . current ! . style . height = Number ( currentHeight . substr ( 0 , currentHeight . length - 2 ) ) + height + 'px' ;
83
+ const currentHeight = Number ( refNode . current ! . style . height . substr ( 0 , refNode . current ! . style . height . length - 2 ) ) ;
84
+ // 设置的高度 < '已有展开的高度',
85
+ if ( refNode . current ! . getBoundingClientRect ( ) . height < currentHeight ) {
86
+ refNode . current ! . style . height = currentHeight + 'px' ;
87
+ } else {
88
+ refNode . current ! . style . height = currentHeight + height + 'px' ;
89
+ }
87
90
}
88
- } , [ height ] ) ;
91
+ } , [ height , ele ] ) ;
89
92
90
93
useMemo ( ( ) => {
91
94
if ( collapse ) setIsOpen ( false ) ;
@@ -101,23 +104,12 @@ export const SubMenu = React.forwardRef(function <Tag extends TagType = 'a'>(
101
104
}
102
105
}
103
106
}
104
- function onExit ( node : HTMLElement ) {
105
- node . style . height = `${ node . scrollHeight } px` ;
106
- setIsOpen ( false ) ;
107
- }
108
- function onExiting ( node : HTMLElement ) {
109
- node . style . height = '0px' ;
110
- setContextHeight ( {
111
- height : - currentHeight . current ,
112
- ele : elementSource . current ! ,
113
- } ) ;
114
- }
115
107
function onEnter ( node : HTMLElement ) {
116
- node . style . height = '1px' ;
108
+ node . style . height = '0px' ;
109
+ refNode . current = node ;
117
110
setIsOpen ( true ) ;
118
- currentHeight . current = popupRef . current ! . overlayDom . current ! . getBoundingClientRect ( ) . height ;
119
111
setContextHeight ( {
120
- height : currentHeight . current ,
112
+ height : popupRef . current ! . overlayDom . current ! . getBoundingClientRect ( ) . height ,
121
113
ele : elementSource . current ! ,
122
114
} ) ;
123
115
}
@@ -126,9 +118,20 @@ export const SubMenu = React.forwardRef(function <Tag extends TagType = 'a'>(
126
118
}
127
119
function onEntered ( node : HTMLElement ) {
128
120
// node.style.height = 'initial';
129
- node . style . height = currentHeight . current + 'px' ;
130
- refNode . current = node ;
121
+ node . style . height = popupRef . current ! . overlayDom . current ! . getBoundingClientRect ( ) . height + 'px' ;
122
+ }
123
+ function onExiting ( node : HTMLElement ) {
124
+ node . style . height = '0px' ;
125
+ setContextHeight ( {
126
+ height : - popupRef . current ! . overlayDom . current ! . getBoundingClientRect ( ) . height ,
127
+ ele : elementSource . current ! ,
128
+ } ) ;
129
+ }
130
+ function onExit ( node : HTMLElement ) {
131
+ node . style . height = `${ node . scrollHeight } px` ;
132
+ setIsOpen ( false ) ;
131
133
}
134
+
132
135
if ( ! collapse ) {
133
136
delete menuProps . onClick ;
134
137
menuProps . bordered = false ;
0 commit comments