@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.
|
@@ -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
|
-
//
|
|
31
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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.
|