11import React , { Component } from 'react' ;
22import PropTypes from 'prop-types' ;
33import shallowEqualArrays from 'shallow-equal/arrays' ;
4- import Autowhatever from 'react-autowhatever ' ;
4+ import Autowhatever from './Autowhatever ' ;
55import { defaultTheme , mapToAutowhateverTheme } from './theme' ;
66
77const alwaysTrue = ( ) => true ;
8- const defaultShouldRenderSuggestions = value => value . trim ( ) . length > 0 ;
8+ const defaultShouldRenderSuggestions = ( value ) => value . trim ( ) . length > 0 ;
99const defaultRenderSuggestionsContainer = ( { containerProps, children } ) => (
1010 < div { ...containerProps } > { children } </ div >
1111) ;
@@ -81,7 +81,7 @@ export default class Autosuggest extends Component {
8181 focusInputOnSuggestionClick : PropTypes . bool ,
8282 highlightFirstSuggestion : PropTypes . bool ,
8383 theme : PropTypes . object ,
84- id : PropTypes . string
84+ id : PropTypes . string ,
8585 } ;
8686
8787 static defaultProps = {
@@ -92,7 +92,7 @@ export default class Autosuggest extends Component {
9292 focusInputOnSuggestionClick : true ,
9393 highlightFirstSuggestion : false ,
9494 theme : defaultTheme ,
95- id : '1'
95+ id : '1' ,
9696 } ;
9797
9898 constructor ( { alwaysRenderSuggestions } ) {
@@ -104,7 +104,7 @@ export default class Autosuggest extends Component {
104104 highlightedSectionIndex : null ,
105105 highlightedSuggestionIndex : null ,
106106 highlightedSuggestion : null ,
107- valueBeforeUpDown : null
107+ valueBeforeUpDown : null ,
108108 } ;
109109
110110 this . justPressedUpDown = false ;
@@ -147,7 +147,7 @@ export default class Autosuggest extends Component {
147147 const {
148148 suggestions,
149149 onSuggestionHighlighted,
150- highlightFirstSuggestion
150+ highlightFirstSuggestion,
151151 } = this . props ;
152152
153153 if (
@@ -165,7 +165,7 @@ export default class Autosuggest extends Component {
165165
166166 if ( highlightedSuggestion != prevHighlightedSuggestion ) {
167167 onSuggestionHighlighted ( {
168- suggestion : highlightedSuggestion
168+ suggestion : highlightedSuggestion ,
169169 } ) ;
170170 }
171171 }
@@ -177,7 +177,7 @@ export default class Autosuggest extends Component {
177177 }
178178
179179 updateHighlightedSuggestion ( sectionIndex , suggestionIndex , prevValue ) {
180- this . setState ( state => {
180+ this . setState ( ( state ) => {
181181 let { valueBeforeUpDown } = state ;
182182
183183 if ( suggestionIndex === null ) {
@@ -196,13 +196,13 @@ export default class Autosuggest extends Component {
196196 suggestionIndex === null
197197 ? null
198198 : this . getSuggestion ( sectionIndex , suggestionIndex ) ,
199- valueBeforeUpDown
199+ valueBeforeUpDown,
200200 } ;
201201 } ) ;
202202 }
203203
204204 resetHighlightedSuggestion ( shouldResetValueBeforeUpDown = true ) {
205- this . setState ( state => {
205+ this . setState ( ( state ) => {
206206 const { valueBeforeUpDown } = state ;
207207
208208 return {
@@ -211,14 +211,14 @@ export default class Autosuggest extends Component {
211211 highlightedSuggestion : null ,
212212 valueBeforeUpDown : shouldResetValueBeforeUpDown
213213 ? null
214- : valueBeforeUpDown
214+ : valueBeforeUpDown ,
215215 } ;
216216 } ) ;
217217 }
218218
219219 revealSuggestions ( ) {
220220 this . setState ( {
221- isCollapsed : false
221+ isCollapsed : false ,
222222 } ) ;
223223 }
224224
@@ -228,7 +228,7 @@ export default class Autosuggest extends Component {
228228 highlightedSuggestionIndex : null ,
229229 highlightedSuggestion : null ,
230230 valueBeforeUpDown : null ,
231- isCollapsed : true
231+ isCollapsed : true ,
232232 } ) ;
233233 }
234234
@@ -272,11 +272,11 @@ export default class Autosuggest extends Component {
272272 return {
273273 sectionIndex :
274274 typeof sectionIndex === 'string' ? parseInt ( sectionIndex , 10 ) : null ,
275- suggestionIndex : parseInt ( suggestionIndex , 10 )
275+ suggestionIndex : parseInt ( suggestionIndex , 10 ) ,
276276 } ;
277277 }
278278
279- onDocumentMouseDown = event => {
279+ onDocumentMouseDown = ( event ) => {
280280 this . justClickedOnSuggestionsContainer = false ;
281281
282282 let node =
@@ -335,7 +335,7 @@ export default class Autosuggest extends Component {
335335 return suggestions . length > 0 && shouldRenderSuggestions ( value ) ;
336336 }
337337
338- storeAutowhateverRef = autowhatever => {
338+ storeAutowhateverRef = ( autowhatever ) => {
339339 if ( autowhatever !== null ) {
340340 this . autowhatever = autowhatever ;
341341 }
@@ -366,7 +366,7 @@ export default class Autosuggest extends Component {
366366 this . pressedSuggestion = null ;
367367 } ;
368368
369- onSuggestionMouseDown = event => {
369+ onSuggestionMouseDown = ( event ) => {
370370 // Checking if this.justSelectedSuggestion is already true to not duplicate touch events in chrome
371371 // See: https://github.com/facebook/react/issues/9809#issuecomment-413978405
372372 if ( ! this . justSelectedSuggestion ) {
@@ -385,15 +385,15 @@ export default class Autosuggest extends Component {
385385 const {
386386 alwaysRenderSuggestions,
387387 onSuggestionSelected,
388- onSuggestionsFetchRequested
388+ onSuggestionsFetchRequested,
389389 } = this . props ;
390390
391391 onSuggestionSelected && onSuggestionSelected ( event , data ) ;
392392
393393 if ( alwaysRenderSuggestions ) {
394394 onSuggestionsFetchRequested ( {
395395 value : data . suggestionValue ,
396- reason : 'suggestion-selected'
396+ reason : 'suggestion-selected' ,
397397 } ) ;
398398 } else {
399399 this . onSuggestionsClearRequested ( ) ;
@@ -402,7 +402,7 @@ export default class Autosuggest extends Component {
402402 this . resetHighlightedSuggestion ( ) ;
403403 } ;
404404
405- onSuggestionClick = event => {
405+ onSuggestionClick = ( event ) => {
406406 const { alwaysRenderSuggestions, focusInputOnSuggestionClick } = this . props ;
407407 const { sectionIndex, suggestionIndex } = this . getSuggestionIndices (
408408 this . findSuggestionElement ( event . target )
@@ -418,7 +418,7 @@ export default class Autosuggest extends Component {
418418 suggestionValue : clickedSuggestionValue ,
419419 suggestionIndex : suggestionIndex ,
420420 sectionIndex,
421- method : 'click'
421+ method : 'click' ,
422422 } ) ;
423423
424424 if ( ! alwaysRenderSuggestions ) {
@@ -448,13 +448,13 @@ export default class Autosuggest extends Component {
448448 highlightedSuggestionIndex : null ,
449449 highlightedSuggestion : null ,
450450 valueBeforeUpDown : null ,
451- isCollapsed : ! shouldRender
451+ isCollapsed : ! shouldRender ,
452452 } ) ;
453453
454454 onBlur && onBlur ( this . blurEvent , { highlightedSuggestion } ) ;
455455 } ;
456456
457- onSuggestionMouseLeave = event => {
457+ onSuggestionMouseLeave = ( event ) => {
458458 this . resetHighlightedSuggestion ( false ) ; // shouldResetValueBeforeUpDown
459459
460460 if (
@@ -486,7 +486,7 @@ export default class Autosuggest extends Component {
486486 onMouseDown : this . onSuggestionMouseDown ,
487487 onTouchStart : this . onSuggestionTouchStart ,
488488 onTouchMove : this . onSuggestionTouchMove ,
489- onClick : this . onSuggestionClick
489+ onClick : this . onSuggestionClick ,
490490 } ;
491491 } ;
492492
@@ -504,7 +504,7 @@ export default class Autosuggest extends Component {
504504 return renderSuggestionsContainer ( {
505505 containerProps,
506506 children,
507- query : this . getQuery ( )
507+ query : this . getQuery ( ) ,
508508 } ) ;
509509 } ;
510510
@@ -522,14 +522,14 @@ export default class Autosuggest extends Component {
522522 theme,
523523 getSuggestionValue,
524524 alwaysRenderSuggestions,
525- highlightFirstSuggestion
525+ highlightFirstSuggestion,
526526 } = this . props ;
527527 const {
528528 isFocused,
529529 isCollapsed,
530530 highlightedSectionIndex,
531531 highlightedSuggestionIndex,
532- valueBeforeUpDown
532+ valueBeforeUpDown,
533533 } = this . state ;
534534 const shouldRenderSuggestions = alwaysRenderSuggestions
535535 ? alwaysTrue
@@ -542,7 +542,7 @@ export default class Autosuggest extends Component {
542542 const items = isOpen ? suggestions : [ ] ;
543543 const autowhateverInputProps = {
544544 ...inputProps ,
545- onFocus : event => {
545+ onFocus : ( event ) => {
546546 if (
547547 ! this . justSelectedSuggestion &&
548548 ! this . justClickedOnSuggestionsContainer
@@ -551,7 +551,7 @@ export default class Autosuggest extends Component {
551551
552552 this . setState ( {
553553 isFocused : true ,
554- isCollapsed : ! shouldRender
554+ isCollapsed : ! shouldRender ,
555555 } ) ;
556556
557557 onFocus && onFocus ( event ) ;
@@ -561,7 +561,7 @@ export default class Autosuggest extends Component {
561561 }
562562 }
563563 } ,
564- onBlur : event => {
564+ onBlur : ( event ) => {
565565 if ( this . justClickedOnSuggestionsContainer ) {
566566 this . input . focus ( ) ;
567567 return ;
@@ -574,7 +574,7 @@ export default class Autosuggest extends Component {
574574 this . onSuggestionsClearRequested ( ) ;
575575 }
576576 } ,
577- onChange : event => {
577+ onChange : ( event ) => {
578578 const { value } = event . target ;
579579 const shouldRender = shouldRenderSuggestions ( value ) ;
580580
@@ -590,10 +590,10 @@ export default class Autosuggest extends Component {
590590 : {
591591 highlightedSectionIndex : null ,
592592 highlightedSuggestionIndex : null ,
593- highlightedSuggestion : null
593+ highlightedSuggestion : null ,
594594 } ) ,
595595 valueBeforeUpDown : null ,
596- isCollapsed : ! shouldRender
596+ isCollapsed : ! shouldRender ,
597597 } ) ;
598598
599599 if ( shouldRender ) {
@@ -612,14 +612,14 @@ export default class Autosuggest extends Component {
612612 if ( shouldRenderSuggestions ( value ) ) {
613613 onSuggestionsFetchRequested ( {
614614 value,
615- reason : 'suggestions-revealed'
615+ reason : 'suggestions-revealed' ,
616616 } ) ;
617617 this . revealSuggestions ( ) ;
618618 }
619619 } else if ( suggestions . length > 0 ) {
620620 const {
621621 newHighlightedSectionIndex,
622- newHighlightedItemIndex
622+ newHighlightedItemIndex,
623623 } = data ;
624624
625625 let newValue ;
@@ -682,7 +682,7 @@ export default class Autosuggest extends Component {
682682 suggestionValue : newValue ,
683683 suggestionIndex : highlightedSuggestionIndex ,
684684 sectionIndex : highlightedSectionIndex ,
685- method : 'enter'
685+ method : 'enter' ,
686686 } ) ;
687687
688688 this . justSelectedSuggestion = true ;
@@ -717,7 +717,7 @@ export default class Autosuggest extends Component {
717717 if ( shouldRenderSuggestions ( newValue ) ) {
718718 onSuggestionsFetchRequested ( {
719719 value : newValue ,
720- reason : 'escape-pressed'
720+ reason : 'escape-pressed' ,
721721 } ) ;
722722 } else {
723723 this . onSuggestionsClearRequested ( ) ;
@@ -740,10 +740,10 @@ export default class Autosuggest extends Component {
740740 }
741741
742742 onKeyDown && onKeyDown ( event ) ;
743- }
743+ } ,
744744 } ;
745745 const renderSuggestionData = {
746- query : this . getQuery ( )
746+ query : this . getQuery ( ) ,
747747 } ;
748748
749749 return (
0 commit comments