Skip to content

Commit

Permalink
Merge branch 'formily_next' of github.com:alibaba/formily into formil…
Browse files Browse the repository at this point in the history
…y_next
  • Loading branch information
janryWang committed Aug 26, 2021
2 parents 3b92370 + 71fb981 commit 0dba9f2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
40 changes: 40 additions & 0 deletions packages/vue/src/__tests__/schema.json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,46 @@ describe('x-content', () => {
expect(queryByTestId('previewer2')).toBeVisible()
expect(queryByTestId('previewer2').textContent).toEqual('123')
})

test('named slot in void field', () => {
const form = createForm()
const Content = {
render(h) {
return h('span', '123')
},
}
const { SchemaField } = createSchemaField({
components: {
Previewer2,
},
scope: {
Content,
},
})
const { queryByTestId } = render({
components: { SchemaField },
data() {
return {
form,
schema: new Schema({
type: 'void',
'x-component': 'Previewer2',
'x-content': {
content: '{{Content}}',
},
}),
}
},
template: `<FormProvider :form="form">
<SchemaField
name="string"
:schema="schema"
/>
</FormProvider>`,
})
expect(queryByTestId('previewer2')).toBeVisible()
expect(queryByTestId('previewer2').textContent).toEqual('123')
})
})

describe('scope', () => {
Expand Down
10 changes: 9 additions & 1 deletion packages/vue/src/components/RecursionField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ const RecursionField = observer(
}
)

const slots = getSlots(children)
const slots: Record<string, () => any> = {}
const allSlots = getSlots(children)
if (allSlots.default) {
slots.default = allSlots.default
}

return h(Fragment, {}, slots)
}
Expand All @@ -163,6 +167,7 @@ const RecursionField = observer(
if (!isValid(props.name)) return renderProperties()
if (fieldSchemaRef.value.type === 'object') {
if (props.onlyRenderProperties) return renderProperties()
const slots = getSlots()
return h(
ObjectField,
{
Expand All @@ -173,6 +178,7 @@ const RecursionField = observer(
},
},
{
...slots,
default: ({ field }) => [renderProperties(field)],
}
)
Expand All @@ -191,6 +197,7 @@ const RecursionField = observer(
)
} else if (fieldSchemaRef.value.type === 'void') {
if (props.onlyRenderProperties) return renderProperties()
const slots = getSlots()
return h(
VoidField,
{
Expand All @@ -201,6 +208,7 @@ const RecursionField = observer(
},
},
{
...slots,
default: ({ field }) => [renderProperties(field)],
}
)
Expand Down

0 comments on commit 0dba9f2

Please sign in to comment.