@trackunit/react-form-components 0.0.447 → 0.0.450

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
@@ -579,8 +579,7 @@ const cvaHelpAddon = cssClassVarianceUtilities.cvaMerge(["ml-auto"]);
579
579
  * @returns {JSX.Element} FormGroup component
580
580
  */
581
581
  const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, htmlFor, children, tipIconProps, disabled = false, required = false, }) => {
582
- return (jsxRuntime.jsxs("div", { className: cvaFormGroup({ disabled, className }), "data-testid": dataTestId, children: [jsxRuntime.jsxs("div", { className: cvaFormGroupContainerBefore(), children: [label ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Label, { className: "component-formGroup-font", dataTestId: dataTestId && `${dataTestId}-label`, htmlFor: htmlFor, id: htmlFor + "-label", children: label }), jsxRuntime.jsx("span", { className: "required-asterisk", children: "*" })] })) :
583
- null, tip ? (jsxRuntime.jsx(reactComponents.Tooltip, { className: "ml-1", dataTestId: dataTestId && `${dataTestId}-tooltip`, iconProps: tipIconProps, label: tip, placement: "bottom" })) : null] }), children, jsxRuntime.jsxs("div", { className: cvaFormGroupContainerAfter({ invalid: isInvalid }), children: [helpText && jsxRuntime.jsx("span", { "data-testid": dataTestId && `${dataTestId}-helpText`, children: helpText }), helpAddon && (jsxRuntime.jsx("span", { className: cvaHelpAddon(), "data-testid": dataTestId && `${dataTestId}-helpAddon`, children: helpAddon }))] })] }));
582
+ return (jsxRuntime.jsxs("div", { className: cvaFormGroup({ disabled, className }), "data-testid": dataTestId, children: [jsxRuntime.jsxs("div", { className: cvaFormGroupContainerBefore(), children: [label ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Label, { className: "component-formGroup-font", dataTestId: dataTestId && `${dataTestId}-label`, htmlFor: htmlFor, id: htmlFor + "-label", children: label }), required && jsxRuntime.jsx("span", { className: "required-asterisk", children: "*" })] })) : null, tip ? (jsxRuntime.jsx(reactComponents.Tooltip, { className: "ml-1", dataTestId: dataTestId && `${dataTestId}-tooltip`, iconProps: tipIconProps, label: tip, placement: "bottom" })) : null] }), children, jsxRuntime.jsxs("div", { className: cvaFormGroupContainerAfter({ invalid: isInvalid }), children: [helpText && jsxRuntime.jsx("span", { "data-testid": dataTestId && `${dataTestId}-helpText`, children: helpText }), helpAddon && (jsxRuntime.jsx("span", { className: cvaHelpAddon(), "data-testid": dataTestId && `${dataTestId}-helpAddon`, children: helpAddon }))] })] }));
584
583
  };
585
584
 
586
585
  /**
@@ -1922,6 +1921,7 @@ Select.displayName = "Select";
1922
1921
 
1923
1922
  const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
1924
1923
  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"]);
1924
+ const isFirstRender = reactComponents.useIsFirstRender();
1925
1925
  const [innerValue, setInnerValue] = React.useState(value || defaultValue);
1926
1926
  React.useEffect(() => {
1927
1927
  setInnerValue(defaultValue);
@@ -1930,18 +1930,18 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
1930
1930
  const htmlFor = React.useMemo(() => (id ? id : "selectField-" + uuid.v4()), [id]);
1931
1931
  const innerRef = React.useRef(null);
1932
1932
  React.useImperativeHandle(ref, () => innerRef.current, []);
1933
- const handleChange = React.useCallback((newValue) => {
1934
- setInnerValue(newValue === null || newValue === void 0 ? void 0 : newValue.value);
1935
- }, []);
1936
1933
  React.useEffect(() => {
1937
1934
  var _a;
1938
- if (!innerValue) {
1935
+ if (innerValue === undefined) {
1939
1936
  return;
1940
1937
  }
1941
1938
  const event = new Event("change");
1939
+ if (innerValue === "" && innerRef.current) {
1940
+ innerRef.current.value = ""; // Set the desired option value
1941
+ }
1942
1942
  (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
1943
1943
  onChange === null || onChange === void 0 ? void 0 : onChange(event);
1944
- }, [onChange, innerValue]);
1944
+ }, [onChange, innerValue, isFirstRender]);
1945
1945
  const optionsWithCurrentSelectionBackupOption = [
1946
1946
  // Add the current selection in case there's no options loaded yet (in CreatableSelect)
1947
1947
  // Also _don't_ add it if it's a duplicate
@@ -1961,7 +1961,12 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
1961
1961
  label,
1962
1962
  disabled, children: [jsxRuntime.jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: optionsWithCurrentSelectionBackupOption.map(option => {
1963
1963
  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: handleChange, value: selectedOption, defaultValue: selectedOption }))] }));
1964
+ }) }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur, options: optionsWithCurrentSelectionBackupOption, onChange: e => {
1965
+ // If theres no value, set the inner value to an empty string
1966
+ // A native select can not have a null value
1967
+ // So even if react-select sends a null value, we need to convert it to an empty string
1968
+ setInnerValue(!e ? "" : e.value);
1969
+ }, value: selectedOption, defaultValue: selectedOption }))] }));
1965
1970
  });
1966
1971
 
1967
1972
  /**
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';
@@ -549,8 +549,7 @@ const cvaHelpAddon = cvaMerge(["ml-auto"]);
549
549
  * @returns {JSX.Element} FormGroup component
550
550
  */
