@trackunit/react-form-components 2.10.8-alpha-0ef4e15e7c1.0 → 2.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/index.cjs.js CHANGED
@@ -2432,6 +2432,10 @@ formatOptionLabel, onMenuScrollToBottom, getMenuGeometry, setMenuListRef, }) =>
2432
2432
  getOptionPrefixRef.current = getOptionPrefix;
2433
2433
  const onMenuScrollToBottomRef = react.useRef(onMenuScrollToBottom);
2434
2434
  onMenuScrollToBottomRef.current = onMenuScrollToBottom;
2435
+ // Toggling hasError must not recreate customComponents. react-select remounts its input when
2436
+ // that object changes, which drops focus and the in-progress value.
2437
+ const hasErrorRef = react.useRef(hasError);
2438
+ hasErrorRef.current = hasError;
2435
2439
  // Keep react-select's control ref intact while retaining the live DOM node for viewport-relative
2436
2440
  // vertical measurements that can change without changing an absolute portal's document offset.
2437
2441
  const controlRef = react.useRef(null);
@@ -2450,7 +2454,7 @@ formatOptionLabel, onMenuScrollToBottom, getMenuGeometry, setMenuListRef, }) =>
2450
2454
  return {
2451
2455
  SelectContainer: selectContainer => {
2452
2456
  return (jsxRuntime.jsx(ReactSelect.components.SelectContainer, { ...selectContainer, className: cvaSelectContainer({
2453
- invalid: hasError,
2457
+ invalid: hasErrorRef.current,
2454
2458
  fieldSize,
2455
2459
  disabled: Boolean(disabled),
2456
2460
  className: [className, selectContainer.className],
@@ -2613,7 +2617,6 @@ formatOptionLabel, onMenuScrollToBottom, getMenuGeometry, setMenuListRef, }) =>
2613
2617
  },
2614
2618
  };
2615
2619
  }, [
2616
- hasError,
2617
2620
  fieldSize,
2618
2621
  disabled,
2619
2622
  className,
@@ -2667,9 +2670,22 @@ const getMenuGeometryStyle = (geometry, controlRect, placement) => {
2667
2670
  return style;
2668
2671
  };
2669
2672
  const getInputComponent = (children) => {
2670
- return Array.isArray(children)
2671
- ? children.find(child => child !== null && child !== undefined && /react-select-\d+-input/.test(child?.props?.id))
2672
- : null;
2673
+ if (!Array.isArray(children)) {
2674
+ return null;
2675
+ }
2676
+ return children.find(child => isSelectInputElement(child)) ?? null;
2677
+ };
2678
+ const isSelectInputElement = (child) => {
2679
+ if (child === null || typeof child !== "object" || !("props" in child)) {
2680
+ return false;
2681
+ }
2682
+ const props = child.props;
2683
+ if (props === null || typeof props !== "object") {
2684
+ return false;
2685
+ }
2686
+ const id = "id" in props ? props.id : undefined;
2687
+ const role = "role" in props ? props.role : undefined;
2688
+ return (typeof id === "string" && /react-select-\d+-input/.test(id)) || role === "combobox";
2673
2689
  };
2674
2690
  const getMultiValueComponents = (children) => {
2675
2691
  if (!Array.isArray(children)) {
package/index.esm.js CHANGED
@@ -2431,6 +2431,10 @@ formatOptionLabel, onMenuScrollToBottom, getMenuGeometry, setMenuListRef, }) =>
2431
2431
  getOptionPrefixRef.current = getOptionPrefix;
2432
2432
  const onMenuScrollToBottomRef = useRef(onMenuScrollToBottom);
2433
2433
  onMenuScrollToBottomRef.current = onMenuScrollToBottom;
2434
+ // Toggling hasError must not recreate customComponents. react-select remounts its input when
2435
+ // that object changes, which drops focus and the in-progress value.
2436
+ const hasErrorRef = useRef(hasError);
2437
+ hasErrorRef.current = hasError;
2434
2438
  // Keep react-select's control ref intact while retaining the live DOM node for viewport-relative
2435
2439
  // vertical measurements that can change without changing an absolute portal's document offset.
2436
2440
  const controlRef = useRef(null);
@@ -2449,7 +2453,7 @@ formatOptionLabel, onMenuScrollToBottom, getMenuGeometry, setMenuListRef, }) =>
2449
2453
  return {
2450
2454
  SelectContainer: selectContainer => {
2451
2455
  return (jsx(components.SelectContainer, { ...selectContainer, className: cvaSelectContainer({
2452
- invalid: hasError,
2456
+ invalid: hasErrorRef.current,
2453
2457
  fieldSize,
2454
2458
  disabled: Boolean(disabled),
2455
2459
  className: [className, selectContainer.className],
@@ -2612,7 +2616,6 @@ formatOptionLabel, onMenuScrollToBottom, getMenuGeometry, setMenuListRef, }) =>
2612
2616
  },
2613
2617
  };
2614
2618
  }, [
2615
- hasError,
2616
2619
  fieldSize,
2617
2620
  disabled,
2618
2621
  className,
@@ -2666,9 +2669,22 @@ const getMenuGeometryStyle = (geometry, controlRect, placement) => {
2666
2669
  return style;
2667
2670
  };
2668
2671
  const getInputComponent = (children) => {
2669
- return Array.isArray(children)
2670
- ? children.find(child => child !== null && child !== undefined && /react-select-\d+-input/.test(child?.props?.id))
2671
- : null;
2672
+ if (!Array.isArray(children)) {
2673
+ return null;
2674
+ }
2675
+ return children.find(child => isSelectInputElement(child)) ?? null;
2676
+ };
2677
+ const isSelectInputElement = (child) => {
2678
+ if (child === null || typeof child !== "object" || !("props" in child)) {
2679
+ return false;
2680
+ }
2681
+ const props = child.props;
2682
+ if (props === null || typeof props !== "object") {
2683
+ return false;
2684
+ }
2685
+ const id = "id" in props ? props.id : undefined;
2686
+ const role = "role" in props ? props.role : undefined;
2687
+ return (typeof id === "string" && /react-select-\d+-input/.test(id)) || role === "combobox";
2672
2688
  };
2673
2689
  const getMultiValueComponents = (children) => {
2674
2690
  if (!Array.isArray(children)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "2.10.8-alpha-0ef4e15e7c1.0",
3
+ "version": "2.10.8",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "migrations": "./migrations.json",
@@ -10,17 +10,17 @@
10
10
  "dependencies": {
11
11
  "react-calendar": "^6.0.1",
12
12
  "react-select": "^5.10.2",
13
- "@trackunit/date-and-time-utils": "1.17.5-alpha-0ef4e15e7c1.0",
13
+ "@trackunit/date-and-time-utils": "1.17.4",
14
14
  "usehooks-ts": "^3.1.0",
15
15
  "libphonenumber-js": "^1.13.11",
16
16
  "zod": "^3.25.76",
17
17
  "tailwind-merge": "^2.0.0",
18
- "@trackunit/css-class-variance-utilities": "2.3.5-alpha-0ef4e15e7c1.0",
19
- "@trackunit/react-components": "3.8.2-alpha-0ef4e15e7c1.0",
20
- "@trackunit/ui-icons": "1.17.5-alpha-0ef4e15e7c1.0",
21
- "@trackunit/shared-utils": "1.19.5-alpha-0ef4e15e7c1.0",
22
- "@trackunit/ui-design-tokens": "1.18.5-alpha-0ef4e15e7c1.0",
23
- "@trackunit/i18n-library-translation": "2.8.5-alpha-0ef4e15e7c1.0",
18
+ "@trackunit/css-class-variance-utilities": "2.3.4",
19
+ "@trackunit/react-components": "3.8.1",
20
+ "@trackunit/ui-icons": "1.17.4",
21
+ "@trackunit/shared-utils": "1.19.4",
22
+ "@trackunit/ui-design-tokens": "1.18.4",
23
+ "@trackunit/i18n-library-translation": "2.8.4",
24
24
  "string-ts": "^2.0.0",
25
25
  "es-toolkit": "^1.52.0"
26
26
  },