@@ -14,11 +14,15 @@ const getInputs = children =>
14
14
if ( child && child . props && child . props . children ) {
15
15
return partialInputs . concat ( getInputs ( child . props . children ) ) ;
16
16
}
17
- if ( child && child . props && ! ! child . props . name ) return partialInputs . concat ( child ) ;
17
+ if ( child && child . props && ! ! child . props . name )
18
+ return partialInputs . concat ( child ) ;
18
19
return partialInputs ;
19
20
} , [ ] ) ;
20
21
21
- export const withNextInputAutoFocusForm = ( WrappedComponent , { submitAfterLastInput } = { submitAfterLastInput : true } ) => {
22
+ export const withNextInputAutoFocusForm = (
23
+ WrappedComponent ,
24
+ { submitAfterLastInput } = { submitAfterLastInput : true }
25
+ ) => {
22
26
class WithNextInputAutoFocusForm extends React . PureComponent {
23
27
static childContextTypes = withNextInputAutoFocusContextType ;
24
28
@@ -32,24 +36,26 @@ export const withNextInputAutoFocusForm = (WrappedComponent, { submitAfterLastIn
32
36
inputNameMap ;
33
37
inputRefs = { } ;
34
38
35
- getInputPosition = name => this . inputs . findIndex ( input => input . props . name === name ) ;
39
+ getInputPosition = name =>
40
+ this . inputs . findIndex ( input => input . props . name === name ) ;
36
41
37
42
getChildContext = ( ) => ( {
38
43
setInput : ( name , component ) => {
39
44
this . inputRefs [ name ] = component ;
40
45
} ,
41
46
handleSubmitEditing : name => {
42
47
const inputPosition = this . getInputPosition ( name ) ;
43
- const isLastInput = inputPosition === this . inputs . length - 1 ;
44
-
45
- if ( isLastInput ) {
46
- if ( submitAfterLastInput ) this . props . formik . submitForm ( ) ;
47
- } else {
48
- const nextInputs = this . inputs . slice ( inputPosition + 1 ) ;
49
- const nextFocusableInput = nextInputs . find (
50
- element => this . inputRefs [ element . props . name ] && this . inputRefs [ element . props . name ] . focus
51
- ) ;
48
+ const nextInputs = this . inputs . slice ( inputPosition + 1 ) ;
49
+ const nextFocusableInput = nextInputs . find (
50
+ element =>
51
+ this . inputRefs [ element . props . name ] &&
52
+ this . inputRefs [ element . props . name ] . focus
53
+ ) ;
54
+
55
+ if ( nextFocusableInput ) {
52
56
this . inputRefs [ nextFocusableInput . props . name ] . focus ( ) ;
57
+ } else {
58
+ if ( submitAfterLastInput ) this . props . formik . submitForm ( ) ;
53
59
}
54
60
} ,
55
61
getReturnKeyType : name => {
@@ -69,7 +75,10 @@ export const withNextInputAutoFocusForm = (WrappedComponent, { submitAfterLastIn
69
75
} ;
70
76
71
77
export const withNextInputAutoFocusInput = Input => {
72
- class WithNextInputAutoFocusInput extends React . Component < $FlowFixMeProps , $FlowFixMeState > {
78
+ class WithNextInputAutoFocusInput extends React . Component <
79
+ $FlowFixMeProps ,
80
+ $FlowFixMeState
81
+ > {
73
82
static contextTypes = withNextInputAutoFocusContextType ;
74
83
75
84
setInput = component => {
0 commit comments