FormatInput

pro

FormatInput formats numeric entry as the user types, with numeric, pattern-mask, and custom-format variants over the shared Input.

Installation

Add this component with the NateUI CLI.

npx nateui@latest add FormatInput

Examples

Numeric Formats

Value: — — the $ became part of the text
kgValue: — — the icon and “kg” are decoration only

Custom Format

Controlled

Raw value: 1200

API

FormatInput.Numeric, FormatInput.Pattern, and FormatInput.Custom each wrap a react-number-format primitive over the shared Input surface. All three take inputPrefix/inputSuffix instead of Input's own prefix/suffix, because Numeric and Custom already use prefix/suffix for text that's baked into the formatted value itself.

FormatInput.Numeric

PropDescriptionTypeDefault
valueControlled numeric value.number | string | null—
defaultValueInitial value for uncontrolled usage.number | string | null—
onValueChangeFires with the parsed float, raw digits, and formatted string whenever the value changes.(values: NumberFormatValues, sourceInfo: SourceInfo) => void—
thousandSeparatorCharacter used to group digits, or true for a comma.boolean | string—
decimalSeparatorCharacter shown before the decimal digits.string'.'
decimalScaleNumber of digits kept after the decimal separator.number—
fixedDecimalScalePads with trailing zeros to always show decimalScale digits.booleanfalse
allowNegativeAllows a leading minus sign.booleantrue
allowLeadingZerosKeeps leading zeros instead of stripping them.booleanfalse
thousandsGroupStyleDigit grouping convention.'thousand' | 'lakh' | 'wan' | 'none''thousand'
prefixText baked into the formatted value, before the digits (for example '$').string—
suffixText baked into the formatted value, after the digits (for example '%').string—
stepperReplaces the suffix slot with built-in increment/decrement buttons. Requires controlled value + onValueChange; the buttons have no effect with only defaultValue.booleanfalse
minLowest value the stepper buttons will reach.number0
maxHighest value the stepper buttons will reach.numberInfinity
stepAmount each stepper click adds or subtracts.number1
inputPrefixDecorative content in Input's prefix slot; not part of the value.string | ReactNode—
inputSuffixDecorative content in Input's suffix slot; not part of the value. Ignored when stepper is true.string | ReactNode—
sizeControl size.ControlSize'md'
disabledPrevents editing and applies disabled control styling.boolean—
...restRemaining NumericFormat props from react-number-format, plus native input attributes.NumericFormatProps—

FormatInput.Pattern

PropDescriptionTypeDefault
formatPattern string where each patternChar is a fillable digit slot (for example '(###) ###-####').string—
maskPlaceholder character shown in empty digit slots, or one character per slot.string | string[]—
patternCharCharacter in format that marks a fillable slot.string'#'
allowEmptyFormattingShows the literal pattern characters even before any digit is entered.booleanfalse
valueControlled value.string | number | null—
defaultValueInitial value for uncontrolled usage.string | number | null—
onValueChangeFires with the parsed digits and formatted string whenever the value changes.(values: NumberFormatValues, sourceInfo: SourceInfo) => void—
inputPrefixDecorative content in Input's prefix slot.string | ReactNode—
inputSuffixDecorative content in Input's suffix slot.string | ReactNode—
sizeControl size.ControlSize'md'
disabledPrevents editing and applies disabled control styling.boolean—
...restRemaining PatternFormat props from react-number-format, plus native input attributes.PatternFormatProps—

FormatInput.Custom

PropDescriptionTypeDefault
formatTransforms raw characters into the displayed string.(value: string) => stringidentity
removeFormattingStrips a formatted string back to raw characters, typically while editing.(value: string, changeMeta?: ChangeMeta) => stringdigits-only
getCaretBoundaryMarks which caret positions are safe to land on inside the formatted string.(formattedValue: string) => boolean[]numeric-boundary heuristic
valueControlled value.string | number | null—
defaultValueInitial value for uncontrolled usage.string | number | null—
onValueChangeFires with the parsed value and formatted string whenever the value changes.(values: NumberFormatValues, sourceInfo: SourceInfo) => void—
inputPrefixDecorative content in Input's prefix slot.string | ReactNode—
inputSuffixDecorative content in Input's suffix slot.string | ReactNode—
sizeControl size.ControlSize'md'
disabledPrevents editing and applies disabled control styling.boolean—
...restRemaining NumberFormatBase props from react-number-format, plus native input attributes.NumberFormatBaseProps—

NumericFormatProps, PatternFormatProps, and NumberFormatBaseProps are react-number-format's own types; see the library's docs for its full option list.

Types

type NumberFormatValues = {
  floatValue: number | undefined;
  formattedValue: string;
  value: string;
};
 
type SourceInfo = {
  event?: SyntheticEvent<HTMLInputElement>;
  source: 'event' | 'prop';
};
 
type ChangeMeta = {
  from: { start: number; end: number };
  to: { start: number; end: number };
  lastValue: string;
};
 
type ControlSize = 'sm' | 'md' | 'lg';