From 268f17f7da0185a31d5756524ffb083aafe74ddc Mon Sep 17 00:00:00 2001 From: chenxi-20 <2465950588@qq.com> Date: Fri, 27 Oct 2023 02:08:31 -0700 Subject: [PATCH] fix(tabs): Fix tabs initialization clicking more buttons not working properly --- packages/renderless/src/tabs/index.ts | 42 ++++++++++----------------- packages/renderless/src/tabs/vue.ts | 2 +- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/packages/renderless/src/tabs/index.ts b/packages/renderless/src/tabs/index.ts index e3de2f84cc..903c21c9cc 100644 --- a/packages/renderless/src/tabs/index.ts +++ b/packages/renderless/src/tabs/index.ts @@ -62,13 +62,7 @@ export const calcPaneInstances = /* istanbul ignore */ export const calcMorePanes = - ({ - parent, - props, - state, - refs, - nextTick - }: Pick) => + ({ parent, props, state, refs }: Pick) => () => { if (!props.showMoreTabs) { return @@ -79,26 +73,22 @@ export const calcMorePanes = const tabNavRefs = refs.nav.$refs if (tabs && tabs.length) { - nextTick(() => { - nextTick(() => { - let tabsAllWidth = 0 - for (let i = 0; i < tabs.length; i++) { - const tabItem = tabs[i] as HTMLElement - // 遮住元素一半则隐藏 - tabsAllWidth = tabItem.offsetLeft + tabItem.offsetWidth / 2 - const tabsHeaderWidth = tabNavRefs.navScroll.offsetWidth - const currentName = Number(state.currentName) - if (tabsAllWidth > tabsHeaderWidth && currentName >= 0) { - if (currentName >= i + 1) { - state.showPanesCount = currentName - 0 - } else { - state.showPanesCount = i - } - break - } + let tabsAllWidth = 0 + for (let i = 0; i < tabs.length; i++) { + const tabItem = tabs[i] as HTMLElement + // 遮住元素一半则隐藏 + tabsAllWidth = tabItem.offsetLeft + tabItem.offsetWidth / 2 + const tabsHeaderWidth = tabNavRefs.navScroll.offsetWidth + const currentName = Number(state.currentName || 0) + if (tabsAllWidth > tabsHeaderWidth && currentName >= 0) { + if (currentName >= i + 1) { + state.showPanesCount = currentName - 0 + } else { + state.showPanesCount = i } - }) - }) + break + } + } } } diff --git a/packages/renderless/src/tabs/vue.ts b/packages/renderless/src/tabs/vue.ts index 1761810e45..7a3b76b1ef 100644 --- a/packages/renderless/src/tabs/vue.ts +++ b/packages/renderless/src/tabs/vue.ts @@ -111,7 +111,7 @@ export const renderless = ( handleTabRemove: handleTabRemove(emit), changeDirection: changeDirection({ props, state }), changeCurrentName: changeCurrentName({ emit, state }), - calcMorePanes: calcMorePanes({ parent, props, state, refs, nextTick }), + calcMorePanes: calcMorePanes({ parent, props, state, refs }), calcExpandPanes: calcExpandPanes({ parent, props, state }), calcPaneInstances: calcPaneInstances({ constants, parent, state, childrenHandler }), handleTabDragStart: handleTabDragStart({ emit }),