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

Commit b4f388c

Browse files
committed
Fixing Control.checkbox to use custom changeAction if provided. Fixes #440
1 parent 4d7bb4b commit b4f388c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/components/control-component.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ function createControlClass(customControlPropsMap = {}, defaultProps = {}) {
642642
mapProps={{
643643
...controlPropsMap.checkbox,
644644
...props.mapProps,
645+
changeAction: props.changeAction || controlPropsMap.checkbox.changeAction,
645646
}}
646647
{...omit(props, 'mapProps')}
647648
/>

test/control-component-spec.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,10 @@ Object.keys(testContexts).forEach((testKey) => {
12501250
});
12511251

12521252
describe('changeAction prop', () => {
1253-
const initialState = getInitialState({ foo: '' });
1253+
const initialState = getInitialState({
1254+
foo: '',
1255+
checked: false,
1256+
});
12541257
const reducer = modelReducer('test', initialState);
12551258
const store = testCreateStore({
12561259
test: reducer,
@@ -1284,6 +1287,27 @@ Object.keys(testContexts).forEach((testKey) => {
12841287
get(store.getState().test, 'foo'),
12851288
'testing');
12861289
});
1290+
1291+
it('should execute the custom change action (checkbox)', () => {
1292+
let customChanged = false;
1293+
1294+
const field = TestUtils.renderIntoDocument(
1295+
<Provider store={store}>
1296+
<Control.checkbox
1297+
model="test.checked"
1298+
changeAction={() => {
1299+
customChanged = true;
1300+
}}
1301+
/>
1302+
</Provider>
1303+
);
1304+
1305+
const control = TestUtils.findRenderedDOMComponentWithTag(field, 'input');
1306+
1307+
TestUtils.Simulate.change(control);
1308+
1309+
assert.isTrue(customChanged);
1310+
});
12871311
});
12881312

12891313
describe('event handlers on control', () => {

0 commit comments

Comments
 (0)