@homecode/ui 4.20.1 → 4.20.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -59,9 +59,14 @@ import '../Virtualized/List/ListScroll.styl.js';
|
|
|
59
59
|
function Autocomplete(props) {
|
|
60
60
|
const { className, inputWrapperClassName, value, onChange, size = 'm', getOptions, onSelect, debounceDelay = 300, inputProps = {}, popupProps = {}, } = props;
|
|
61
61
|
const isMounted = useIsMounted();
|
|
62
|
-
const [searchValue, setSearchValue] = useState(value);
|
|
63
62
|
const [options, setOptions] = useState([]);
|
|
64
63
|
const [isLoading, setIsLoading] = useState(false);
|
|
64
|
+
const searchValRef = useRef(value);
|
|
65
|
+
const [searchValue, _setSearchValue] = useState(value);
|
|
66
|
+
const setSearchValue = (val) => {
|
|
67
|
+
searchValRef.current = val;
|
|
68
|
+
_setSearchValue(val);
|
|
69
|
+
};
|
|
65
70
|
const currentRequest = useRef('');
|
|
66
71
|
// @ts-ignore
|
|
67
72
|
const inputRef = useRef(null);
|
|
@@ -118,7 +123,13 @@ function Autocomplete(props) {
|
|
|
118
123
|
}
|
|
119
124
|
}, debounceDelay);
|
|
120
125
|
useEffect(() => {
|
|
121
|
-
|
|
126
|
+
if (value !== searchValRef.current) {
|
|
127
|
+
if (isOpen)
|
|
128
|
+
fetchOptions(value);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
setSearchValue(value);
|
|
132
|
+
}
|
|
122
133
|
}, [value]);
|
|
123
134
|
const optionsList = useMemo(() => {
|
|
124
135
|
if (!options.length)
|