@trackunit/react-form-components 0.0.312 → 0.0.313

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
@@ -1158,6 +1158,8 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
1158
1158
  return (jsxRuntime.jsx(ReactSelect.components.SingleValue, Object.assign({}, props, { className: props.isDisabled ? "text-slate-700" : "", children: jsxRuntime.jsx("div", { "data-testid": dataTestId + "-singleValue", children: props.children }) })));
1159
1159
  }, Menu: props => {
1160
1160
  return (jsxRuntime.jsx(ReactSelect.components.Menu, Object.assign({}, props, { className: cvaSelectMenuList({ menuIsOpen: props.selectProps.menuIsOpen }) })));
1161
+ }, Placeholder: props => {
1162
+ return (jsxRuntime.jsx(ReactSelect.components.Placeholder, Object.assign({}, props, { className: "!text-slate-400", children: props.children })));
1161
1163
  }, MenuList: props => {
1162
1164
  return (jsxRuntime.jsx(ReactSelect.components.MenuList, Object.assign({}, props, { innerProps: Object.assign(Object.assign({}, props.innerProps), { onScroll: e => {
1163
1165
  const listEl = e.currentTarget;
@@ -1983,12 +1985,15 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
1983
1985
  (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
1984
1986
  onChange === null || onChange === void 0 ? void 0 : onChange(event);
1985
1987
  }, [onChange, innerValue]);
1986
- const optionsWithCurrentSelectionToEnsureThatItWorks = [
1987
- innerValue ? { value: innerValue, label: String(innerValue) } : null,
1988
+ const optionsWithCurrentSelectionBackupOption = [
1989
+ // Add the current selection in case there's no options loaded yet (in CreatableSelect)
1990
+ // Also _don't_ add it if it's a duplicate
1991
+ innerValue && !options.find(option => option.value === innerValue)
1992
+ ? { value: innerValue, label: String(innerValue) }
1993
+ : null,
1988
1994
  ...options,
1989
1995
  ].filter(sharedUtils.nonNullable);
1990
- const selectedOption = optionsWithCurrentSelectionToEnsureThatItWorks.find(option => { var _a; return option.value === ((_a = innerRef === null || innerRef === void 0 ? void 0 : innerRef.current) === null || _a === void 0 ? void 0 : _a.value); });
1991
- const defaultSelectedOption = optionsWithCurrentSelectionToEnsureThatItWorks.find(option => option.value === innerValue);
1996
+ const selectedOption = optionsWithCurrentSelectionBackupOption.find(option => option.value === innerValue);
1992
1997
  return (jsxRuntime.jsxs(FormGroup, { isInvalid: renderAsInvalid,
1993
1998
  htmlFor,
1994
1999
  className,
@@ -1997,10 +2002,9 @@ const FormFieldSelectAdapter = React.forwardRef((_a, ref) => {
1997
2002
  helpAddon,
1998
2003
  tip,
1999
2004
  label,
2000
- disabled, children: [jsxRuntime.jsxs("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: [jsxRuntime.jsx("option", { value: innerValue, children: innerValue }), options.map(option => {
2001
- return (jsxRuntime.jsx("option", { value: option.value, children: option.label }, option.value));
2002
- })] }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur,
2003
- options, onChange: handleChange, value: selectedOption, defaultValue: defaultSelectedOption }))] }));
2005
+ disabled, children: [jsxRuntime.jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: optionsWithCurrentSelectionBackupOption.map(option => {
2006
+ return (jsxRuntime.jsx("option", { value: option.value, children: option.label }, option.value));
2007
+ }) }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur, options: optionsWithCurrentSelectionBackupOption, onChange: handleChange, value: selectedOption, defaultValue: selectedOption }))] }));
2004
2008
  });
2005
2009
 
2006
2010
  /**
package/index.esm.js CHANGED
@@ -1128,6 +1128,8 @@ const useCustomComponents = (componentsProps, disabled, menuIsOpen, refMenuIsEna
1128
1128
  return (jsx(components.SingleValue, Object.assign({}, props, { className: props.isDisabled ? "text-slate-700" : "", children: jsx("div", { "data-testid": dataTestId + "-singleValue", children: props.children }) })));
1129
1129
  }, Menu: props => {
1130
1130
  return (jsx(components.Menu, Object.assign({}, props, { className: cvaSelectMenuList({ menuIsOpen: props.selectProps.menuIsOpen }) })));
1131
+ }, Placeholder: props => {
1132
+ return (jsx(components.Placeholder, Object.assign({}, props, { className: "!text-slate-400", children: props.children })));
1131
1133
  }, MenuList: props => {
1132
1134
  return (jsx(components.MenuList, Object.assign({}, props, { innerProps: Object.assign(Object.assign({}, props.innerProps), { onScroll: e => {
1133
1135
  const listEl = e.currentTarget;
@@ -1953,12 +1955,15 @@ const FormFieldSelectAdapter = forwardRef((_a, ref) => {
1953
1955
  (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.dispatchEvent(event);
1954
1956
  onChange === null || onChange === void 0 ? void 0 : onChange(event);
1955
1957
  }, [onChange, innerValue]);
1956
- const optionsWithCurrentSelectionToEnsureThatItWorks = [
1957
- innerValue ? { value: innerValue, label: String(innerValue) } : null,
1958
+ const optionsWithCurrentSelectionBackupOption = [
1959
+ // Add the current selection in case there's no options loaded yet (in CreatableSelect)
1960
+ // Also _don't_ add it if it's a duplicate
1961
+ innerValue && !options.find(option => option.value === innerValue)
1962
+ ? { value: innerValue, label: String(innerValue) }
1963
+ : null,
1958
1964
  ...options,
1959
1965
  ].filter(nonNullable);
1960
- const selectedOption = optionsWithCurrentSelectionToEnsureThatItWorks.find(option => { var _a; return option.value === ((_a = innerRef === null || innerRef === void 0 ? void 0 : innerRef.current) === null || _a === void 0 ? void 0 : _a.value); });
1961
- const defaultSelectedOption = optionsWithCurrentSelectionToEnsureThatItWorks.find(option => option.value === innerValue);
1966
+ const selectedOption = optionsWithCurrentSelectionBackupOption.find(option => option.value === innerValue);
1962
1967
  return (jsxs(FormGroup, { isInvalid: renderAsInvalid,
1963
1968
  htmlFor,
1964
1969
  className,
@@ -1967,10 +1972,9 @@ const FormFieldSelectAdapter = forwardRef((_a, ref) => {
1967
1972
  helpAddon,
1968
1973
  tip,
1969
1974
  label,
1970
- disabled, children: [jsxs("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: [jsx("option", { value: innerValue, children: innerValue }), options.map(option => {
1971
- return (jsx("option", { value: option.value, children: option.label }, option.value));
1972
- })] }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur,
1973
- options, onChange: handleChange, value: selectedOption, defaultValue: defaultSelectedOption }))] }));
1975
+ disabled, children: [jsx("select", { onChange, ref: innerRef, name, value: innerValue, hidden: true, children: optionsWithCurrentSelectionBackupOption.map(option => {
1976
+ return (jsx("option", { value: option.value, children: option.label }, option.value));
1977
+ }) }), children(Object.assign(Object.assign({}, rest), { id, isDisabled: disabled, onBlur, options: optionsWithCurrentSelectionBackupOption, onChange: handleChange, value: selectedOption, defaultValue: selectedOption }))] }));
1974
1978
  });
1975
1979
 
1976
1980
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "0.0.312",
3
+ "version": "0.0.313",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {