@@ -7,7 +7,7 @@ import CloseIcon from '@material-ui/icons/Close';
77import SearchIcon from '@material-ui/icons/Search' ;
88import Downshift from 'downshift' ;
99import _isNil from 'ramda/src/isNil' ;
10- import React , { useState } from 'react' ;
10+ import React , { useRef , useState } from 'react' ;
1111import { useDispatch , useSelector } from 'react-redux' ;
1212import { useHistory } from 'react-router-dom' ;
1313import { autocompleteRequested } from '../../redux/autocomplete/actionCreators' ;
@@ -111,13 +111,14 @@ interface Options {
111111 readonly type : AutocompleteType ;
112112}
113113
114+ const POPPER_OFFSET = 4 ;
115+
114116const Autocomplete = ( { id, type } : Options ) => {
115117 const classes = useStyles ( ) ;
116118
117119 const additionalOptions = autocompleteOptions [ type ] ;
118120
119- // TODO: explore useRef, fix popper width
120- let popperNode : any ;
121+ const popperNode : any = useRef ( { } ) ;
121122
122123 const [ value , setValue ] = useState ( '' ) ;
123124 const history = useHistory ( ) ;
@@ -141,7 +142,8 @@ const Autocomplete = ({ id, type }: Options) => {
141142 const link =
142143 item . type === 'course'
143144 ? `/courses/${ item . slug } `
144- : `/instructors/${ item . email } ` ;
145+ // TODO: create username property as uniq db field
146+ : `/instructors/${ String ( item . firstName + item . lastName ) . toLowerCase ( ) } ` ;
145147 setValue ( '' ) ;
146148 history . push ( link ) ;
147149 } else if ( changes . hasOwnProperty ( 'inputValue' ) ) {
@@ -179,16 +181,14 @@ const Autocomplete = ({ id, type }: Options) => {
179181 classes,
180182 fullWidth : true ,
181183 inputProps,
182- ref : ( node : any ) => {
183- popperNode = node ;
184- } ,
184+ ref : popperNode
185185 } ) }
186186 { String ( inputProps . value ) . length > 0 && (
187187 < div className = { [ classes . icon , classes . closeIcon ] . join ( ' ' ) } >
188188 < CloseIcon onClick = { clearSelection as any } />
189189 </ div >
190190 ) }
191- < Popper open = { isOpen } anchorEl = { popperNode } >
191+ < Popper open = { isOpen } anchorEl = { popperNode . current } disablePortal >
192192 < div
193193 { ...( isOpen
194194 ? getMenuProps ( { } , { suppressRefError : true } )
@@ -197,8 +197,8 @@ const Autocomplete = ({ id, type }: Options) => {
197197 < Paper
198198 square
199199 style = { {
200- marginTop : 8 ,
201- width : popperNode ? popperNode . clientWidth : undefined ,
200+ marginTop : '4px' ,
201+ width : popperNode . current && popperNode . current . clientWidth ? popperNode . current . clientWidth - POPPER_OFFSET : undefined ,
202202 } }
203203 >
204204 { results . map ( ( suggestion : any , index : number ) =>
0 commit comments