@vectara/vectara-ui 15.6.5 → 15.7.0

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.
@@ -5,4 +5,5 @@ export declare const VuiNumberInput: import("react").ForwardRefExoticComponent<O
5
5
  max?: number | undefined;
6
6
  min?: number | undefined;
7
7
  step?: number | undefined;
8
+ allowUndefined?: boolean | undefined;
8
9
  } & import("react").RefAttributes<HTMLInputElement | null>>;
@@ -13,7 +13,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { forwardRef, useEffect, useState } from "react";
14
14
  import { VuiBasicInput } from "./BasicInput";
15
15
  export const VuiNumberInput = forwardRef((_a, ref) => {
16
- var { value, onChange, max, min, step } = _a, rest = __rest(_a, ["value", "onChange", "max", "min", "step"]);
16
+ var { value, onChange, max, min, step, allowUndefined } = _a, rest = __rest(_a, ["value", "onChange", "max", "min", "step", "allowUndefined"]);
17
17
  const [localValue, setLocalValue] = useState(value);
18
18
  // This is a hacky solution to the number input misbehaving on Firefox.
19
19
  // If we were to apply the value and onChange values directly to the
@@ -26,17 +26,21 @@ export const VuiNumberInput = forwardRef((_a, ref) => {
26
26
  // For some reason, using a useState hook to store the value doesn't have
27
27
  // this problem.
28
28
  useEffect(() => {
29
- // Reflect the upstream value when it changes. Ignore 0
30
- // because that indicates the user has entered a decimal point.
31
- if (value !== 0) {
29
+ // Reflect the upstream value when it changes. Ignore 0 because that
30
+ // indicates the user has entered a decimal point (Firefox workaround).
31
+ // When allowUndefined is on, also ignore undefined — otherwise the
32
+ // parent reflecting undefined back would clear the input mid-typing.
33
+ const isUndefined = !(allowUndefined && value === undefined);
34
+ if (value !== 0 && isUndefined) {
32
35
  setLocalValue(value);
33
36
  }
34
37
  }, [value]);
35
- // Part of the hacky solution above.
38
+ // Propagate localValue changes upstream. Without allowUndefined, an
39
+ // undefined localValue (empty input) is coerced to 0 so existing
40
+ // consumers always receive a number. With allowUndefined, undefined
41
+ // passes through so consumers can treat empty as "no value."
36
42
  useEffect(() => {
37
- // Set value locally so an undefined value doesn't reset it to 0.
38
- // Pass the value upstream, e.g. so it can be persisted.
39
- onChange(localValue !== null && localValue !== void 0 ? localValue : 0);
43
+ onChange(allowUndefined ? localValue : localValue !== null && localValue !== void 0 ? localValue : 0);
40
44
  }, [localValue]);
41
45
  const onChangeValue = (e) => {
42
46
  // Enable resetting the value to undefined.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectara/vectara-ui",
3
- "version": "15.6.5",
3
+ "version": "15.7.0",
4
4
  "homepage": "./",
5
5
  "description": "Vectara's design system, codified as a React and Sass component library",
6
6
  "author": "Vectara",