@martinsura/ui 0.1.9 → 0.1.10

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/dist/index.cjs CHANGED
@@ -532,8 +532,18 @@ var NumberInput = ({
532
532
  const resolvedErrors = props.errorName ? resolveError(props.errorName) : [];
533
533
  const errorDisplay = props.error ?? props.customError ?? (resolvedErrors.length > 0 ? resolvedErrors.join(", ") : void 0);
534
534
  const hasError = !!errorDisplay;
535
+ const [internalValue, setInternalValue] = react.useState(
536
+ props.value != null ? String(props.value) : ""
537
+ );
538
+ const isFocused = react.useRef(false);
539
+ react.useEffect(() => {
540
+ if (!isFocused.current) {
541
+ setInternalValue(props.value != null ? String(props.value) : "");
542
+ }
543
+ }, [props.value]);
535
544
  const handleChange = (e) => {
536
545
  const raw = e.target.value;
546
+ setInternalValue(raw);
537
547
  if (raw === "" || raw === "-") {
538
548
  props.onChange?.(null);
539
549
  return;
@@ -543,6 +553,13 @@ var NumberInput = ({
543
553
  props.onChange?.(num);
544
554
  }
545
555
  };
556
+ const handleFocus = () => {
557
+ isFocused.current = true;
558
+ };
559
+ const handleBlur = () => {
560
+ isFocused.current = false;
561
+ setInternalValue(props.value != null ? String(props.value) : "");
562
+ };
546
563
  return /* @__PURE__ */ jsxRuntime.jsxs(InputField, { noMargin: props.noMargin, className: props.className, children: [
547
564
  props.label && /* @__PURE__ */ jsxRuntime.jsx(
548
565
  InputLabel,
@@ -558,11 +575,13 @@ var NumberInput = ({
558
575
  {
559
576
  type: "number",
560
577
  placeholder: props.placeholder,
561
- value: props.value ?? "",
578
+ value: internalValue,
562
579
  disabled: props.disabled,
563
580
  min: props.min,
564
581
  max: props.max,
565
582
  onChange: handleChange,
583
+ onFocus: handleFocus,
584
+ onBlur: handleBlur,
566
585
  className: tailwindMerge.twMerge(
567
586
  numberInputClass,
568
587
  inputSizeClasses[size],