@@ -22,15 +22,18 @@ export default class GeoPointEditor extends React.Component {
2222 this . checkExternalClick = this . checkExternalClick . bind ( this ) ;
2323 this . handleKeyLatitude = this . handleKeyLatitude . bind ( this ) ;
2424 this . handleKeyLongitude = this . handleKeyLongitude . bind ( this ) ;
25+
26+ this . latitudeRef = React . createRef ( ) ;
27+ this . longitudeRef = React . createRef ( ) ;
2528 }
2629
2730 componentDidMount ( ) {
2831 if ( ! this . props . disableAutoFocus ) {
29- this . refs . latitude . focus ( ) ;
32+ this . latitudeRef . current . focus ( ) ;
3033 }
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 ) ;
3437 }
3538
3639 componentWillReceiveProps ( props ) {
@@ -45,8 +48,8 @@ export default class GeoPointEditor extends React.Component {
4548 }
4649
4750 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 ) ;
5053 }
5154
5255 checkExternalClick ( ) {
@@ -55,8 +58,8 @@ export default class GeoPointEditor extends React.Component {
5558 // check if activeElement is something else from input fields,
5659 // to avoid commiting new value on every switch of focus beetween latitude and longitude fields
5760 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
6063 ) {
6164 this . commitValue ( ) ;
6265 }
@@ -65,8 +68,8 @@ export default class GeoPointEditor extends React.Component {
6568
6669 handleKeyLatitude ( e ) {
6770 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 ) ;
7073 }
7174 }
7275
@@ -112,15 +115,15 @@ export default class GeoPointEditor extends React.Component {
112115
113116 if ( values [ 1 ] . length <= 0 || ! validateNumeric ( values [ 1 ] ) ) {
114117 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 ) ;
117120 return ;
118121 }
119122
120123 if ( validateNumeric ( values [ 1 ] ) ) {
121124 this . setState ( { latitude : values [ 0 ] } ) ;
122125 this . setState ( { longitude : values [ 1 ] } ) ;
123- this . refs . longitude . focus ( ) ;
126+ this . longitudeRef . current . focus ( ) ;
124127 return ;
125128 }
126129 }
@@ -130,14 +133,14 @@ export default class GeoPointEditor extends React.Component {
130133 this . setState ( { [ target ] : validateNumeric ( value ) ? value : this . state [ target ] } ) ;
131134 } ;
132135 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 } >
134137 < input
135- ref = 'latitude'
138+ ref = { this . latitudeRef }
136139 value = { this . state . latitude }
137140 onBlur = { this . checkExternalClick }
138141 onChange = { onChange . bind ( this , 'latitude' ) } />
139142 < input
140- ref = 'longitude'
143+ ref = { this . longitudeRef }
141144 value = { this . state . longitude }
142145 onBlur = { this . checkExternalClick }
143146 onChange = { onChange . bind ( this , 'longitude' ) } />
0 commit comments