Skip to content

Commit

Permalink
feat(forms): Adds children to Forms (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
talend-glorieux authored Jun 7, 2017
1 parent 5c13599 commit 9ce1469
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/forms/src/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class Form extends React.Component {
this.form = c;
}}
>
{this.props.children}
<div className={this.props.buttonBlockClass}>
{renderActions(this.props.actions, this.handleActionClick)}
</div>
Expand Down Expand Up @@ -189,6 +190,7 @@ Form.propTypes = {
handleAction: PropTypes.func,
widgets: PropTypes.object,
formContext: PropTypes.func,
children: PropTypes.element,
};

Form.defaultProps = {
Expand Down
11 changes: 11 additions & 0 deletions packages/forms/src/Form.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,17 @@ describe('<Form/>', () => {
});
});

describe('children', () => {
it('should render children', () => {
wrapper = shallow(
<Form data={data} onSubmit={onSubmit}>
<h1>test</h1>
</Form>
);
expect(wrapper.find('h1')).toBeDefined();
});
});

describe('actions', () => {
it('should render default actions when no actions specified', () => {
// when
Expand Down
25 changes: 25 additions & 0 deletions packages/forms/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,28 @@ decoratedStories.add('Custom widget', () => {
/>
);
});

decoratedStories.add('Form Children', () => {
const schema = {
jsonSchema: {
title: 'Form with children',
type: 'object',
properties: {
test: {
title: 'Test title',
type: 'string',
},
},
},
uiSchema: {},
properties: {
test: 'test',
},
};
return (
<Form data={schema} onSubmit={action('SUBMIT')}>
<h1>Child</h1>
<p>This is an inner child in the form</p>
</Form>
);
});

0 comments on commit 9ce1469

Please sign in to comment.