// @subframe/sync-disable -- local fix: removed hardcoded `value=""` on the inner // so it can be driven controlled (value) OR uncontrolled (defaultValue). The generated // `value=""` (before {...otherProps}) forced controlled-empty whenever no `value` was // passed, breaking defaultValue-only call sites (Phase 0 Subframe migration). // Second local fix (AK-P19): with `showLabel` the root kept its fixed h-9 while label + // gap + input need ~72px, so the input box overflowed the card below (TextInput already // uses the flexible-root/fixed-box pattern). With a label the root is now h-auto and the // input box a fixed h-9 flex item. // Third local fix (AK-P19): the generated stepper chevrons were purely decorative. They // now call stepUp()/stepDown() on the contained input and emit a native `input` event so // React onChange handlers fire. "use client"; /* * Documentation: * Number Input — https://app.subframe.com/f023064a5ca0/library?component=Number+Input_06ebc0c5-994e-4eac-b855-f3c6d7f1bbbf */ import React from "react"; import { FeatherChevronDown } from "@subframe/core"; import { FeatherChevronUp } from "@subframe/core"; import * as SubframeUtils from "../../utils"; export interface StepperProps extends React.HTMLAttributes { down?: boolean; disabled?: boolean; className?: string; } const Stepper = React.forwardRef(function Stepper( { down = false, disabled = false, className, ...otherProps }: StepperProps, ref ) { return (
{down ? ( ) : ( )}
); }); export interface InputProps extends Omit, "placeholder"> { placeholder?: React.ReactNode; className?: string; } const Input = React.forwardRef(function Input( { placeholder, className, ...otherProps }: InputProps, ref ) { return ( ); }); export interface NumberInputRootProps extends React.HTMLAttributes { disabled?: boolean; error?: boolean; variant?: "outline" | "filled"; borderless?: boolean; noPadding?: boolean; size?: "small" | "medium" | "large"; showLabel?: boolean; label?: React.ReactNode; description?: React.ReactNode; children?: React.ReactNode; className?: string; } const NumberInputRoot = React.forwardRef( function NumberInputRoot( { disabled = false, error = false, variant = "outline", borderless = false, noPadding = false, size = "medium", showLabel = false, label, description, children, className, ...otherProps }: NumberInputRootProps, ref ) { const boxRef = React.useRef(null); const generatedLabelId = React.useId(); const inputLabelId = showLabel && label ? generatedLabelId : undefined; // Steps the contained native number input and notifies React listeners. const stepBy = (direction: "up" | "down") => { if (disabled) return; const input = boxRef.current?.querySelector("input"); if (!input || input.disabled || input.readOnly) return; if (direction === "up") input.stepUp(); else input.stepDown(); input.dispatchEvent(new Event("input", { bubbles: true })); input.focus(); }; return (
{label ? ( {label} ) : null} {description ? ( {description} ) : null}
{children ? (
{React.Children.map(children, (child) => { if (!inputLabelId || !React.isValidElement(child)) return child; if (child.props["aria-label"] || child.props["aria-labelledby"]) return child; return React.cloneElement(child, { "aria-labelledby": inputLabelId }); })}
) : null}
stepBy("up")} />
stepBy("down")} />
); } ); export const NumberInput = Object.assign(NumberInputRoot, { Stepper, Input, });