Skip to content

Commit

Permalink
fix(utils): [vnode] flattedChildren support subTree (#10298)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxch committed Oct 31, 2022
1 parent deccb07 commit b45346c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
28 changes: 27 additions & 1 deletion packages/components/tabs/__tests__/tabs.test.tsx
@@ -1,4 +1,4 @@
import { nextTick, ref } from 'vue'
import { defineComponent, nextTick, ref } from 'vue'
import { mount } from '@vue/test-utils'
import { describe, expect, test, vi } from 'vitest'
import { EVENT_CODE } from '@element-plus/constants'
Expand All @@ -8,6 +8,19 @@ import TabNav from '../src/tab-nav'
import type { TabPaneName } from '../src/tabs'
import type { TabsPaneContext } from '@element-plus/tokens'

const Comp = defineComponent({
components: {
TabPane,
},
setup() {
return () => (
<TabPane name="tab1" label="tab1">
Tab 1 content
</TabPane>
)
},
})

describe('Tabs.vue', () => {
test('create', async () => {
const wrapper = mount(() => (
Expand Down Expand Up @@ -754,4 +767,17 @@ describe('Tabs.vue', () => {
expect(navItemsWrapper[2].classes('is-active')).toBe(true)
expect(navItemsWrapper[3].classes('is-active')).toBe(false)
})

test('tab-pane nested', async () => {
const wrapper = mount(() => (
<Tabs>
<Comp />
</Tabs>
))

const panesWrapper = wrapper.findAllComponents(TabPane)
await nextTick()

expect(panesWrapper.length).toBe(1)
})
})
3 changes: 3 additions & 0 deletions packages/utils/vue/vnode.ts
Expand Up @@ -159,6 +159,9 @@ export const flattedChildren = (
result.push(...flattedChildren(child.children))
} else {
result.push(child)
if (isVNode(child) && child.component?.subTree) {
result.push(...flattedChildren(child.component.subTree))
}
}
})
return result
Expand Down

0 comments on commit b45346c

Please sign in to comment.