From 0b4acfbabbdfb67752ccbb6ba4654612e31bf5bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=9D=E8=A3=B3?= <1923740402@qq.com> Date: Mon, 21 Feb 2022 14:23:20 +0800 Subject: [PATCH] fix: [el-popover] compatible svg (#6089) * fix: [el-popover] compatible svg * fix: add test --- .../slot/__tests__/only-child.spec.ts | 30 +++++++++++++++++++ packages/components/slot/src/only-child.ts | 2 ++ 2 files changed, 32 insertions(+) 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: