Skip to content

Commit f667c53

Browse files
committed
fix(autocomplete): minor fixes
fix breaking tests, add message when no matching results and fix list update after blur
1 parent 49cdf3c commit f667c53

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/autocomplete/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class AutoComplete extends Component {
1717
*/
1818
this.state = {
1919
data: props.data,
20+
// eslint-disable-next-line react/no-unused-state
2021
prevProps: props.data,
2122
input: { [`${props.labelKey}`]: '', [`${props.valueKey}`]: null },
2223
showSuggestions: false,
@@ -92,7 +93,7 @@ class AutoComplete extends Component {
9293
// Hide the options dropdown menu and clear keyboard focused element.
9394
hideSuggestions = () => {
9495
const { data, input, blockOnBlur } = this.state;
95-
const { labelKey, valueKey } = this.props;
96+
const { labelKey, valueKey, data: propsData } = this.props;
9697

9798
// Only if a valid option is typed then allow to remain without clicking
9899
const matchedItem = data
@@ -108,6 +109,7 @@ class AutoComplete extends Component {
108109
[`${labelKey}`]: '',
109110
[`${valueKey}`]: null,
110111
},
112+
data: propsData,
111113
});
112114
}
113115

@@ -222,7 +224,7 @@ class AutoComplete extends Component {
222224
renderOptions = () => {
223225
const { theme, labelKey } = this.props;
224226
const { focus, data } = this.state;
225-
return data
227+
return data.length ? data
226228
.map((item, index) => {
227229
// Assign each item a class to customize
228230
const classes = cx(theme['autocomplete-list-item'], {
@@ -245,7 +247,7 @@ class AutoComplete extends Component {
245247
{item[`${labelKey}`]}
246248
</div>
247249
);
248-
});
250+
}) : 'No results found!';
249251
};
250252

251253
render() {
@@ -258,7 +260,9 @@ class AutoComplete extends Component {
258260
valueKey,
259261
...rest
260262
} = this.props;
261-
const { showSuggestions, focused, input } = this.state;
263+
const {
264+
showSuggestions, focused, input,
265+
} = this.state;
262266
const classes = cx(className, theme.autocomplete);
263267
return (
264268
<div className={classes}>

lib/autocomplete/theme.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
box-sizing: border-box;
3131
height: fit-content;
3232
height: -moz-fit-content;
33+
text-align: center;
3334
max-height: 300px;
3435
width: 100%;
3536
overflow-y: auto;

0 commit comments

Comments
 (0)