This repository was archived by the owner on Aug 23, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ const propTypes = {
102
102
persist : PropTypes . bool ,
103
103
getValue : PropTypes . func ,
104
104
isToggle : PropTypes . bool ,
105
+ updateOnEnter : PropTypes . bool ,
105
106
106
107
// HTML5 attributes
107
108
formNoValidate : PropTypes . bool ,
@@ -440,11 +441,12 @@ function createControlClass(s = defaultStrategy) {
440
441
handleKeyPress ( event ) {
441
442
const {
442
443
controlProps : { onKeyPress } ,
444
+ updateOnEnter,
443
445
} = this . props ;
444
446
445
447
if ( onKeyPress ) onKeyPress ( event ) ;
446
448
447
- if ( event . key === 'Enter' ) {
449
+ if ( updateOnEnter && event . key === 'Enter' ) {
448
450
this . forceHandleUpdate ( event ) ;
449
451
}
450
452
}
@@ -646,6 +648,7 @@ function createControlClass(s = defaultStrategy) {
646
648
persist : false ,
647
649
getValue : _getValue ,
648
650
isToggle : false ,
651
+ updateOnEnter : true ,
649
652
} ;
650
653
651
654
function mapStateToProps ( state , props ) {
@@ -770,6 +773,7 @@ function createControlClass(s = defaultStrategy) {
770
773
return (
771
774
< ConnectedControl
772
775
component = "textarea"
776
+ updateOnEnter = { false }
773
777
{ ...this . props }
774
778
mapProps = { {
775
779
...controlPropsMap . textarea ,
Original file line number Diff line number Diff line change @@ -1487,6 +1487,35 @@ Object.keys(testContexts).forEach((testKey) => {
1487
1487
1488
1488
assert . isFalse ( store . getState ( ) . testForm . foo . valid ) ;
1489
1489
} ) ;
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
+ } ) ;
1490
1519
} ) ;
1491
1520
1492
1521
describe ( 'handling onKeyPress' , ( ) => {
You can’t perform that action at this time.
0 commit comments