@trackunit/react-form-components 0.0.444 → 0.0.448
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 +13 -7
- package/index.esm.js +14 -8
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -1922,6 +1922,7 @@ Select.displayName = "Select";
|
|
|
1922
1922
|
|
|
1923
1923
|
const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
|
|
1924
1924
|
var { className, dataTestId, helpText, helpAddon, tip, label, disabled, isInvalid, errorMessage, name, onBlur, options, value, defaultValue, id, onChange, children } = _a, rest = __rest(_a, ["className", "dataTestId", "helpText", "helpAddon", "tip", "label", "disabled", "isInvalid", "errorMessage", "name", "onBlur", "options", "value", "defaultValue", "id", "onChange", "children"]);
|
|
1925
|
+
const isFirstRender = reactComponents.useIsFirstRender();
|
|
1925
1926
|
const [innerValue, setInnerValue] = React.useState(value || defaultValue);
|
|
1926
1927
|
React.useEffect(() => {
|
|
1927
1928
|
setInnerValue(defaultValue);
|
|
@@ -1930,18 +1931,18 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
|
|
|
1930
1931
|
const htmlFor = React.useMemo(() => (id ? id : "selectField-" + uuid.v4()), [id]);
|
|
1931
1932
|
const innerRef = React.useRef(null);
|
|
1932
1933
|
React.useImperativeHandle(ref, () => innerRef.current, []);
|
|
1933
|
-
const handleChange = React.useCallback((newValue) => {
|
|
1934
|
-
setInnerValue(newValue === null || newValue === void 0 ? void 0 : newValue.value);
|
|
1935
|
-
}, []);
|
|
1936
1934
|
React.useEffect(() => {
|
|
1937
1935
|
var _a;
|
|
1938
|
-
if (
|
|
1936
|
+
if (innerValue === undefined) {
|
|
1939
1937
|
return;
|
|
1940
1938
|
}
|
|
1941
1939
|
const event = new Event("change");
|
|
1940
|
+
if (innerValue === "" && innerRef.current) {
|
|
1941
|
+
innerRef.current.value = ""; // Set the desired option value
|
|
1942
|
+
}
|
|
1942
1943
|
(_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
|
|
1943
1944
|
onChange === null || onChange === void 0 ? void 0 : onChange(event);
|
|
1944
|
-
}, [onChange, innerValue]);
|
|
1945
|
+
}, [onChange, innerValue, isFirstRender]);
|
|
1945
1946
|
const optionsWithCurrentSelectionBackupOption = [
|
|
1946
1947
|
// Add the current selection in case there's no options loaded yet (in CreatableSelect)
|
|
1947
1948
|
// Also _don't_ add it if it's a duplicate
|
|
@@ -1955,13 +1956,18 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
|
|
|
1955
1956
|
htmlFor,
|
|
1956
1957
|
className,
|
|
1957
1958
|
dataTestId,
|
|
1958
|
-
helpText,
|
|
1959
|
+
helpText: (renderAsInvalid && errorMessage) || helpText,
|
|
1959
1960
|
helpAddon,
|
|
1960
1961
|
tip,
|
|
1961
1962
|
label,
|
|
1962
1963
|
disabled, children: [jsxRuntime.jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: optionsWithCurrentSelectionBackupOption.map(option => {
|
|
1963
1964
|
return (jsxRuntime.jsx("option", { value: option.value, children: option.label }, option.value));
|
|
1964
|
-
}) }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur, options: optionsWithCurrentSelectionBackupOption, onChange:
|
|
1965
|
+
}) }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur, options: optionsWithCurrentSelectionBackupOption, onChange: e => {
|
|
1966
|
+
// If theres no value, set the inner value to an empty string
|
|
1967
|
+
// A native select can not have a null value
|
|
1968
|
+
// So even if react-select sends a null value, we need to convert it to an empty string
|
|
1969
|
+
setInnerValue(!e ? "" : e.value);
|
|
1970
|
+
}, value: selectedOption, defaultValue: selectedOption }))] }));
|
|
1965
1971
|
});
|
|
1966
1972
|
|
|
1967
1973
|
/**
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation, NamespaceTrans } from '@trackunit/i18n-library-translation';
|
|
3
|
-
import { IconButton, Icon, Tooltip, Heading, Text, MenuItem, Tag, Spinner } from '@trackunit/react-components';
|
|
3
|
+
import { IconButton, Icon, Tooltip, Heading, Text, MenuItem, Tag, Spinner, useIsFirstRender } from '@trackunit/react-components';
|
|
4
4
|
import { useCopyToClipboard } from 'react-use';
|
|
5
5
|
import { cvaMerge } from '@trackunit/css-class-variance-utilities';
|
|
6
6
|
import * as React from 'react';
|
|
@@ -1892,6 +1892,7 @@ Select.displayName = "Select";
|
|
|
1892
1892
|
|
|
1893
1893
|
const FormFieldSelectAdapter = forwardRef((_a, ref) => {
|
|
1894
1894
|
var { className, dataTestId, helpText, helpAddon, tip, label, disabled, isInvalid, errorMessage, name, onBlur, options, value, defaultValue, id, onChange, children } = _a, rest = __rest(_a, ["className", "dataTestId", "helpText", "helpAddon", "tip", "label", "disabled", "isInvalid", "errorMessage", "name", "onBlur", "options", "value", "defaultValue", "id", "onChange", "children"]);
|
|
1895
|
+
const isFirstRender = useIsFirstRender();
|
|
1895
1896
|
const [innerValue, setInnerValue] = useState(value || defaultValue);
|
|
1896
1897
|
useEffect(() => {
|
|
1897
1898
|
setInnerValue(defaultValue);
|
|
@@ -1900,18 +1901,18 @@ const FormFieldSelectAdapter = forwardRef((_a, ref) => {
|
|
|
1900
1901
|
const htmlFor = useMemo(() => (id ? id : "selectField-" + v4()), [id]);
|
|
1901
1902
|
const innerRef = useRef(null);
|
|
1902
1903
|
useImperativeHandle(ref, () => innerRef.current, []);
|
|
1903
|
-
const handleChange = useCallback((newValue) => {
|
|
1904
|
-
setInnerValue(newValue === null || newValue === void 0 ? void 0 : newValue.value);
|
|
1905
|
-
}, []);
|
|
1906
1904
|
useEffect(() => {
|
|
1907
1905
|
var _a;
|
|
1908
|
-
if (
|
|
1906
|
+
if (innerValue === undefined) {
|
|
1909
1907
|
return;
|
|
1910
1908
|
}
|
|
1911
1909
|
const event = new Event("change");
|
|
1910
|
+
if (innerValue === "" && innerRef.current) {
|
|
1911
|
+
innerRef.current.value = ""; // Set the desired option value
|
|
1912
|
+
}
|
|
1912
1913
|
(_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
|
|
1913
1914
|
onChange === null || onChange === void 0 ? void 0 : onChange(event);
|
|
1914
|
-
}, [onChange, innerValue]);
|
|
1915
|
+
}, [onChange, innerValue, isFirstRender]);
|
|
1915
1916
|
const optionsWithCurrentSelectionBackupOption = [
|
|
1916
1917
|
// Add the current selection in case there's no options loaded yet (in CreatableSelect)
|
|
1917
1918
|
// Also _don't_ add it if it's a duplicate
|
|
@@ -1925,13 +1926,18 @@ const FormFieldSelectAdapter = forwardRef((_a, ref) => {
|
|
|
1925
1926
|
htmlFor,
|
|
1926
1927
|
className,
|
|
1927
1928
|
dataTestId,
|
|
1928
|
-
helpText,
|
|
1929
|
+
helpText: (renderAsInvalid && errorMessage) || helpText,
|
|
1929
1930
|
helpAddon,
|
|
1930
1931
|
tip,
|
|
1931
1932
|
label,
|
|
1932
1933
|
disabled, children: [jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: optionsWithCurrentSelectionBackupOption.map(option => {
|
|
1933
1934
|
return (jsx("option", { value: option.value, children: option.label }, option.value));
|
|
1934
|
-
}) }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur, options: optionsWithCurrentSelectionBackupOption, onChange:
|
|
1935
|
+
}) }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur, options: optionsWithCurrentSelectionBackupOption, onChange: e => {
|
|
1936
|
+
// If theres no value, set the inner value to an empty string
|
|
1937
|
+
// A native select can not have a null value
|
|
1938
|
+
// So even if react-select sends a null value, we need to convert it to an empty string
|
|
1939
|
+
setInnerValue(!e ? "" : e.value);
|
|
1940
|
+
}, value: selectedOption, defaultValue: selectedOption }))] }));
|
|
1935
1941
|
});
|
|
1936
1942
|
|
|
1937
1943
|
/**
|