Skip to content

Commit

Permalink
fix(vue): fix x-content not work in void field (#2603)
Browse files Browse the repository at this point in the history
  • Loading branch information
MisicDemone authored Dec 9, 2021
1 parent c9d43f0 commit a7757be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions packages/vue/src/__tests__/schema.markup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -686,10 +682,12 @@ describe('recursion field', () => {
},
template: `<FormProvider :form="form">
<SchemaField>
<SchemaVoidField x-component="VoidComponent" />
<SchemaVoidField x-component="VoidComponent" :x-component-props="{ 'data-testid': 'void-component-1' }" />
<SchemaVoidField x-component="VoidComponent" :x-component-props="{ 'data-testid': 'void-component-2' }" x-content="content" />
</SchemaField>
</FormProvider>`,
})
expect(queryByTestId('void-component').textContent).toBe('placeholder')
expect(queryByTestId('void-component-1').textContent).toBe('placeholder')
expect(queryByTestId('void-component-2').textContent).toBe('content')
})
})
2 changes: 1 addition & 1 deletion packages/vue/src/components/ReactiveField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit a7757be

Please sign in to comment.