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

Commit 98fa978

Browse files
committed
Fixing textarea onUpdate="blur" change triggered on enter key. Fixes #930
1 parent e9e4980 commit 98fa978

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/components/control-component.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const propTypes = {
102102
persist: PropTypes.bool,
103103
getValue: PropTypes.func,
104104
isToggle: PropTypes.bool,
105+
updateOnEnter: PropTypes.bool,
105106

106107
// HTML5 attributes
107108
formNoValidate: PropTypes.bool,
@@ -440,11 +441,12 @@ function createControlClass(s = defaultStrategy) {
440441
handleKeyPress(event) {
441442
const {
442443
controlProps: { onKeyPress },
444+
updateOnEnter,
443445
} = this.props;
444446

445447
if (onKeyPress) onKeyPress(event);
446448

447-
if (event.key === 'Enter') {
449+
if (updateOnEnter && event.key === 'Enter') {
448450
this.forceHandleUpdate(event);
449451
}
450452
}
@@ -646,6 +648,7 @@ function createControlClass(s = defaultStrategy) {
646648
persist: false,
647649
getValue: _getValue,
648650
isToggle: false,
651+
updateOnEnter: true,
649652
};
650653

651654
function mapStateToProps(state, props) {
@@ -770,6 +773,7 @@ function createControlClass(s = defaultStrategy) {
770773
return (
771774
<ConnectedControl
772775
component="textarea"
776+
updateOnEnter={false}
773777
{...this.props}
774778
mapProps={{
775779
...controlPropsMap.textarea,

test/control-component-spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,35 @@ Object.keys(testContexts).forEach((testKey) => {
14871487

14881488
assert.isFalse(store.getState().testForm.foo.valid);
14891489
});
1490+
1491+
it('should not change blur-updated textareas upon pressing Enter', () => {
1492+
const reducer = modelReducer('test');
1493+
const store = testCreateStore({
1494+
test: reducer,
1495+
testForm: formReducer('test'),
1496+
});
1497+
const field = TestUtils.renderIntoDocument(
1498+
<Provider store={store}>
1499+
<Control.textarea
1500+
model="test.foo"
1501+
updateOn="blur"
1502+
/>
1503+
</Provider>
1504+
);
1505+
1506+
const control = TestUtils.findRenderedDOMComponentWithTag(field, 'textarea');
1507+
1508+
control.value = 'testing';
1509+
1510+
TestUtils.Simulate.keyPress(control, {
1511+
key: 'Enter',
1512+
keyCode: 13,
1513+
which: 13,
1514+
});
1515+
1516+
assert.isUndefined(
1517+
get(store.getState().test, 'foo'));
1518+
});
14901519
});
14911520

14921521
describe('handling onKeyPress', () => {

0 commit comments

Comments
 (0)