@trackunit/react-form-components 1.6.33 → 1.7.1

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
@@ -1129,7 +1129,40 @@ const validateNumber = (number, required = false, min, max) => {
1129
1129
  * NOTE: If shown with a label, please use the `NumberField` component instead.
1130
1130
  */
1131
1131
  const NumberInput = ({ ref, ...rest }) => {
1132
- return jsxRuntime.jsx(BaseInput, { ref: ref, type: "number", ...rest, value: rest.value });
1132
+ const inputElementRef = react.useRef(null);
1133
+ const preventDefaultWheelEvent = react.useCallback((event) => {
1134
+ const inputElement = inputElementRef.current;
1135
+ const activeElement = document.activeElement;
1136
+ if (inputElement && activeElement === inputElement) {
1137
+ event.preventDefault();
1138
+ }
1139
+ }, []);
1140
+ const forwardAndStoreInputRef = react.useCallback((node) => {
1141
+ const previousNode = inputElementRef.current;
1142
+ if (previousNode) {
1143
+ previousNode.removeEventListener("wheel", preventDefaultWheelEvent);
1144
+ }
1145
+ inputElementRef.current = node;
1146
+ if (node) {
1147
+ // NOTE: Prevent the default browser behavior of changing the value via mouse wheel
1148
+ node.addEventListener("wheel", preventDefaultWheelEvent, { passive: false });
1149
+ }
1150
+ if (typeof ref === "function") {
1151
+ ref(node);
1152
+ }
1153
+ else if (ref && typeof ref === "object") {
1154
+ ref.current = node;
1155
+ }
1156
+ }, [preventDefaultWheelEvent, ref]);
1157
+ react.useEffect(() => {
1158
+ return () => {
1159
+ const element = inputElementRef.current;
1160
+ if (element) {
1161
+ element.removeEventListener("wheel", preventDefaultWheelEvent);
1162
+ }
1163
+ };
1164
+ }, [preventDefaultWheelEvent]);
1165
+ return jsxRuntime.jsx(BaseInput, { ref: forwardAndStoreInputRef, type: "number", ...rest, value: rest.value });
1133
1166
  };
1134
1167
  NumberInput.displayName = "NumberInput";
1135
1168
 
@@ -2159,6 +2192,13 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, setMenuIsEna
2159
2192
  const tags = key === PLACEHOLDER_KEY ? [] : values;
2160
2193
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
2161
2194
  const searchInput = props && props.children && props.children[1];
2195
+ const placeholderElement = Array.isArray(props.children)
2196
+ ? props.children.find(child => child && child.key === "placeholder")
2197
+ : null;
2198
+ const shouldShowPlaceholder = !!placeholderElement && tags?.length === 0;
2199
+ if (shouldShowPlaceholder) {
2200
+ return (jsxRuntime.jsx(ReactSelect.components.ValueContainer, { ...props, isDisabled: props.selectProps.isDisabled, children: props.children }));
2201
+ }
2162
2202
  return (jsxRuntime.jsx(ReactSelect.components.ValueContainer, { ...props, isDisabled: props.selectProps.isDisabled, children: maxSelectedDisplayCount === undefined ? (jsxRuntime.jsx(TagsContainer, { disabled: disabled, items: tags
2163
2203
  ? tags.map(({ props: tagProps }) => {
2164
2204
  return {
package/index.esm.js CHANGED
@@ -1128,7 +1128,40 @@ const validateNumber = (number, required = false, min, max) => {
1128
1128
  * NOTE: If shown with a label, please use the `NumberField` component instead.
1129
1129
  */
1130
1130
  const NumberInput = ({ ref, ...rest }) => {
1131
- return jsx(BaseInput, { ref: ref, type: "number", ...rest, value: rest.value });
1131
+ const inputElementRef = useRef(null);
1132
+ const preventDefaultWheelEvent = useCallback((event) => {
1133
+ const inputElement = inputElementRef.current;
1134
+ const activeElement = document.activeElement;
1135
+ if (inputElement && activeElement === inputElement) {
1136
+ event.preventDefault();
1137
+ }
1138
+ }, []);
1139
+ const forwardAndStoreInputRef = useCallback((node) => {
1140
+ const previousNode = inputElementRef.current;
1141
+ if (previousNode) {
1142
+ previousNode.removeEventListener("wheel", preventDefaultWheelEvent);
1143
+ }
1144
+ inputElementRef.current = node;
1145
+ if (node) {
1146
+ // NOTE: Prevent the default browser behavior of changing the value via mouse wheel
1147
+ node.addEventListener("wheel", preventDefaultWheelEvent, { passive: false });
1148
+ }
1149
+ if (typeof ref === "function") {
1150
+ ref(node);
1151
+ }
1152
+ else if (ref && typeof ref === "object") {
1153
+ ref.current = node;
1154
+ }
1155
+ }, [preventDefaultWheelEvent, ref]);
1156
+ useEffect(() => {
1157
+ return () => {
1158
+ const element = inputElementRef.current;
1159
+ if (element) {
1160
+ element.removeEventListener("wheel", preventDefaultWheelEvent);
1161
+ }
1162
+ };
1163
+ }, [preventDefaultWheelEvent]);
1164
+ return jsx(BaseInput, { ref: forwardAndStoreInputRef, type: "number", ...rest, value: rest.value });
1132
1165
  };
1133
1166
  NumberInput.displayName = "NumberInput";
1134
1167
 
@@ -2158,6 +2191,13 @@ const useCustomComponents = ({ componentsProps, disabled, readOnly, setMenuIsEna
2158
2191
  const tags = key === PLACEHOLDER_KEY ? [] : values;
2159
2192
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
2160
2193
  const searchInput = props && props.children && props.children[1];
2194
+ const placeholderElement = Array.isArray(props.children)
2195
+ ? props.children.find(child => child && child.key === "placeholder")
2196
+ : null;
2197
+ const shouldShowPlaceholder = !!placeholderElement && tags?.length === 0;
2198
+ if (shouldShowPlaceholder) {
2199
+ return (jsx(components.ValueContainer, { ...props, isDisabled: props.selectProps.isDisabled, children: props.children }));
2200
+ }
2161
2201
  return (jsx(components.ValueContainer, { ...props, isDisabled: props.selectProps.isDisabled, children: maxSelectedDisplayCount === undefined ? (jsx(TagsContainer, { disabled: disabled, items: tags
2162
2202
  ? tags.map(({ props: tagProps }) => {
2163
2203
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-components",
3
- "version": "1.6.33",
3
+ "version": "1.7.1",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -18,7 +18,7 @@
18
18
  "react-hook-form": "7.62.0",
19
19
  "tailwind-merge": "^2.0.0",
20
20
  "@trackunit/css-class-variance-utilities": "1.6.23",
21
- "@trackunit/react-components": "1.7.31",
21
+ "@trackunit/react-components": "1.7.32",
22
22
  "@trackunit/ui-icons": "1.6.22",
23
23
  "@trackunit/shared-utils": "1.8.23",
24
24
  "@trackunit/ui-design-tokens": "1.6.24",