Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 591cdae

Browse files
committed
Bypassing null/falsey children in createFieldControlComponent. Fixes #111
1 parent e5446c8 commit 591cdae

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/components/field-component.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,12 @@ function createFieldControlComponent(control, props, options) {
261261
control.props.children,
262262
child => createFieldControlComponent(
263263
child,
264-
{ ...props, ...child.props },
264+
{
265+
...props,
266+
...(child && child.props
267+
? child.props
268+
: {}),
269+
},
265270
options
266271
)
267272
),

test/field-component-spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ describe('<Field /> component', () => {
9494
'should update state when control is changed');
9595
});
9696

97+
it('should bypass null/falsey children', () => {
98+
assert.doesNotThrow(() => {
99+
const store = applyMiddleware(thunk)(createStore)(combineReducers({
100+
test: modelReducer('test', { foo: 'bar' }),
101+
}));
102+
103+
TestUtils.renderIntoDocument(
104+
<Provider store={store}>
105+
<Field model="test.foo">
106+
<input />
107+
<div>{ false }</div>
108+
</Field>
109+
</Provider>
110+
);
111+
});
112+
});
113+
97114
textFieldElements.map(([element, type]) => { // eslint-disable-line array-callback-return
98115
describe(`with <${element} ${type ? `type="${type}"` : ''}/>`, () => {
99116
const store = applyMiddleware(thunk)(createStore)(combineReducers({
@@ -1196,6 +1213,7 @@ describe('<Field /> component', () => {
11961213
model="test.foo"
11971214
>
11981215
<input type="text" onChange={onChangeFnSpy} />
1216+
<div>{ false }</div>
11991217
</Field>
12001218
</Provider>
12011219
);

0 commit comments

Comments
 (0)