Skip to content

Commit

Permalink
fix: 修复tabs组件异步加载tab时下划线失效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
三少 committed Dec 7, 2021
1 parent a0f6c29 commit ce7804b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/vantui/src/tabs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ export function Tabs(props: TabsProps) {
comIndex++
indexRef.current = comIndex
}, [])

const tabs = useMemo(() => {
return parseTabList(children)
}, [children])

const newChildren = useMemo(() => {
return tabs.map((tab, index) => {
return cloneElement(tab.node, {
Expand All @@ -130,6 +132,7 @@ export function Tabs(props: TabsProps) {
})
}) as any[]
}, [animated, currentIndex, lazyRender, tabs])

const trigger = function (
eventName: 'onClick' | 'onChange' | 'onDisabled',
child?: any,
Expand Down Expand Up @@ -391,6 +394,17 @@ export function Tabs(props: TabsProps) {
[swipeThreshold],
)

// 解决异步加载的时候默认的下划线不出现的问题
useEffect(
function () {
Taro.nextTick(() => {
resize()
})
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[newChildren],
)

return (
<View
className={
Expand Down

0 comments on commit ce7804b

Please sign in to comment.