@@ -64,6 +64,34 @@ interface ExtraContentProps {
64
64
extra ?: ( info ?: { position : 'left' | 'right' } ) => TabBarExtraContent ;
65
65
}
66
66
67
+ const getTabSize = ( tab : HTMLElement , containerRect : { x : number ; y : number } ) => {
68
+ // tabListRef
69
+ const { offsetWidth, offsetHeight, offsetTop, offsetLeft } = tab ;
70
+ const { width, height, x, y } = tab . getBoundingClientRect ( ) ;
71
+
72
+ // Use getBoundingClientRect to avoid decimal inaccuracy
73
+ if ( Math . abs ( width - offsetWidth ) < 1 ) {
74
+ return [ width , height , x - containerRect . x , y - containerRect . y ] ;
75
+ }
76
+
77
+ return [ offsetWidth , offsetHeight , offsetLeft , offsetTop ] ;
78
+ } ;
79
+
80
+ // const getSize = (refObj: ShallowRef<HTMLElement>) => {
81
+ // const { offsetWidth = 0, offsetHeight = 0 } = refObj.value || {};
82
+
83
+ // // Use getBoundingClientRect to avoid decimal inaccuracy
84
+ // if (refObj.value) {
85
+ // const { width, height } = refObj.value.getBoundingClientRect();
86
+
87
+ // if (Math.abs(width - offsetWidth) < 1) {
88
+ // return [width, height];
89
+ // }
90
+ // }
91
+
92
+ // return [offsetWidth, offsetHeight];
93
+ // };
94
+
67
95
export default defineComponent ( {
68
96
compatConfig : { MODE : 3 } ,
69
97
name : 'TabNavList' ,
@@ -288,7 +316,29 @@ export default defineComponent({
288
316
289
317
return ( [ visibleStart . value , visibleEnd . value ] = [ startIndex , endIndex ] ) ;
290
318
} ) ;
319
+ const updateTabSizes = ( ) => {
320
+ setTabSizes ( ( ) => {
321
+ const newSizes : TabSizeMap = new Map ( ) ;
322
+ const listRect = tabListRef . value ?. getBoundingClientRect ( ) ;
323
+ tabs . value . forEach ( ( { key } ) => {
324
+ const btnRef = btnRefs . value . get ( key ) ;
325
+ const btnNode = ( btnRef as any ) ?. $el || btnRef ;
326
+ if ( btnNode ) {
327
+ const [ width , height , left , top ] = getTabSize ( btnNode , listRect ) ;
328
+ newSizes . set ( key , { width, height, left, top } ) ;
329
+ }
330
+ } ) ;
331
+ return newSizes ;
332
+ } ) ;
333
+ } ;
291
334
335
+ watch (
336
+ ( ) => tabs . value . map ( tab => tab . key ) . join ( '%%' ) ,
337
+ ( ) => {
338
+ updateTabSizes ( ) ;
339
+ } ,
340
+ { flush : 'post' } ,
341
+ ) ;
292
342
const onListHolderResize = ( ) => {
293
343
// Update wrapper records
294
344
const offsetWidth = tabsWrapperRef . value ?. offsetWidth || 0 ;
@@ -308,22 +358,7 @@ export default defineComponent({
308
358
setWrapperScrollHeight ( newWrapperScrollHeight ) ;
309
359
310
360
// Update buttons records
311
- setTabSizes ( ( ) => {
312
- const newSizes : TabSizeMap = new Map ( ) ;
313
- tabs . value . forEach ( ( { key } ) => {
314
- const btnRef = btnRefs . value . get ( key ) ;
315
- const btnNode = ( btnRef as any ) ?. $el || btnRef ;
316
- if ( btnNode ) {
317
- newSizes . set ( key , {
318
- width : btnNode . offsetWidth ,
319
- height : btnNode . offsetHeight ,
320
- left : btnNode . offsetLeft ,
321
- top : btnNode . offsetTop ,
322
- } ) ;
323
- }
324
- } ) ;
325
- return newSizes ;
326
- } ) ;
361
+ updateTabSizes ( ) ;
327
362
} ;
328
363
329
364
// ======================== Dropdown =======================
0 commit comments