@homecode/ui 4.20.0 → 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.
- package/dist/esm/index.js +5 -0
- package/dist/esm/src/components/Autocomplete/Autocomplete.js +13 -2
- package/dist/esm/src/hooks/useDebounce.js +8 -0
- package/dist/esm/types/src/hooks/index.d.ts +5 -0
- package/dist/esm/types/src/hooks/useDebounce.d.ts +1 -0
- package/dist/esm/types/src/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -73,6 +73,11 @@ import * as resizeObserver from './src/tools/resizeObserver.js';
|
|
|
73
73
|
export { resizeObserver };
|
|
74
74
|
import * as queryParams from './src/tools/queryParams.js';
|
|
75
75
|
export { queryParams };
|
|
76
|
+
export { useDebounce } from './src/hooks/useDebounce.js';
|
|
77
|
+
import 'react';
|
|
78
|
+
export { useThrottle } from './src/hooks/useThrottle.js';
|
|
79
|
+
export { useIsMounted } from './src/hooks/useIsMounted.js';
|
|
80
|
+
export { useListKeyboardControl } from './src/hooks/useListKeyboardControl.js';
|
|
76
81
|
import * as Form_types from './src/components/Form/Form.types.js';
|
|
77
82
|
export { Form_types as FormTypes };
|
|
78
83
|
export { SubmitButtons } from './src/components/Form/SubmitButtons/SubmitButtons.js';
|
|
@@ -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)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useDebounce(fn: (...args: any[]) => void, delay: number): any;
|