@rolster/react-components 18.10.6 → 18.10.8

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
@@ -1279,16 +1279,14 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
1279
1279
  useEffect(() => filterSuggestions(pattern, true), [suggestions]);
1280
1280
  useEffect(() => filterSuggestions(pattern), [pattern]);
1281
1281
  useEffect(() => {
1282
- changeInternal
1283
- ? setChangeInternal(false)
1284
- : reset(collection, formControl?.state);
1282
+ changeInternal ? setChangeInternal(false) : resetState(formControl?.state);
1285
1283
  }, [formControl?.state]);
1286
- useEffect(() => reset(collection, formControl?.state), [collection]);
1284
+ useEffect(() => resetCollection(collection, formControl?.state), [collection]);
1287
1285
  function setFormState(value) {
1288
1286
  setChangeInternal(true);
1289
1287
  formControl?.setState(value);
1290
1288
  }
1291
- function reset(collection, state) {
1289
+ function resetCollection(collection, state) {
1292
1290
  if (state) {
1293
1291
  const element = collection.find(state);
1294
1292
  if (element) {
@@ -1296,13 +1294,15 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
1296
1294
  }
1297
1295
  else {
1298
1296
  setValue('');
1299
- setFormState(undefined);
1300
1297
  }
1301
1298
  }
1302
1299
  else {
1303
1300
  setValue('');
1304
1301
  }
1305
1302
  }
1303
+ function resetState(state) {
1304
+ setValue(state ? collection.find(state)?.description || '' : '');
1305
+ }
1306
1306
  function onClickControl() {
1307
1307
  if (!disabled) {
1308
1308
  setVisible(true);
@@ -1894,16 +1894,14 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1894
1894
  const { collection, inputRef, visible, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
1895
1895
  const [changeInternal, setChangeInternal] = useState(false);
1896
1896
  useEffect(() => {
1897
- changeInternal
1898
- ? setChangeInternal(false)
1899
- : reset(collection, formControl?.state);
1897
+ changeInternal ? setChangeInternal(false) : resetState(formControl?.state);
1900
1898
  }, [formControl?.state]);
1901
- useEffect(() => reset(collection, formControl?.state), [collection]);
1899
+ useEffect(() => resetCollection(collection, formControl?.state), [collection]);
1902
1900
  function setFormState(value) {
1903
1901
  setChangeInternal(true);
1904
1902
  formControl?.setState(value);
1905
1903
  }
1906
- function reset(collection, state) {
1904
+ function resetCollection(collection, state) {
1907
1905
  if (state) {
1908
1906
  const element = collection.find(state);
1909
1907
  if (element) {
@@ -1911,13 +1909,15 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1911
1909
  }
1912
1910
  else {
1913
1911
  setValue('');
1914
- setFormState(undefined);
1915
1912
  }
1916
1913
  }
1917
1914
  else {
1918
1915
  setValue('');
1919
1916
  }
1920
1917
  }
1918
+ function resetState(state) {
1919
+ setValue(state ? collection.find(state)?.description || '' : '');
1920
+ }
1921
1921
  function onFocusInput() {
1922
1922
  setFocused(true);
1923
1923
  }