@@ -17,6 +17,7 @@ class AutoComplete extends Component {
17
17
*/
18
18
this . state = {
19
19
data : props . data ,
20
+ // eslint-disable-next-line react/no-unused-state
20
21
prevProps : props . data ,
21
22
input : { [ `${ props . labelKey } ` ] : '' , [ `${ props . valueKey } ` ] : null } ,
22
23
showSuggestions : false ,
@@ -92,7 +93,7 @@ class AutoComplete extends Component {
92
93
// Hide the options dropdown menu and clear keyboard focused element.
93
94
hideSuggestions = ( ) => {
94
95
const { data, input, blockOnBlur } = this . state ;
95
- const { labelKey, valueKey } = this . props ;
96
+ const { labelKey, valueKey, data : propsData } = this . props ;
96
97
97
98
// Only if a valid option is typed then allow to remain without clicking
98
99
const matchedItem = data
@@ -108,6 +109,7 @@ class AutoComplete extends Component {
108
109
[ `${ labelKey } ` ] : '' ,
109
110
[ `${ valueKey } ` ] : null ,
110
111
} ,
112
+ data : propsData ,
111
113
} ) ;
112
114
}
113
115
@@ -222,7 +224,7 @@ class AutoComplete extends Component {
222
224
renderOptions = ( ) => {
223
225
const { theme, labelKey } = this . props ;
224
226
const { focus, data } = this . state ;
225
- return data
227
+ return data . length ? data
226
228
. map ( ( item , index ) => {
227
229
// Assign each item a class to customize
228
230
const classes = cx ( theme [ 'autocomplete-list-item' ] , {
@@ -245,7 +247,7 @@ class AutoComplete extends Component {
245
247
{ item [ `${ labelKey } ` ] }
246
248
</ div >
247
249
) ;
248
- } ) ;
250
+ } ) : 'No results found!' ;
249
251
} ;
250
252
251
253
render ( ) {
@@ -258,7 +260,9 @@ class AutoComplete extends Component {
258
260
valueKey,
259
261
...rest
260
262
} = this . props ;
261
- const { showSuggestions, focused, input } = this . state ;
263
+ const {
264
+ showSuggestions, focused, input,
265
+ } = this . state ;
262
266
const classes = cx ( className , theme . autocomplete ) ;
263
267
return (
264
268
< div className = { classes } >
0 commit comments