@@ -22,15 +22,18 @@ export default class GeoPointEditor extends React.Component {
22
22
this . checkExternalClick = this . checkExternalClick . bind ( this ) ;
23
23
this . handleKeyLatitude = this . handleKeyLatitude . bind ( this ) ;
24
24
this . handleKeyLongitude = this . handleKeyLongitude . bind ( this ) ;
25
+
26
+ this . latitudeRef = React . createRef ( ) ;
27
+ this . longitudeRef = React . createRef ( ) ;
25
28
}
26
29
27
30
componentDidMount ( ) {
28
31
if ( ! this . props . disableAutoFocus ) {
29
- this . refs . latitude . focus ( ) ;
32
+ this . latitudeRef . current . focus ( ) ;
30
33
}
31
- this . refs . latitude . setSelectionRange ( 0 , String ( this . state . latitude ) . length ) ;
32
- this . refs . latitude . addEventListener ( 'keypress' , this . handleKeyLatitude ) ;
33
- this . refs . longitude . addEventListener ( 'keypress' , this . handleKeyLongitude ) ;
34
+ this . latitudeRef . current . setSelectionRange ( 0 , String ( this . state . latitude ) . length ) ;
35
+ this . latitudeRef . current . addEventListener ( 'keypress' , this . handleKeyLatitude ) ;
36
+ this . longitudeRef . current . addEventListener ( 'keypress' , this . handleKeyLongitude ) ;
34
37
}
35
38
36
39
componentWillReceiveProps ( props ) {
@@ -45,8 +48,8 @@ export default class GeoPointEditor extends React.Component {
45
48
}
46
49
47
50
componentWillUnmount ( ) {
48
- this . refs . latitude . removeEventListener ( 'keypress' , this . handleKeyLatitude ) ;
49
- this . refs . longitude . removeEventListener ( 'keypress' , this . handleKeyLongitude ) ;
51
+ this . latitudeRef . current . removeEventListener ( 'keypress' , this . handleKeyLatitude ) ;
52
+ this . longitudeRef . current . removeEventListener ( 'keypress' , this . handleKeyLongitude ) ;
50
53
}
51
54
52
55
checkExternalClick ( ) {
@@ -55,8 +58,8 @@ export default class GeoPointEditor extends React.Component {
55
58
// check if activeElement is something else from input fields,
56
59
// to avoid commiting new value on every switch of focus beetween latitude and longitude fields
57
60
if (
58
- document . activeElement !== this . refs . latitude &&
59
- document . activeElement !== this . refs . longitude
61
+ document . activeElement !== this . latitudeRef . current &&
62
+ document . activeElement !== this . longitudeRef . current
60
63
) {
61
64
this . commitValue ( ) ;
62
65
}
@@ -65,8 +68,8 @@ export default class GeoPointEditor extends React.Component {
65
68
66
69
handleKeyLatitude ( e ) {
67
70
if ( e . keyCode === 13 || e . keyCode === 44 ) {
68
- this . refs . longitude . focus ( ) ;
69
- this . refs . longitude . setSelectionRange ( 0 , String ( this . state . longitude ) . length ) ;
71
+ this . longitudeRef . current . focus ( ) ;
72
+ this . longitudeRef . current . setSelectionRange ( 0 , String ( this . state . longitude ) . length ) ;
70
73
}
71
74
}
72
75
@@ -112,15 +115,15 @@ export default class GeoPointEditor extends React.Component {
112
115
113
116
if ( values [ 1 ] . length <= 0 || ! validateNumeric ( values [ 1 ] ) ) {
114
117
this . setState ( { latitude : values [ 0 ] } ) ;
115
- this . refs . longitude . focus ( ) ;
116
- this . refs . longitude . setSelectionRange ( 0 , String ( this . state . longitude ) . length ) ;
118
+ this . longitudeRef . current . focus ( ) ;
119
+ this . longitudeRef . current . setSelectionRange ( 0 , String ( this . state . longitude ) . length ) ;
117
120
return ;
118
121
}
119
122
120
123
if ( validateNumeric ( values [ 1 ] ) ) {
121
124
this . setState ( { latitude : values [ 0 ] } ) ;
122
125
this . setState ( { longitude : values [ 1 ] } ) ;
123
- this . refs . longitude . focus ( ) ;
126
+ this . longitudeRef . current . focus ( ) ;
124
127
return ;
125
128
}
126
129
}
@@ -130,14 +133,14 @@ export default class GeoPointEditor extends React.Component {
130
133
this . setState ( { [ target ] : validateNumeric ( value ) ? value : this . state [ target ] } ) ;
131
134
} ;
132
135
return (
133
- < div ref = 'input' style = { { width : this . props . width , ...this . props . style } } className = { styles . editor } >
136
+ < div style = { { width : this . props . width , ...this . props . style } } className = { styles . editor } >
134
137
< input
135
- ref = 'latitude'
138
+ ref = { this . latitudeRef }
136
139
value = { this . state . latitude }
137
140
onBlur = { this . checkExternalClick }
138
141
onChange = { onChange . bind ( this , 'latitude' ) } />
139
142
< input
140
- ref = 'longitude'
143
+ ref = { this . longitudeRef }
141
144
value = { this . state . longitude }
142
145
onBlur = { this . checkExternalClick }
143
146
onChange = { onChange . bind ( this , 'longitude' ) } />
0 commit comments