@rolster/react-components 18.10.5 → 18.10.6

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
@@ -1125,7 +1125,7 @@ const ELEMENT_SIZE_REM = 4;
1125
1125
  const BASE_SIZE_PX = 16;
1126
1126
  const ELEMENT_SIZE_PX = BASE_SIZE_PX * ELEMENT_SIZE_REM;
1127
1127
  const MAZ_LIST_SIZE_PX = BASE_SIZE_PX * LIST_SIZE_REM;
1128
- function useListControl({ suggestions, formControl, withHigher = false }) {
1128
+ function useListControl({ suggestions, formControl, higher: withHigher = false }) {
1129
1129
  const boxContentRef = useRef(null);
1130
1130
  const listRef = useRef(null);
1131
1131
  const inputRef = useRef(null);
@@ -1217,10 +1217,7 @@ function useListControl({ suggestions, formControl, withHigher = false }) {
1217
1217
  setPositionElement(0);
1218
1218
  elements.item(0).focus();
1219
1219
  setTimeout(() => {
1220
- listRef?.current?.scroll({
1221
- top: 0,
1222
- behavior: 'smooth'
1223
- });
1220
+ listRef?.current?.scroll({ top: 0, behavior: 'smooth' });
1224
1221
  }, 100);
1225
1222
  }
1226
1223
  }
@@ -1252,19 +1249,19 @@ function useListControl({ suggestions, formControl, withHigher = false }) {
1252
1249
  higher,
1253
1250
  inputRef,
1254
1251
  listRef,
1255
- value,
1256
- visible,
1257
1252
  navigationElement,
1258
1253
  navigationInput,
1259
1254
  setFocused,
1260
1255
  setValue,
1261
- setVisible
1256
+ setVisible,
1257
+ value,
1258
+ visible
1262
1259
  };
1263
1260
  }
1264
1261
 
1265
1262
  const DURATION_ANIMATION$1 = 240;
1266
1263
  const MAX_ELEMENTS = 6;
1267
- function useAutocompleteField({ suggestions, disabled, formControl, onSelect, onValue }) {
1264
+ function useAutocompleteField({ disabled, formControl, onSelect, onValue, suggestions }) {
1268
1265
  const [pattern, setPattern] = useState('');
1269
1266
  const [coincidences, setCoincidences] = useState([]);
1270
1267
  const [store, setStore] = useState({
@@ -1275,25 +1272,35 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1275
1272
  const listControl = useListControl({
1276
1273
  suggestions,
1277
1274
  formControl,
1278
- withHigher: true
1275
+ higher: true
1279
1276
  });
1280
- const { collection, inputRef, setFocused, setValue, setVisible, navigationElement, navigationInput } = listControl;
1277
+ const { collection, inputRef, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
1281
1278
  const [changeInternal, setChangeInternal] = useState(false);
1282
1279
  useEffect(() => filterSuggestions(pattern, true), [suggestions]);
1283
1280
  useEffect(() => filterSuggestions(pattern), [pattern]);
1284
1281
  useEffect(() => {
1285
- changeInternal ? setChangeInternal(false) : resetState();
1282
+ changeInternal
1283
+ ? setChangeInternal(false)
1284
+ : reset(collection, formControl?.state);
1286
1285
  }, [formControl?.state]);
1287
- useEffect(() => resetState(), [collection]);
1288
- function requestCurrentElement() {
1289
- return formControl?.state && collection.find(formControl.state);
1290
- }
1291
- function resetState() {
1292
- const element = requestCurrentElement();
1293
- setValue(element?.description || '');
1294
- if (!element) {
1295
- setChangeInternal(true);
1296
- formControl?.setState(undefined);
1286
+ useEffect(() => reset(collection, formControl?.state), [collection]);
1287
+ function setFormState(value) {
1288
+ setChangeInternal(true);
1289
+ formControl?.setState(value);
1290
+ }
1291
+ function reset(collection, state) {
1292
+ if (state) {
1293
+ const element = collection.find(state);
1294
+ if (element) {
1295
+ setValue(element.description);
1296
+ }
1297
+ else {
1298
+ setValue('');
1299
+ setFormState(undefined);
1300
+ }
1301
+ }
1302
+ else {
1303
+ setValue('');
1297
1304
  }
1298
1305
  }
1299
1306
  function onClickControl() {
@@ -1325,8 +1332,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1325
1332
  setVisible(false);
1326
1333
  setValue('');
1327
1334
  if (formControl) {
1328
- setChangeInternal(true);
1329
- formControl.setState(undefined);
1335
+ setFormState(undefined);
1330
1336
  }
1331
1337
  if (onValue) {
1332
1338
  onValue(undefined);
@@ -1359,8 +1365,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1359
1365
  }
1360
1366
  else {
1361
1367
  if (formControl) {
1362
- setChangeInternal(true);
1363
- formControl.setState(value);
1368
+ setFormState(value);
1364
1369
  }
1365
1370
  setValue(description);
1366
1371
  }
@@ -1414,7 +1419,6 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1414
1419
  return {
1415
1420
  coincidences,
1416
1421
  listControl,
1417
- pattern,
1418
1422
  onBlurInput,
1419
1423
  onClickAction,
1420
1424
  onClickBackdrop,
@@ -1423,6 +1427,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1423
1427
  onFocusInput,
1424
1428
  onKeydownElement,
1425
1429
  onKeydownInput,
1430
+ pattern,
1426
1431
  setPattern
1427
1432
  };
1428
1433
  }
@@ -1886,21 +1891,31 @@ function RlsFormNavigation({ children, visible, rlsTheme }) {
1886
1891
 
1887
1892
  function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1888
1893
  const listControl = useListControl({ suggestions, formControl });
1889
- const { collection, inputRef, visible, setFocused, setValue, setVisible, navigationElement, navigationInput } = listControl;
1894
+ const { collection, inputRef, visible, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
1890
1895
  const [changeInternal, setChangeInternal] = useState(false);
1891
1896
  useEffect(() => {
1892
- changeInternal ? setChangeInternal(false) : resetState();
1897
+ changeInternal
1898
+ ? setChangeInternal(false)
1899
+ : reset(collection, formControl?.state);
1893
1900
  }, [formControl?.state]);
1894
- useEffect(() => resetState(), [collection]);
1895
- function requestCurrentElement() {
1896
- return formControl?.state && collection.find(formControl.state);
1897
- }
1898
- function resetState() {
1899
- const element = requestCurrentElement();
1900
- setValue(element?.description || '');
1901
- if (!element) {
1902
- setChangeInternal(true);
1903
- formControl?.setState(undefined);
1901
+ useEffect(() => reset(collection, formControl?.state), [collection]);
1902
+ function setFormState(value) {
1903
+ setChangeInternal(true);
1904
+ formControl?.setState(value);
1905
+ }
1906
+ function reset(collection, state) {
1907
+ if (state) {
1908
+ const element = collection.find(state);
1909
+ if (element) {
1910
+ setValue(element.description);
1911
+ }
1912
+ else {
1913
+ setValue('');
1914
+ setFormState(undefined);
1915
+ }
1916
+ }
1917
+ else {
1918
+ setValue('');
1904
1919
  }
1905
1920
  }
1906
1921
  function onFocusInput() {
@@ -1966,8 +1981,7 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1966
1981
  }
1967
1982
  else {
1968
1983
  if (formControl) {
1969
- setChangeInternal(true);
1970
- formControl.setState(value);
1984
+ setFormState(value);
1971
1985
  }
1972
1986
  setValue(description);
1973
1987
  }