Skip to content

Commit

Permalink
fix(vue): fix void field children is not undefined (#2551)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Dec 2, 2021
1 parent cb9f134 commit f5a1d1b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 26 deletions.
32 changes: 32 additions & 0 deletions packages/vue/src/__tests__/schema.markup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,36 @@ describe('recursion field', () => {
expect(wrapper.find('.ccc').exists()).toBeTruthy()
wrapper.destroy()
})

test('void field children', () => {
const form = createForm()
const VoidComponent = {
render(h: CreateElement) {
return h(
'div',
{ attrs: { 'data-testid': 'void-component' } },
this.$slots.default || 'placeholder'
)
},
}
const { SchemaField, SchemaVoidField } = createSchemaField({
components: {
VoidComponent,
},
})
const { queryByTestId } = render({
components: { SchemaField, SchemaVoidField },
data() {
return {
form,
}
},
template: `<FormProvider :form="form">
<SchemaField>
<SchemaVoidField x-component="VoidComponent" />
</SchemaField>
</FormProvider>`,
})
expect(queryByTestId('void-component').textContent).toBe('placeholder')
})
})
52 changes: 26 additions & 26 deletions packages/vue/src/components/RecursionField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,35 @@ const RecursionField = observer(

const renderProperties = (field?: GeneralField) => {
if (props.onlyRenderSelf) return
const children = fieldSchemaRef.value.mapProperties(
(item, name, index) => {
const base = field?.address || basePath
let schema: Schema = item
if (isFn(props.mapProperties)) {
const mapped = props.mapProperties(item, name)
if (mapped) {
schema = mapped
}
const properties = Schema.getOrderProperties(fieldSchemaRef.value)
if (!properties.length) return
const children = properties.map(({ schema: item, key: name }) => {
const base = field?.address || basePath
let schema: Schema = item
if (isFn(props.mapProperties)) {
const mapped = props.mapProperties(item, name)
if (mapped) {
schema = mapped
}
if (isFn(props.filterProperties)) {
if (props.filterProperties(schema, name) === false) {
return null
}
}
if (isFn(props.filterProperties)) {
if (props.filterProperties(schema, name) === false) {
return null
}
return h(
RecursionField,
{
key: name,
attrs: {
schema,
name,
basePath: base,
},
},
{}
)
}
)
return h(
RecursionField,
{
key: name,
attrs: {
schema,
name,
basePath: base,
},
},
{}
)
})

const slots: Record<string, () => any> = {}
if (children.length > 0) {
Expand Down

0 comments on commit f5a1d1b

Please sign in to comment.