@trackunit/react-form-components 1.16.11 → 1.16.14
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 +15 -5
- package/index.esm.js +15 -5
- package/package.json +8 -8
package/index.cjs.js
CHANGED
|
@@ -3779,16 +3779,26 @@ Search.displayName = "Search";
|
|
|
3779
3779
|
const FormFieldSelectAdapter = ({ className, "data-testid": dataTestId, helpText, helpAddon, tip, label, isInvalid = false, errorMessage, name, onBlur, options, value, defaultValue, id, htmlFor: htmlForProp, onChange, children, ref, required = false, ...rest }) => {
|
|
3780
3780
|
const isFirstRender = reactComponents.useIsFirstRender();
|
|
3781
3781
|
const [innerValue, setInnerValue] = react.useState(value ?? defaultValue);
|
|
3782
|
+
const onChangeRef = react.useRef(onChange);
|
|
3783
|
+
react.useEffect(() => {
|
|
3784
|
+
onChangeRef.current = onChange;
|
|
3785
|
+
}, [onChange]);
|
|
3782
3786
|
react.useEffect(() => {
|
|
3783
|
-
|
|
3784
|
-
|
|
3787
|
+
const nextValue = value ?? defaultValue;
|
|
3788
|
+
setInnerValue(currentValue => {
|
|
3789
|
+
if (currentValue === nextValue) {
|
|
3790
|
+
return currentValue;
|
|
3791
|
+
}
|
|
3792
|
+
return nextValue;
|
|
3793
|
+
});
|
|
3794
|
+
}, [value, defaultValue]);
|
|
3785
3795
|
const renderAsInvalid = isInvalid || Boolean(errorMessage);
|
|
3786
3796
|
const htmlFor = react.useMemo(() => htmlForProp ?? id ?? "selectField-" + sharedUtils.uuidv4(), [htmlForProp, id]);
|
|
3787
3797
|
const innerRef = react.useRef(null);
|
|
3788
3798
|
// eslint-disable-next-line @trackunit/no-typescript-assertion, @typescript-eslint/no-non-null-assertion
|
|
3789
3799
|
react.useImperativeHandle(ref, () => innerRef.current, []);
|
|
3790
3800
|
react.useEffect(() => {
|
|
3791
|
-
if (innerValue === undefined) {
|
|
3801
|
+
if (isFirstRender || innerValue === undefined) {
|
|
3792
3802
|
return;
|
|
3793
3803
|
}
|
|
3794
3804
|
const event = new Event("change");
|
|
@@ -3796,8 +3806,8 @@ const FormFieldSelectAdapter = ({ className, "data-testid": dataTestId, helpText
|
|
|
3796
3806
|
innerRef.current.value = ""; // Set the desired option value
|
|
3797
3807
|
}
|
|
3798
3808
|
innerRef.current?.dispatchEvent(event);
|
|
3799
|
-
|
|
3800
|
-
}, [
|
|
3809
|
+
onChangeRef.current?.(event);
|
|
3810
|
+
}, [innerValue, isFirstRender]);
|
|
3801
3811
|
const optionsWithCurrentSelectionBackupOption = [
|
|
3802
3812
|
// Add the current selection in case there's no options loaded yet (in CreatableSelect)
|
|
3803
3813
|
// Also _don't_ add it if it's a duplicate
|
package/index.esm.js
CHANGED
|
@@ -3778,16 +3778,26 @@ Search.displayName = "Search";
|
|
|
3778
3778
|
const FormFieldSelectAdapter = ({ className, "data-testid": dataTestId, helpText, helpAddon, tip, label, isInvalid = false, errorMessage, name, onBlur, options, value, defaultValue, id, htmlFor: htmlForProp, onChange, children, ref, required = false, ...rest }) => {
|
|
3779
3779
|
const isFirstRender = useIsFirstRender();
|
|
3780
3780
|
const [innerValue, setInnerValue] = useState(value ?? defaultValue);
|
|
3781
|
+
const onChangeRef = useRef(onChange);
|
|
3782
|
+
useEffect(() => {
|
|
3783
|
+
onChangeRef.current = onChange;
|
|
3784
|
+
}, [onChange]);
|
|
3781
3785
|
useEffect(() => {
|
|
3782
|
-
|
|
3783
|
-
|
|
3786
|
+
const nextValue = value ?? defaultValue;
|
|
3787
|
+
setInnerValue(currentValue => {
|
|
3788
|
+
if (currentValue === nextValue) {
|
|
3789
|
+
return currentValue;
|
|
3790
|
+
}
|
|
3791
|
+
return nextValue;
|
|
3792
|
+
});
|
|
3793
|
+
}, [value, defaultValue]);
|
|
3784
3794
|
const renderAsInvalid = isInvalid || Boolean(errorMessage);
|
|
3785
3795
|
const htmlFor = useMemo(() => htmlForProp ?? id ?? "selectField-" + uuidv4(), [htmlForProp, id]);
|
|
3786
3796
|
const innerRef = useRef(null);
|
|
3787
3797
|
// eslint-disable-next-line @trackunit/no-typescript-assertion, @typescript-eslint/no-non-null-assertion
|
|
3788
3798
|
useImperativeHandle(ref, () => innerRef.current, []);
|
|
3789
3799
|
useEffect(() => {
|
|
3790
|
-
if (innerValue === undefined) {
|
|
3800
|
+
if (isFirstRender || innerValue === undefined) {
|
|
3791
3801
|
return;
|
|
3792
3802
|
}
|
|
3793
3803
|
const event = new Event("change");
|
|
@@ -3795,8 +3805,8 @@ const FormFieldSelectAdapter = ({ className, "data-testid": dataTestId, helpText
|
|
|
3795
3805
|
innerRef.current.value = ""; // Set the desired option value
|
|
3796
3806
|
}
|
|
3797
3807
|
innerRef.current?.dispatchEvent(event);
|
|
3798
|
-
|
|
3799
|
-
}, [
|
|
3808
|
+
onChangeRef.current?.(event);
|
|
3809
|
+
}, [innerValue, isFirstRender]);
|
|
3800
3810
|
const optionsWithCurrentSelectionBackupOption = [
|
|
3801
3811
|
// Add the current selection in case there's no options loaded yet (in CreatableSelect)
|
|
3802
3812
|
// Also _don't_ add it if it's a duplicate
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-form-components",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.14",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -9,18 +9,18 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"react": "19.0.0",
|
|
11
11
|
"react-select": "^5.10.2",
|
|
12
|
-
"@trackunit/date-and-time-utils": "1.11.
|
|
12
|
+
"@trackunit/date-and-time-utils": "1.11.77",
|
|
13
13
|
"usehooks-ts": "^3.1.0",
|
|
14
14
|
"libphonenumber-js": "^1.12.22",
|
|
15
15
|
"zod": "^3.23.8",
|
|
16
16
|
"react-hook-form": "7.62.0",
|
|
17
17
|
"tailwind-merge": "^2.0.0",
|
|
18
|
-
"@trackunit/css-class-variance-utilities": "1.11.
|
|
19
|
-
"@trackunit/react-components": "1.18.
|
|
20
|
-
"@trackunit/ui-icons": "1.11.
|
|
21
|
-
"@trackunit/shared-utils": "1.13.
|
|
22
|
-
"@trackunit/ui-design-tokens": "1.11.
|
|
23
|
-
"@trackunit/i18n-library-translation": "1.13.
|
|
18
|
+
"@trackunit/css-class-variance-utilities": "1.11.75",
|
|
19
|
+
"@trackunit/react-components": "1.18.21",
|
|
20
|
+
"@trackunit/ui-icons": "1.11.72",
|
|
21
|
+
"@trackunit/shared-utils": "1.13.75",
|
|
22
|
+
"@trackunit/ui-design-tokens": "1.11.73",
|
|
23
|
+
"@trackunit/i18n-library-translation": "1.13.13",
|
|
24
24
|
"string-ts": "^2.0.0",
|
|
25
25
|
"es-toolkit": "^1.39.10"
|
|
26
26
|
},
|