@homecode/ui 4.20.1 → 4.20.3

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,14 +59,29 @@ 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 isFocusedRef = useRef(false);
65
+ const searchValRef = useRef(value);
66
+ const [searchValue, _setSearchValue] = useState(value);
67
+ const setSearchValue = (val) => {
68
+ searchValRef.current = val;
69
+ _setSearchValue(val);
70
+ };
65
71
  const currentRequest = useRef('');
66
72
  // @ts-ignore
67
73
  const inputRef = useRef(null);
68
74
  const isOpen = options.length > 0;
69
75
  const classes = cn(S.root, className);
76
+ const handleFocus = (e) => {
77
+ isFocusedRef.current = true;
78
+ fetchOptions(searchValue);
79
+ inputProps?.onFocus?.(e);
80
+ };
81
+ const handleBlur = (e) => {
82
+ isFocusedRef.current = false;
83
+ inputProps?.onBlur?.(e);
84
+ };
70
85
  const handleInputChange = (e, value) => {
71
86
  const val = (value || e?.target.value) ?? '';
72
87
  setOptions([]);
@@ -119,6 +134,9 @@ function Autocomplete(props) {
119
134
  }, debounceDelay);
120
135
  useEffect(() => {
121
136
  setSearchValue(value);
137
+ setOptions([]);
138
+ if (isFocusedRef.current || isOpen)
139
+ fetchOptions(value);
122
140
  }, [value]);
123
141
  const optionsList = useMemo(() => {
124
142
  if (!options.length)
@@ -127,7 +145,7 @@ function Autocomplete(props) {
127
145
  }, [options, focusedIndex]);
128
146
  return (jsx(Popup, { className: classes, isOpen: isOpen, focusControl: true, size: size, direction: "bottom", ...popupProps, trigger: jsxs("div", { className: inputWrapperClassName, children: [jsx(Input, { ref: inputRef,
129
147
  // @ts-ignore
130
- size: size, ...inputProps, value: searchValue, onChange: handleInputChange, className: inputProps.className }), isLoading && (jsx(Shimmer, { className: S.shimmer, size: size, round: inputProps?.round }))] }), content: optionsList, contentProps: {
148
+ size: size, ...inputProps, value: searchValue, onChange: handleInputChange, onFocus: handleFocus, onBlur: handleBlur, className: inputProps.className }), isLoading && (jsx(Shimmer, { className: S.shimmer, size: size, round: inputProps?.round }))] }), content: optionsList, contentProps: {
131
149
  className: S.popupContent,
132
150
  } }));
133
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "4.20.1",
3
+ "version": "4.20.3",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "test": "jest",