View as Markdown

API reference: @salmonui/inputs/number-field

NumberFieldcomponent

import { NumberField } from '@salmonui/inputs/number-field';
function NumberField(props: NumberFieldProps): ReactNode;

Numeric input: a text input with role="spinbutton", formatted with Intl.NumberFormat (or a Data Grid format preset) when blurred and shown raw while focused. A hidden input with name submits the number. ref is the visible input.

Props: NumberFieldProps

NumberField props (30)
NameSignatureDescription
labeloptionalinheritedlabel?: ReactNode;
descriptionoptionalinheriteddescription?: ReactNode;
errorMessageoptionalinheritederrorMessage?: ((ctx: { readonly errors: readonly string[]; }) => ReactNode) | ReactNode;

Error text (or a function of the errors) shown while the field is invalid.

invalidoptionalinheritedinvalid?: boolean;

Forces the error state.

validationoptionalinheritedvalidation?: FieldValidation;

Rules in the Data Grid vocabulary.

validateOnoptionalinheritedvalidateOn?: ValidateOn;

When errors appear; default the Form's, else 'blur'.

sizeoptionalinheritedsize?: FieldSize;

Metric set. Default 'md'.

valueoptionalreadonly value?: number | null | undefined;
defaultValueoptionalreadonly defaultValue?: number | null | undefined;
onValueChangeoptionalreadonly onValueChange?: ((value: number | null, details: NumberChangeDetails) => void) | undefined;
minoptionalreadonly min?: number | undefined;
maxoptionalreadonly max?: number | undefined;
stepoptionalreadonly step?: number | undefined;

Arrow keys and the stepper change the value by step; Page keys by ten steps. Default 1.

showStepperoptionalreadonly showStepper?: boolean | undefined;

Increment and decrement buttons. Default true.

formatOptionsoptionalreadonly formatOptions?: Intl.NumberFormatOptions | undefined;

Intl.NumberFormat options of the blurred text.

formatoptionalreadonly format?: string | undefined;

A Data Grid column.format preset or pattern instead ('n2', 'C2', 'P1', '#,##0.00').

currencyoptionalreadonly currency?: string | undefined;

ISO 4217 code for currency formats.

localeoptionalreadonly locale?: string | undefined;

BCP 47 locale for formatting and parsing. Default 'en-US'; the host locale is never read.

decimalsoptionalreadonly decimals?: number | undefined;

Fraction digits the committed value is rounded to.

restrictDecimalsoptionalreadonly restrictDecimals?: boolean | undefined;

Refuses typing more fraction digits than decimals.

clampBehavioroptionalreadonly clampBehavior?: 'blur' | 'none' | undefined;

'blur' (default) clamps to min / max on blur; 'none' keeps the value and reports the range error.

incrementOnWheeloptionalreadonly incrementOnWheel?: boolean | undefined;

Mouse wheel over the focused field steps the value. Default false.

clearableoptionalreadonly clearable?: boolean | undefined;
startAdornmentoptionalreadonly startAdornment?: ReactNode;
endAdornmentoptionalreadonly endAdornment?: ReactNode;
localeTextoptionalreadonly localeText?: NumberFieldLocaleText | undefined;
classNameoptionalreadonly className?: string | undefined;
styleoptionalreadonly style?: CSSProperties | undefined;
classNamesoptionalreadonly classNames?: { readonly group?: string; readonly input?: string; readonly label?: string; readonly description?: string; readonly error?: string; readonly stepper?: string; } | undefined;
refoptionalreadonly ref?: Ref<HTMLInputElement> | undefined;

The native <input>.