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