@@ -84,8 +84,12 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
84
84
85
85
const [ wrapperScrollWidth , setWrapperScrollWidth ] = useState < number > ( 0 ) ;
86
86
const [ wrapperScrollHeight , setWrapperScrollHeight ] = useState < number > ( 0 ) ;
87
+ const [ wrapperContentWidth , setWrapperContentWidth ] = useState < number > ( 0 ) ;
88
+ const [ wrapperContentHeight , setWrapperContentHeight ] = useState < number > ( 0 ) ;
87
89
const [ wrapperWidth , setWrapperWidth ] = useState < number > ( null ) ;
88
90
const [ wrapperHeight , setWrapperHeight ] = useState < number > ( null ) ;
91
+ const [ addWidth , setAddWidth ] = useState < number > ( 0 ) ;
92
+ const [ addHeight , setAddHeight ] = useState < number > ( 0 ) ;
89
93
90
94
const [ tabSizes , setTabSizes ] = useRafState < TabSizeMap > ( new Map ( ) ) ;
91
95
const tabOffsets = useOffsets ( tabs , tabSizes , wrapperScrollWidth ) ;
@@ -226,19 +230,17 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
226
230
left : transformLeft ,
227
231
top : transformTop ,
228
232
} ,
233
+ {
234
+ width : wrapperContentWidth ,
235
+ height : wrapperContentHeight ,
236
+ } ,
237
+ {
238
+ width : addWidth ,
239
+ height : addHeight ,
240
+ } ,
229
241
{ ...props , tabs } ,
230
242
) ;
231
243
232
- function getAdditionalSpaceSize ( type : 'offsetWidth' | 'offsetHeight' ) {
233
- const addBtnSize = innerAddButtonRef . current ?. [ type ] || 0 ;
234
- let optionsSize = 0 ;
235
- if ( operationsRef . current ?. className . includes ( operationsHiddenClassName ) ) {
236
- optionsSize = operationsRef . current [ type ] ;
237
- }
238
-
239
- return addBtnSize + optionsSize ;
240
- }
241
-
242
244
const tabNodes : React . ReactElement [ ] = tabs . map ( tab => {
243
245
const { key } = tab ;
244
246
return (
@@ -280,14 +282,25 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
280
282
// Update wrapper records
281
283
const offsetWidth = tabsWrapperRef . current ?. offsetWidth || 0 ;
282
284
const offsetHeight = tabsWrapperRef . current ?. offsetHeight || 0 ;
285
+ const newAddWidth = innerAddButtonRef . current ?. offsetWidth || 0 ;
286
+ const newAddHeight = innerAddButtonRef . current ?. offsetHeight || 0 ;
287
+ const newOperationWidth = operationsRef . current ?. offsetWidth || 0 ;
288
+ const newOperationHeight = operationsRef . current ?. offsetHeight || 0 ;
289
+
283
290
setWrapperWidth ( offsetWidth ) ;
284
291
setWrapperHeight ( offsetHeight ) ;
285
- setWrapperScrollWidth (
286
- ( tabListRef . current ?. offsetWidth || 0 ) - getAdditionalSpaceSize ( 'offsetWidth' ) ,
287
- ) ;
288
- setWrapperScrollHeight (
289
- ( tabListRef . current ?. offsetHeight || 0 ) - getAdditionalSpaceSize ( 'offsetHeight' ) ,
290
- ) ;
292
+ setAddWidth ( newAddWidth ) ;
293
+ setAddHeight ( newAddHeight ) ;
294
+
295
+ const newWrapperScrollWidth = ( tabListRef . current ?. offsetWidth || 0 ) - newAddWidth ;
296
+ const newWrapperScrollHeight = ( tabListRef . current ?. offsetHeight || 0 ) - newAddHeight ;
297
+
298
+ setWrapperScrollWidth ( newWrapperScrollWidth ) ;
299
+ setWrapperScrollHeight ( newWrapperScrollHeight ) ;
300
+
301
+ const isOperationHidden = operationsRef . current ?. className . includes ( operationsHiddenClassName ) ;
302
+ setWrapperContentWidth ( newWrapperScrollWidth - ( isOperationHidden ? 0 : newOperationWidth ) ) ;
303
+ setWrapperContentHeight ( newWrapperScrollHeight - ( isOperationHidden ? 0 : newOperationHeight ) ) ;
291
304
292
305
// Update buttons records
293
306
setTabSizes ( ( ) => {
@@ -355,7 +368,7 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
355
368
// Should recalculate when rtl changed
356
369
useEffect ( ( ) => {
357
370
onListHolderResize ( ) ;
358
- } , [ rtl , tabBarGutter , activeKey , tabs . map ( ( tab ) => tab . key ) . join ( '_' ) ] ) ;
371
+ } , [ rtl , tabBarGutter , activeKey , tabs . map ( tab => tab . key ) . join ( '_' ) ] ) ;
359
372
360
373
// ========================= Render ========================
361
374
const hasDropdown = ! ! hiddenTabs . length ;
@@ -410,14 +423,13 @@ function TabNavList(props: TabNavListProps, ref: React.Ref<HTMLDivElement>) {
410
423
} }
411
424
>
412
425
{ tabNodes }
413
- { ! hasDropdown && (
414
- < AddButton
415
- ref = { innerAddButtonRef }
416
- prefixCls = { prefixCls }
417
- locale = { locale }
418
- editable = { editable }
419
- />
420
- ) }
426
+ < AddButton
427
+ ref = { innerAddButtonRef }
428
+ prefixCls = { prefixCls }
429
+ locale = { locale }
430
+ editable = { editable }
431
+ style = { { visibility : hasDropdown ? 'hidden' : null } }
432
+ />
421
433
422
434
< div
423
435
className = { classNames ( `${ prefixCls } -ink-bar` , {
0 commit comments