@rolster/react-components 18.10.5 → 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/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,26 +1272,37 @@ 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 ? setChangeInternal(false) : resetState(formControl?.state);
1286
1283
  }, [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);
1284
+ useEffect(() => resetCollection(collection, formControl?.state), [collection]);
1285
+ function setFormState(value) {
1286
+ setChangeInternal(true);
1287
+ formControl?.setState(value);
1288
+ }
1289
+ function resetCollection(collection, state) {
1290
+ if (state) {
1291
+ const element = collection.find(state);
1292
+ if (element) {
1293
+ setValue(element.description);
1294
+ }
1295
+ else {
1296
+ setValue('');
1297
+ setFormState(undefined);
1298
+ }
1297
1299
  }
1300
+ else {
1301
+ setValue('');
1302
+ }
1303
+ }
1304
+ function resetState(state) {
1305
+ setValue(state ? collection.find(state)?.description || '' : '');
1298
1306
  }
1299
1307
  function onClickControl() {
1300
1308
  if (!disabled) {
@@ -1325,8 +1333,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1325
1333
  setVisible(false);
1326
1334
  setValue('');
1327
1335
  if (formControl) {
1328
- setChangeInternal(true);
1329
- formControl.setState(undefined);
1336
+ setFormState(undefined);
1330
1337
  }
1331
1338
  if (onValue) {
1332
1339
  onValue(undefined);
@@ -1359,8 +1366,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1359
1366
  }
1360
1367
  else {
1361
1368
  if (formControl) {
1362
- setChangeInternal(true);
1363
- formControl.setState(value);
1369
+ setFormState(value);
1364
1370
  }
1365
1371
  setValue(description);
1366
1372
  }
@@ -1414,7 +1420,6 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1414
1420
  return {
1415
1421
  coincidences,
1416
1422
  listControl,
1417
- pattern,
1418
1423
  onBlurInput,
1419
1424
  onClickAction,
1420
1425
  onClickBackdrop,
@@ -1423,6 +1428,7 @@ function useAutocompleteField({ suggestions, disabled, formControl, onSelect, on
1423
1428
  onFocusInput,
1424
1429
  onKeydownElement,
1425
1430
  onKeydownInput,
1431
+ pattern,
1426
1432
  setPattern
1427
1433
  };
1428
1434
  }
@@ -1886,22 +1892,33 @@ function RlsFormNavigation({ children, visible, rlsTheme }) {
1886
1892
 
1887
1893
  function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1888
1894
  const listControl = useListControl({ suggestions, formControl });
1889
- const { collection, inputRef, visible, setFocused, setValue, setVisible, navigationElement, navigationInput } = listControl;
1895
+ const { collection, inputRef, visible, navigationElement, navigationInput, setFocused, setValue, setVisible } = listControl;
1890
1896
  const [changeInternal, setChangeInternal] = useState(false);
1891
1897
  useEffect(() => {
1892
- changeInternal ? setChangeInternal(false) : resetState();
1898
+ changeInternal ? setChangeInternal(false) : resetState(formControl?.state);
1893
1899
  }, [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);
1900
+ useEffect(() => resetCollection(collection, formControl?.state), [collection]);
1901
+ function setFormState(value) {
1902
+ setChangeInternal(true);
1903
+ formControl?.setState(value);
1904
+ }
1905
+ function resetCollection(collection, state) {
1906
+ if (state) {
1907
+ const element = collection.find(state);
1908
+ if (element) {
1909
+ setValue(element.description);
1910
+ }
1911
+ else {
1912
+ setValue('');
1913
+ setFormState(undefined);
1914
+ }
1904
1915
  }
1916
+ else {
1917
+ setValue('');
1918
+ }
1919
+ }
1920
+ function resetState(state) {
1921
+ setValue(state ? collection.find(state)?.description || '' : '');
1905
1922
  }
1906
1923
  function onFocusInput() {
1907
1924
  setFocused(true);
@@ -1966,8 +1983,7 @@ function useSelectField({ suggestions, formControl, onSelect, onValue }) {
1966
1983
  }
1967
1984
  else {
1968
1985
  if (formControl) {
1969
- setChangeInternal(true);
1970
- formControl.setState(value);
1986
+ setFormState(value);
1971
1987
  }
1972
1988
  setValue(description);
1973
1989
  }