@rolster/react-components 18.15.11 → 18.15.13

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/es/index.js CHANGED
@@ -2073,7 +2073,6 @@ function useListControl({ suggestions, formControl }) {
2073
2073
  });
2074
2074
  const collection = useRef(new ListCollection([]));
2075
2075
  const position = useRef(0);
2076
- const changeInternal = useRef(false);
2077
2076
  const protectedValue = useRef();
2078
2077
  useEffect(() => {
2079
2078
  function onCloseSuggestions({ target }) {
@@ -2086,35 +2085,29 @@ function useListControl({ suggestions, formControl }) {
2086
2085
  };
2087
2086
  }, []);
2088
2087
  useEffect(() => {
2089
- formControl?.touch();
2088
+ state.visible && formControl?.touch();
2090
2089
  setState((state) => ({
2091
2090
  ...state,
2092
2091
  higher: locationListCanTop(contentRef.current, listRef.current)
2093
2092
  }));
2094
2093
  }, [state.visible]);
2095
- useEffect(() => {
2096
- if (!changeInternal.current) {
2097
- changeInternal.current = false;
2098
- return;
2099
- }
2100
- refresh(collection.current, formControl?.value);
2101
- }, [formControl?.value]);
2102
2094
  useEffect(() => {
2103
2095
  collection.current = new ListCollection(suggestions);
2104
2096
  refresh(collection.current, formControl?.value);
2105
- }, [suggestions]);
2097
+ }, [suggestions, formControl?.value]);
2106
2098
  function refresh(collection, state) {
2107
2099
  if (!state) {
2108
2100
  return refreshProtected(collection) ? undefined : setValue('');
2109
2101
  }
2110
2102
  const element = collection.find(state);
2111
2103
  if (element) {
2104
+ protectedValue.current = undefined;
2112
2105
  return setValue(element.description);
2113
2106
  }
2114
2107
  if (!refreshProtected(collection)) {
2115
2108
  protectedValue.current = state;
2116
2109
  setValue('');
2117
- setFormState(undefined);
2110
+ setFormValue(undefined);
2118
2111
  }
2119
2112
  }
2120
2113
  function refreshProtected(collection) {
@@ -2134,11 +2127,8 @@ function useListControl({ suggestions, formControl }) {
2134
2127
  function setValue(value) {
2135
2128
  setState((state) => ({ ...state, value }));
2136
2129
  }
2137
- function setFormState(value) {
2138
- if (formControl) {
2139
- changeInternal.current = true;
2140
- formControl.setValue(value);
2141
- }
2130
+ function setFormValue(value) {
2131
+ formControl?.setValue(value);
2142
2132
  }
2143
2133
  function setVisible(visible) {
2144
2134
  setState((state) => ({ ...state, visible }));
@@ -2150,7 +2140,7 @@ function useListControl({ suggestions, formControl }) {
2150
2140
  event: event,
2151
2141
  list: listRef.current
2152
2142
  });
2153
- position.current = newPosition || 0;
2143
+ position.current = newPosition ?? 0;
2154
2144
  }
2155
2145
  }
2156
2146
  function navigationElement(event) {
@@ -2170,7 +2160,7 @@ function useListControl({ suggestions, formControl }) {
2170
2160
  navigationElement,
2171
2161
  navigationInput,
2172
2162
  setFocused,
2173
- setFormState,
2163
+ setFormValue,
2174
2164
  setValue,
2175
2165
  setVisible
2176
2166
  };
@@ -2187,7 +2177,7 @@ function useFieldAutocomplete({ disabled, formControl, onSelect, onValue, sugges
2187
2177
  previous: null
2188
2178
  });
2189
2179
  const listControl = useListControl({ suggestions, formControl });
2190
- const { inputRef, navigationElement, navigationInput, setFocused, setFormState, setValue, setVisible } = listControl;
2180
+ const { inputRef, navigationElement, navigationInput, setFocused, setFormValue, setValue, setVisible } = listControl;
2191
2181
  useEffect(() => {
2192
2182
  refreshCoincidences(pattern, true);
2193
2183
  }, [suggestions]);
@@ -2222,7 +2212,7 @@ function useFieldAutocomplete({ disabled, formControl, onSelect, onValue, sugges
2222
2212
  function onClickAction() {
2223
2213
  setVisible(false);
2224
2214
  setValue('');
2225
- setFormState(undefined);
2215
+ setFormValue(undefined);
2226
2216
  onValue && onValue(undefined);
2227
2217
  }
2228
2218
  function onClickBackdrop() {
@@ -2244,7 +2234,7 @@ function useFieldAutocomplete({ disabled, formControl, onSelect, onValue, sugges
2244
2234
  onSelect(value);
2245
2235
  }
2246
2236
  else {
2247
- setFormState(value);
2237
+ setFormValue(value);
2248
2238
  setValue(description);
2249
2239
  }
2250
2240
  onValue && onValue(value);
@@ -2491,7 +2481,7 @@ function RlsFieldDateRange({ children, date: datePicker, disabled, formControl,
2491
2481
 
2492
2482
  function useFieldSelect({ suggestions, formControl, onSelect, onValue }) {
2493
2483
  const listControl = useListControl({ suggestions, formControl });
2494
- const { inputRef, visible, navigationElement, navigationInput, setFocused, setFormState, setValue, setVisible } = listControl;
2484
+ const { inputRef, visible, navigationElement, navigationInput, setFocused, setFormValue, setValue, setVisible } = listControl;
2495
2485
  function onFocusInput() {
2496
2486
  setFocused(true);
2497
2487
  }
@@ -2540,7 +2530,7 @@ function useFieldSelect({ suggestions, formControl, onSelect, onValue }) {
2540
2530
  onSelect(value);
2541
2531
  }
2542
2532
  else {
2543
- setFormState(value);
2533
+ setFormValue(value);
2544
2534
  setValue(description);
2545
2535
  }
2546
2536
  onValue && onValue(value);