@oliasoft-open-source/react-ui-library 4.15.1 → 4.15.2-beta-1

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/index.js CHANGED
@@ -20651,10 +20651,15 @@ const Layer = ({
20651
20651
  closeLayer,
20652
20652
  testId
20653
20653
  }) => {
20654
+ const isMounted = useRef(true);
20654
20655
  useEffect(() => {
20655
- if (firstSelectedOptionIndex && firstSelectedOptionIndex !== null && listRef.current !== null) {
20656
+ if (!isMounted.current) return;
20657
+ if (firstSelectedOptionIndex !== void 0 && firstSelectedOptionIndex !== null && listRef.current !== null && typeof listRef.current.scrollToItem === "function") {
20656
20658
  listRef.current.scrollToItem(firstSelectedOptionIndex, "start");
20657
20659
  }
20660
+ return () => {
20661
+ isMounted.current = false;
20662
+ };
20658
20663
  }, [firstSelectedOptionIndex, listRef]);
20659
20664
  const optionHeight = small2 ? 24 : 30;
20660
20665
  return /* @__PURE__ */ jsx(
@@ -20762,6 +20767,12 @@ const MultiSelectedOptions = ({
20762
20767
  const isFontLoaded = useFontsReady();
20763
20768
  const [displayedOptions, setDisplayedOptions] = useState([]);
20764
20769
  const [overflowOptions, setOverflowOptions] = useState([]);
20770
+ const isMounted = useRef(true);
20771
+ useEffect(() => {
20772
+ return () => {
20773
+ isMounted.current = false;
20774
+ };
20775
+ }, []);
20765
20776
  useEffect(() => {
20766
20777
  let displayed = [];
20767
20778
  let overflow = [];
@@ -20776,8 +20787,10 @@ const MultiSelectedOptions = ({
20776
20787
  overflow.push(option2);
20777
20788
  }
20778
20789
  });
20779
- setDisplayedOptions(displayed);
20780
- setOverflowOptions(overflow);
20790
+ if (isMounted.current) {
20791
+ setDisplayedOptions(displayed);
20792
+ setOverflowOptions(overflow);
20793
+ }
20781
20794
  }, [selectedOptions, isFontLoaded, width2]);
20782
20795
  return /* @__PURE__ */ jsxs(
20783
20796
  "div",
@@ -20820,6 +20833,12 @@ const Input = ({
20820
20833
  testId
20821
20834
  }) => {
20822
20835
  const containerRef = useRef(null);
20836
+ const isMounted = useRef(true);
20837
+ useEffect(() => {
20838
+ return () => {
20839
+ isMounted.current = false;
20840
+ };
20841
+ }, []);
20823
20842
  const isMulti2 = Array.isArray(selectedOptions);
20824
20843
  const hasSelectedValues = isMulti2 ? selectedOptions.length > 0 : !!selectedOptions;
20825
20844
  const inputSize = searchValue ? searchValue.length + 1 : 1;
@@ -20892,6 +20911,12 @@ const Trigger = ({
20892
20911
  }) => {
20893
20912
  var _a2;
20894
20913
  const [inputRef, setInputFocus] = useFocus();
20914
+ const isMounted = useRef(true);
20915
+ useEffect(() => {
20916
+ return () => {
20917
+ isMounted.current = false;
20918
+ };
20919
+ }, []);
20895
20920
  const hasSelection2 = Array.isArray(selectedOptions) ? selectedOptions.length > 0 && ((_a2 = selectedOptions[0]) == null ? void 0 : _a2.value) : selectedOptions == null ? void 0 : selectedOptions.value;
20896
20921
  const canClear = clearable && hasSelection2;
20897
20922
  const order2 = (() => {
@@ -20931,11 +20956,14 @@ const Trigger = ({
20931
20956
  order2
20932
20957
  ),
20933
20958
  onClick: (evt) => {
20934
- evt.stopPropagation();
20959
+ onClickTrigger(evt);
20935
20960
  if (typeof setInputFocus === "function") {
20936
- setInputFocus();
20961
+ requestAnimationFrame(() => {
20962
+ if (isMounted == null ? void 0 : isMounted.current) {
20963
+ setInputFocus();
20964
+ }
20965
+ });
20937
20966
  }
20938
- onClickTrigger(evt);
20939
20967
  },
20940
20968
  onFocus,
20941
20969
  onBlur,
@@ -21189,22 +21217,32 @@ const useCustomSelectLogic = ({
21189
21217
  firstSelectedOptionIndex,
21190
21218
  createAble,
21191
21219
  listRef,
21192
- autoLayerWidth
21220
+ autoLayerWidth,
21221
+ isMounted
21193
21222
  }) => {
21223
+ const safeDispatch = (action2) => {
21224
+ if (isMounted.current) {
21225
+ dispatch(action2);
21226
+ }
21227
+ };
21194
21228
  const closeLayer = () => {
21195
21229
  if (state.isLayerOpen) {
21196
- dispatch({ type: ActionTypes.CLOSE_LAYER });
21230
+ safeDispatch({ type: ActionTypes.CLOSE_LAYER });
21197
21231
  }
21198
21232
  setTriggerFocus();
21199
21233
  };
21200
- const openLayer = () => dispatch({ type: ActionTypes.OPEN_LAYER });
21234
+ const openLayer = () => safeDispatch({ type: ActionTypes.OPEN_LAYER });
21201
21235
  const isFirstRun = useRef(true);
21202
21236
  useEffect(() => {
21237
+ console.log("isFirstRun mounted");
21203
21238
  if (isFirstRun.current) {
21204
21239
  isFirstRun.current = false;
21205
21240
  } else {
21206
- dispatch({ type: ActionTypes.SET_VISIBLE_OPTIONS, options });
21241
+ safeDispatch({ type: ActionTypes.SET_VISIBLE_OPTIONS, options });
21207
21242
  }
21243
+ return () => {
21244
+ console.log("isFirstRun unmounted");
21245
+ };
21208
21246
  }, [options]);
21209
21247
  const onSelectOption = (evt, option2, close2) => {
21210
21248
  if (!(disabled2 || disabledContext)) {
@@ -21241,7 +21279,7 @@ const useCustomSelectLogic = ({
21241
21279
  }
21242
21280
  }
21243
21281
  }
21244
- dispatch({ type: ActionTypes.CLEAR_SEARCH, options });
21282
+ safeDispatch({ type: ActionTypes.CLEAR_SEARCH, options });
21245
21283
  setTriggerFocus();
21246
21284
  }
21247
21285
  };
@@ -21277,7 +21315,7 @@ const useCustomSelectLogic = ({
21277
21315
  closeLayer();
21278
21316
  return;
21279
21317
  }
21280
- dispatch({
21318
+ safeDispatch({
21281
21319
  type: ActionTypes.RESET_LAYER_FOCUS,
21282
21320
  options,
21283
21321
  firstSelectedOptionIndex
@@ -21286,13 +21324,17 @@ const useCustomSelectLogic = ({
21286
21324
  };
21287
21325
  const isFirstRender = useRef(true);
21288
21326
  useEffect(() => {
21327
+ console.log("isFirstRender mounted");
21289
21328
  if (isFirstRender.current) {
21290
21329
  isFirstRender.current = false;
21291
21330
  } else {
21292
21331
  if (!state.isLayerOpen) {
21293
- dispatch({ type: ActionTypes.CLEAR_SEARCH, options });
21332
+ safeDispatch({ type: ActionTypes.CLEAR_SEARCH, options });
21294
21333
  }
21295
21334
  }
21335
+ return () => {
21336
+ console.log("isFirstRender unmounted");
21337
+ };
21296
21338
  }, [state.isLayerOpen]);
21297
21339
  const onClickDeselectOption = (evt, options2) => {
21298
21340
  const newSelectedOptions = selectedOptions instanceof Array ? selectedOptions.filter((option2) => option2.value !== options2.value) : null;
@@ -21306,7 +21348,7 @@ const useCustomSelectLogic = ({
21306
21348
  onChange(evt, newSelectedOptions);
21307
21349
  }
21308
21350
  };
21309
- const onChangeSearch = (value) => dispatch({
21351
+ const onChangeSearch = (value) => safeDispatch({
21310
21352
  type: ActionTypes.ON_CHANGE_SEARCH,
21311
21353
  options,
21312
21354
  value,
@@ -21314,7 +21356,7 @@ const useCustomSelectLogic = ({
21314
21356
  });
21315
21357
  const clickTrigger = () => {
21316
21358
  openLayer();
21317
- dispatch({ type: ActionTypes.BLUR_TRIGGER_INPUTS });
21359
+ safeDispatch({ type: ActionTypes.BLUR_TRIGGER_INPUTS });
21318
21360
  };
21319
21361
  const scrollToItem = (index2) => {
21320
21362
  if (listRef.current && Number.isInteger(index2)) {
@@ -21323,11 +21365,14 @@ const useCustomSelectLogic = ({
21323
21365
  };
21324
21366
  const focusNextLayerOption = (ICustomSelectDirection2) => {
21325
21367
  const next2 = nextLayerFocus(ICustomSelectDirection2, state.layerFocus);
21326
- dispatch({ type: ActionTypes.FOCUS_LAYER_OPTIONS, nextLayerFocus: next2 });
21368
+ safeDispatch({
21369
+ type: ActionTypes.FOCUS_LAYER_OPTIONS,
21370
+ nextLayerFocus: next2
21371
+ });
21327
21372
  scrollToItem(next2.current);
21328
21373
  };
21329
21374
  const focusTriggerInputs = (ICustomSelectDirection2) => {
21330
- dispatch({
21375
+ safeDispatch({
21331
21376
  type: ActionTypes.FOCUS_TRIGGER_INPUTS,
21332
21377
  ICustomSelectDirection: ICustomSelectDirection2,
21333
21378
  selectedOptions
@@ -21448,6 +21493,12 @@ const CustomSelect = (props) => {
21448
21493
  isLayerOpen: false
21449
21494
  })
21450
21495
  );
21496
+ const isMounted = useRef(true);
21497
+ useEffect(() => {
21498
+ return () => {
21499
+ isMounted.current = false;
21500
+ };
21501
+ }, []);
21451
21502
  const {
21452
21503
  getTriggerWidth,
21453
21504
  onKeyEvent,
@@ -21471,7 +21522,8 @@ const CustomSelect = (props) => {
21471
21522
  disabledContext,
21472
21523
  isFontLoaded,
21473
21524
  createAble,
21474
- listRef
21525
+ listRef,
21526
+ isMounted
21475
21527
  });
21476
21528
  return /* @__PURE__ */ jsx("div", { style: { width: getTriggerWidth() }, children: /* @__PURE__ */ jsxs(
21477
21529
  KeyboardEventHandler,