1919 :class =" `wd-tabs__nav-item ${state.activeIndex === index ? 'is-active' : ''} ${item.disabled ? 'is-disabled' : ''}`"
2020 :style =" state.activeIndex === index ? (color ? 'color:' + color : '') : inactiveColor ? 'color:' + inactiveColor : ''"
2121 >
22- {{ item.title }}
22+ < text class = " wd-tabs__nav-item-text " > {{ item.title }}</ text >
2323 <view class =" wd-tabs__line wd-tabs__line--inner" v-if =" state.activeIndex === index && state.useInnerLine" ></view >
2424 </view >
2525 <!-- 下划线-->
9191 :class =" `wd-tabs__nav-item ${state.activeIndex === index ? 'is-active' : ''} ${item.disabled ? 'is-disabled' : ''}`"
9292 :style =" state.activeIndex === index ? (color ? 'color:' + color : '') : inactiveColor ? 'color:' + inactiveColor : ''"
9393 >
94- {{ item.title }}
94+ < text class = " wd-tabs__nav-item-text " > {{ item.title }}</ text >
9595 <view class =" wd-tabs__line wd-tabs__line--inner" v-if =" state.activeIndex === index && state.useInnerLine" ></view >
9696 </view >
9797 <!-- 下划线-->
@@ -153,6 +153,7 @@ import { useChildren } from '../composables/useChildren'
153153import { useTranslate } from ' ../composables/useTranslate'
154154
155155const $item = ' .wd-tabs__nav-item'
156+ const $itemText = ' .wd-tabs__nav-item-text'
156157const $container = ' .wd-tabs__nav-container'
157158
158159const props = defineProps (tabsProps )
@@ -319,14 +320,20 @@ function toggleMap() {
319320 * 更新 underline的偏移量
320321 * @param animation 是否开启动画
321322 */
322- function updateLineStyle(animation : boolean = true ) {
323+ async function updateLineStyle(animation : boolean = true ) {
323324 if (! state .inited ) return
324- const { lineWidth, lineHeight } = props
325-
326- getRect ($item , true , proxy ). then (( rects ) => {
325+ const { autoLineWidth, lineWidth, lineHeight } = props
326+ try {
327+ const rects = await getRect ($item , true , proxy )
327328 const lineStyle: CSSProperties = {}
328329 if (isDef (lineWidth )) {
329330 lineStyle .width = addUnit (lineWidth )
331+ } else {
332+ if (autoLineWidth ) {
333+ const textRects = await getRect ($itemText , true , proxy )
334+ const textWidth = Number (textRects [state .activeIndex ].width )
335+ lineStyle .width = addUnit (textWidth )
336+ }
330337 }
331338 if (isDef (lineHeight )) {
332339 lineStyle .height = addUnit (lineHeight )
@@ -342,7 +349,9 @@ function updateLineStyle(animation: boolean = true) {
342349 state .useInnerLine = false
343350 state .lineStyle = objToStyle (lineStyle )
344351 }
345- })
352+ } catch (error ) {
353+ console .error (' [wot design] error(wd-tabs): update line style failed' , error )
354+ }
346355}
347356/**
348357 * @description 通过控制tab的active来展示选定的tab
0 commit comments