From a7757be5cc826559a4196994f2c7edc36a01f416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=88=E8=90=BD=E9=9F=B3=E9=98=91?= <424532913@qq.com> Date: Thu, 9 Dec 2021 17:10:28 +0800 Subject: [PATCH] fix(vue): fix x-content not work in void field (#2603) --- packages/vue/src/__tests__/schema.markup.spec.ts | 12 +++++------- packages/vue/src/components/ReactiveField.ts | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/vue/src/__tests__/schema.markup.spec.ts b/packages/vue/src/__tests__/schema.markup.spec.ts index 8ef41b71134..15146180d08 100644 --- a/packages/vue/src/__tests__/schema.markup.spec.ts +++ b/packages/vue/src/__tests__/schema.markup.spec.ts @@ -665,11 +665,7 @@ describe('recursion field', () => { const form = createForm() const VoidComponent = { render(h: CreateElement) { - return h( - 'div', - { attrs: { 'data-testid': 'void-component' } }, - this.$slots.default || 'placeholder' - ) + return h('div', this.$slots.default || 'placeholder') }, } const { SchemaField, SchemaVoidField } = createSchemaField({ @@ -686,10 +682,12 @@ describe('recursion field', () => { }, template: ` - + + `, }) - expect(queryByTestId('void-component').textContent).toBe('placeholder') + expect(queryByTestId('void-component-1').textContent).toBe('placeholder') + expect(queryByTestId('void-component-2').textContent).toBe('content') }) }) diff --git a/packages/vue/src/components/ReactiveField.ts b/packages/vue/src/components/ReactiveField.ts index 3788cec8972..3d1065fdb10 100644 --- a/packages/vue/src/components/ReactiveField.ts +++ b/packages/vue/src/components/ReactiveField.ts @@ -36,7 +36,7 @@ export default observer( if (!Object.keys(slots).length && !content) return {} const defaultSlot = slots?.default - ? slots?.default(props.field, props.field.form) + ? slots?.default(props.field, props.field.form) ?? [] : [] if (typeof content === 'string') { slots['default'] = () => [...defaultSlot, content]