88import Position from 'lib/Position' ;
99import PropTypes from 'prop-types'
1010import React , { Component } from 'react' ;
11- import ReactDOM from 'react-dom' ;
1211import styles from 'components/Autocomplete/Autocomplete.scss' ;
1312import SuggestionsList from 'components/SuggestionsList/SuggestionsList.react' ;
1413
@@ -32,8 +31,9 @@ export default class Autocomplete extends Component {
3231 this . getPosition = this . getPosition . bind ( this ) ;
3332 this . recalculatePosition = this . recalculatePosition . bind ( this ) ;
3433
35- this . inputRef = React . createRef ( null ) ;
36- this . dropdownRef = React . createRef ( null ) ;
34+ this . inputRef = React . createRef ( ) ;
35+ this . dropdownRef = React . createRef ( ) ;
36+ this . fieldRef = React . createRef ( ) ;
3737
3838 this . handleScroll = ( ) => {
3939 const pos = this . getPosition ( ) ;
@@ -57,23 +57,24 @@ export default class Autocomplete extends Component {
5757
5858 componentDidMount ( ) {
5959 window . addEventListener ( 'resize' , this . handleResize ) ;
60- this . node = ReactDOM . findDOMNode ( this ) ;
61- this . node . addEventListener ( 'scroll' , this . handleScroll ) ;
60+ this . fieldRef . current . addEventListener ( 'scroll' , this . handleScroll ) ;
6261 this . recalculatePosition ( ) ;
6362 this . _ignoreBlur = false ;
6463 }
6564
6665 componentWillUnmount ( ) {
67- this . node . removeEventListener ( 'scroll' , this . handleScroll ) ;
66+ this . fieldRef . current . removeEventListener ( 'scroll' , this . handleScroll ) ;
6867 window . removeEventListener ( 'resize' , this . handleResize ) ;
6968 }
7069
7170 getPosition ( ) {
71+ const node = this . fieldRef . current ;
72+
7273 let newPosition = this . props . fixed
73- ? Position . inWindow ( this . node )
74- : Position . inDocument ( this . node ) ;
74+ ? Position . inWindow ( node )
75+ : Position . inDocument ( node ) ;
7576
76- newPosition . y += this . node . offsetHeight ;
77+ newPosition . y += node . offsetHeight ;
7778
7879 return newPosition ;
7980 }
@@ -321,7 +322,7 @@ export default class Autocomplete extends Component {
321322
322323 return (
323324 < React . Fragment >
324- < div className = { fieldClassName } >
325+ < div className = { fieldClassName } ref = { this . fieldRef } >
325326 < input
326327 id = { 1 }
327328 role = { 'combobox' }
0 commit comments