diff --git a/packages/components/slot/__tests__/only-child.spec.ts b/packages/components/slot/__tests__/only-child.spec.ts index 5931085a53..b11a7e112b 100644 --- a/packages/components/slot/__tests__/only-child.spec.ts +++ b/packages/components/slot/__tests__/only-child.spec.ts @@ -75,6 +75,36 @@ describe('', () => { expect(wrapper.find('span').exists()).toBe(true) }) + it('should skip svg and child type is svg', async () => { + const wrapper = createComponent(() => [ + h( + 'svg', + { + xmlns: 'http://www.w3.org/2000/svg', + viewBox: '0 0 32 32', + width: '20', + height: '20', + }, + { + default: () => [ + h('path', { + d: 'M14.667 14.667v-8h2.667v8h8v2.667h-8v8h-2.667v-8h-8v-2.667z', + }), + ], + } + ), + ]) + await nextTick() + + expect(debugWarn).not.toHaveBeenCalled() + expect(wrapper.find('svg').attributes('viewBox')).toEqual('0 0 32 32') + expect(wrapper.find('svg').attributes('width')).toEqual('20') + expect(wrapper.find('svg').attributes('height')).toEqual('20') + + await wrapper.trigger('hover') + await expect(wrapper.find('svg').exists()).toBe(true) + }) + it('should skip comment', async () => { wrapper = createComponent(() => [ h(Fragment, [h(Comment, 'some comment'), AXIOM as any]), diff --git a/packages/components/slot/src/only-child.ts b/packages/components/slot/src/only-child.ts index 2f9548cea2..14c26f16c9 100644 --- a/packages/components/slot/src/only-child.ts +++ b/packages/components/slot/src/only-child.ts @@ -64,6 +64,8 @@ function findFirstLegitChild(node: VNode[] | undefined) { continue case Text: return wrapTextContent(child) + case 'svg': + return wrapTextContent(child) case Fragment: return findFirstLegitChild(child.children as VNode[]) default: