@rolster/react-components 18.10.6 → 18.10.7

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) {
@@ -1305,6 +1303,9 @@ function useAutocompleteField({ disabled, formControl, onSelect, onValue, sugges
1305
1303
  setValue('');
1306
1304
  }
1307
1305
  }
1306
+ function resetState(state) {
1307
+ setValue(state ? collection.find(state)?.description || '' : '');
1308
+ }
1308
1309
  function onClickControl() {
1309
1310
  if (!disabled) {
1310
1311
  setVisible(true);
@@ -1896,16 +1897,14 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1896
1897
  const { collection, inputRef, visible, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
1897
1898
  const [changeInternal, setChangeInternal] = react.useState(false);
1898
1899
  react.useEffect(() => {
1899
- changeInternal
1900
- ? setChangeInternal(false)
1901
- : reset(collection, formControl?.state);
1900
+ changeInternal ? setChangeInternal(false) : resetState(formControl?.state);
1902
1901
  }, [formControl?.state]);
1903
- react.useEffect(() => reset(collection, formControl?.state), [collection]);
1902
+ react.useEffect(() => resetCollection(collection, formControl?.state), [collection]);
1904
1903
  function setFormState(value) {
1905
1904
  setChangeInternal(true);
1906
1905
  formControl?.setState(value);
1907
1906
  }
1908
- function reset(collection, state) {
1907
+ function resetCollection(collection, state) {
1909
1908
  if (state) {
1910
1909
  const element = collection.find(state);
1911
1910
  if (element) {
@@ -1920,6 +1919,9 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1920
1919
  setValue('');
1921
1920
  }
1922
1921
  }
1922
+ function resetState(state) {
1923
+ setValue(state ? collection.find(state)?.description || '' : '');
1924
+ }
1923
1925
  function onFocusInput() {
1924
1926
  setFocused(true);
1925
1927
  }