551
551
  const FormGroup = ({ isInvalid, helpText, helpAddon, tip, className, dataTestId, label, htmlFor, children, tipIconProps, disabled = false, required = false, }) => {
552
- return (jsxs("div", { className: cvaFormGroup({ disabled, className }), "data-testid": dataTestId, children: [jsxs("div", { className: cvaFormGroupContainerBefore(), children: [label ? (jsxs(Fragment, { children: [jsx(Label, { className: "component-formGroup-font", dataTestId: dataTestId && `${dataTestId}-label`, htmlFor: htmlFor, id: htmlFor + "-label", children: label }), jsx("span", { className: "required-asterisk", children: "*" })] })) :
553
- null, tip ? (jsx(Tooltip, { className: "ml-1", dataTestId: dataTestId && `${dataTestId}-tooltip`, iconProps: tipIconProps, label: tip, placement: "bottom" })) : null] }), children, jsxs("div", { className: cvaFormGroupContainerAfter({ invalid: isInvalid }), children: [helpText && jsx("span", { "data-testid": dataTestId && `${dataTestId}-helpText`, children: helpText }), helpAddon && (jsx("span", { className: cvaHelpAddon(), "data-testid": dataTestId && `${dataTestId}-helpAddon`, children: helpAddon }))] })] }));
552
+ return (jsxs("div", { className: cvaFormGroup({ disabled, className }), "data-testid": dataTestId, children: [jsxs("div", { className: cvaFormGroupContainerBefore(), children: [label ? (jsxs(Fragment, { children: [jsx(Label, { className: "component-formGroup-font", dataTestId: dataTestId && `${dataTestId}-label`, htmlFor: htmlFor, id: htmlFor + "-label", children: label }), required && jsx("span", { className: "required-asterisk", children: "*" })] })) : null, tip ? (jsx(Tooltip, { className: "ml-1", dataTestId: dataTestId && `${dataTestId}-tooltip`, iconProps: tipIconProps, label: tip, placement: "bottom" })) : null] }), children, jsxs("div", { className: cvaFormGroupContainerAfter({ invalid: isInvalid }), children: [helpText && jsx("span", { "data-testid": dataTestId && `${dataTestId}-helpText`, children: helpText }), helpAddon && (jsx("span", { className: cvaHelpAddon(), "data-testid": dataTestId && `${dataTestId}-helpAddon`, children: helpAddon }))] })] }));
554
553
  };
555
554
 
556
555
  /**
@@ -1892,6 +1891,7 @@ Select.displayName = "Select";
1892
1891
 
1893
1892
  const FormFieldSelectAdapter = forwardRef((_a, ref) => {
1894
1893
  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"]);
1894
+ const isFirstRender = useIsFirstRender();
1895
1895
  const [innerValue, setInnerValue] = useState(value || defaultValue);
1896
1896
  useEffect(() => {
1897
1897
  setInnerValue(defaultValue);
@@ -1900,18 +1900,18 @@ const FormFieldSelectAdapter = forwardRef((_a, ref) => {
1900
1900
  const htmlFor = useMemo(() => (id ? id : "selectField-" + v4()), [id]);
1901
1901
  const innerRef = useRef(null);
1902
1902
  useImperativeHandle(ref, () => innerRef.current, []);
1903
- const handleChange = useCallback((newValue) => {
1904
- setInnerValue(newValue === null || newValue === void 0 ? void 0 : newValue.value);
1905
- }, []);
1906
1903
  useEffect(() => {
1907
1904
  var _a;
1908
- if (!innerValue) {
1905
+ if (innerValue === undefined) {
1909
1906
  return;
1910
1907
  }
1911
1908
  const event = new Event("change");
1909
+ if (innerValue === "" && innerRef.current) {
1910
+ innerRef.current.value = ""; // Set the desired option value
1911
+ }
1912
1912
  (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
1913
1913
  onChange === null || onChange === void 0 ? void 0 : onChange(event);
1914
- }, [onChange, innerValue]);
1914
+ }, [onChange, innerValue, isFirstRender]);
1915
1915
  const optionsWithCurrentSelectionBackupOption = [
1916
1916
  // Add the current selection in case there's no options loaded yet (in CreatableSelect)
1917
1917
  // Also _don't_ add it if it's a duplicate
@@ -1931,7 +1931,12 @@ const FormFieldSelectAdapter = forwardRef((_a, ref) => {
1931
1931
  label,
1932
1932
  disabled, children: [jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: optionsWithCurrentSelectionBackupOption.map(option => {
1933
1933
  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: handleChange, value: selectedOption, defaultValue: selectedOption }))] }));
1934
+ }) }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur, options: optionsWithCurrentSelectionBackupOption, onChange: e => {
1935
+ // If theres no value, set the inner value to an empty string
1936
+ // A native select can not have a null value
1937
+ // So even if react-select sends a null value, we need to convert it to an empty string
1938
+ setInnerValue(!e ? "" : e.value);
1939
+ }, value: selectedOption, defaultValue: selectedOption }))] }));
1935
1940
  });
1936
1941
 
1937
1942
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "0.0.447",
3
+ "version": "0.0.450",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {