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

Commit 9db9f8c

Browse files
committed
Re-enabling mapProps prop for Field component
1 parent 311f511 commit 9db9f8c

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/components/field-component.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ function createFieldControlComponent(control, props, options) {
114114
}
115115

116116
/* eslint-disable react/prop-types */
117-
const mapProps = options.controlPropsMap[getControlType(control, options)];
117+
const {
118+
mapProps = options.controlPropsMap[getControlType(control, options)],
119+
} = props;
118120

119121
const controlProps = omit(props, ['children', 'className']);
120122

@@ -211,6 +213,7 @@ function createFieldClass(customControlPropsMap = {}, defaultProps = {}) {
211213
PropTypes.object,
212214
]),
213215
modelValue: PropTypes.any,
216+
mapProps: PropTypes.func,
214217
};
215218

216219
Field.defaultProps = {

test/field-component-spec.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import capitalize from 'lodash/capitalize';
99
import sinon from 'sinon';
1010
import createTestStore from 'redux-test-store';
1111

12-
import { Field, actions, actionTypes, formReducer, modelReducer } from '../src';
12+
import { Field, actions, actionTypes, formReducer, modelReducer, controls } from '../src';
1313

1414
describe('<Field /> component', () => {
1515
const textFieldElements = [
@@ -1568,4 +1568,39 @@ describe('<Field /> component', () => {
15681568

15691569
assert.equal(input.name, 'another[name]');
15701570
});
1571+
1572+
it('should allow a custom mapProps() prop for use in Control', () => {
1573+
const store = applyMiddleware(thunk)(createStore)(combineReducers({
1574+
test: modelReducer('test', { foo: 'initial' }),
1575+
}));
1576+
1577+
const CustomInput = (props) => (
1578+
<div><input {...props} /></div>
1579+
);
1580+
1581+
const field = TestUtils.renderIntoDocument(
1582+
<Provider store={store}>
1583+
<Field
1584+
model="test.foo"
1585+
mapProps={controls.text}
1586+
>
1587+
<CustomInput />
1588+
</Field>
1589+
</Provider>
1590+
);
1591+
1592+
const input = TestUtils.findRenderedDOMComponentWithTag(field, 'input');
1593+
1594+
assert.equal(input.value, 'initial');
1595+
1596+
input.value = 'new value';
1597+
1598+
TestUtils.Simulate.change(input);
1599+
1600+
assert.equal(input.value, 'new value');
1601+
assert.equal(
1602+
store.getState().test.foo,
1603+
'new value'
1604+
);
1605+
});
15711606
});

0 commit comments

Comments
 (0)