Skip to content

Commit

Permalink
feat(react): fix schema x-component-props children invalid (#2160)
Browse files Browse the repository at this point in the history
  • Loading branch information
ifblooms authored Sep 17, 2021
1 parent 12dacdc commit 7dc9d9f
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
62 changes: 62 additions & 0 deletions packages/react/src/__tests__/schema.json.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,66 @@ describe('json schema field', () => {
)
expect(queryByTestId('input')).toBeVisible()
})
test('x-component-props children', () => {
const form = createForm()
const Text: React.FC = ({ children }) => {
return <div data-testid="children-test">{children}</div>
}
const SchemaField = createSchemaField({
components: {
Text,
},
})
const { queryByTestId } = render(
<FormProvider form={form}>
<SchemaField
name="object"
schema={{
type: 'object',
properties: {
string: {
type: 'string',
'x-component': 'Text',
'x-component-props': {
children: 'children',
},
},
},
}}
/>
</FormProvider>
)
expect(queryByTestId('children-test')).toBeVisible()
expect(queryByTestId('children-test').innerHTML).toEqual('children')
})
test('x-content', async () => {
const form = createForm()
const Text: React.FC = ({ children }) => {
return <div data-testid="content-test">{children}</div>
}
const SchemaField = createSchemaField({
components: {
Text,
},
})
const { queryByTestId } = render(
<FormProvider form={form}>
<SchemaField
name="object"
schema={{
type: 'object',
properties: {
string: {
type: 'string',
'x-component': 'Text',
'x-content': 'content',
},
},
}}
/>
</FormProvider>
)
expect(queryByTestId('content-test')).toBeVisible()
expect(queryByTestId('content-test').innerHTML).toEqual('content')
})
})
43 changes: 43 additions & 0 deletions packages/react/src/__tests__/schema.markup.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,49 @@ describe('markup schema field', () => {
</FormProvider>
)
})
test('props children', () => {
const form = createForm()
const Text: React.FC = (props) => {
return <div data-testid="children-test">{props.children}</div>
}
const SchemaField = createSchemaField({
components: {
Text,
},
})
const { queryByTestId } = render(
<FormProvider form={form}>
<SchemaField>
<SchemaField.Void
x-component="Text"
x-component-props={{ children: 'props' }}
/>
</SchemaField>
</FormProvider>
)
expect(queryByTestId('children-test')).toBeVisible()
expect(queryByTestId('children-test').innerHTML).toEqual('props')
})
test('x-content', () => {
const form = createForm()
const Text: React.FC = (props) => {
return <div data-testid="content-test">{props.children}</div>
}
const SchemaField = createSchemaField({
components: {
Text,
},
})
const { queryByTestId } = render(
<FormProvider form={form}>
<SchemaField>
<SchemaField.Void x-component="Text" x-content="content" />
</SchemaField>
</FormProvider>
)
expect(queryByTestId('content-test')).toBeVisible()
expect(queryByTestId('content-test').innerHTML).toEqual('content')
})
})

describe('recursion field', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/ReactiveField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const ReactiveInternal: React.FC<IReactiveFieldProps> = (props) => {
const field = props.field
const content = mergeChildren(
renderChildren(props.children, field, field.form),
field.content
field.content ?? field.component[1].children
)
if (field.display !== 'visible') return null

Expand Down

0 comments on commit 7dc9d9f

Please sign in to comment.