NumberInput

core package3.2.2

Note: All components shown on this site are supported by the Constellation design system. To learn how to configure Theme Cosmos, visit Pega Community.

The NumberInput component allows the user to enter numerical data. Any other characters will be ignored. NumberInputs are auto-formatted according to locale, while the user types. You can configure the locale of your application via the Configuration component. If you require a user to select a number from a defined range, you should consider using the Slider component instead.

Usage

The NumberInput component can either show or hide decimals while inserting input via the showDecimal prop. If decimals are shown, you can limit the maximum number of decimals to show via the numberOfDecimals prop. You can also disable the default locale supported group separators by passing false to showGroupSeparators. You may also include a unit to display within the input Field.

The NumberInput component allows for manual entry of numerical values as well as native support of the up and down arrow keys to increase or decrease the current value. The arrow keys will modify the value by multitudes of the provided step, or 1 by default. The component also allows for standard Form Field structures such as being set required, disabled, or readOnly, as well as including a label, status, or info. If an onResolveSuggestion callback function is provided, and the status is set to pending, the user will be prompted to accept or deny whatever suggested value populates the NumberInput.

If there is a label and the Field is not disabled, passing an object to the additionalInfo prop that includes a heading and content will provide the user with more useful information on the Field when they click on the associated information Icon.

Example

Enter a numerical value

Stepper variant

The NumberInput can also take a stepper variant that behaves identically to the NumberInput except that the input is centered with decremental and incremental actions on either end. These actions mimic the role of the up and down keys.

Example

Enter a numerical value

Related components

Properties

NameDescriptionDefaultType
onChange*(value: string) => void
additionalInfoButton when clicked will show additional information
{
  content: string | Element;
  heading: string;
}
aria-labelOptional manual override for generated aria labelstring
autoFocusAutomatically focuses the input on render.boolean
classNameAdditional CSS classes.string
disabledDisable the control. The browser defaults to false.boolean
idSets DOM id for the control and associates label element via 'for' attribute. If an id is not pass, a random id will be generated for any render.string
infoIt is recommended to pass a simple string to offer guidance. Text will be styled based on status prop.ReactNode
labelPass a string or a fragment with an Icon and string.ReactNode
labelHiddenVisually hides the label region.falseboolean
maxThe maximum value to accept for this input. This value must be greater than or equal to the value of the min attribute.Number.MAX_SAFE_INTEGERnumber
minThe minimum value to accept for this input. This value must be less than or equal to the value of the max attribute.Number.MIN_SAFE_INTEGERnumber
nameSets html name attribute for the underlying control. Useful for mapping to a data field.string
numberOfDecimalsDetermines the maximum number of decimal places. The value is rounded to the number of places.variable NUMBER_MAX_DECIMAL_PLACES. Recommended minimum: 1.number
onBlur(value: string) => void
onFocus(value: string) => void
onResolveSuggestion(accepted: boolean) => void
placeholderPlaceholder text. The browser defaults to an empty string.string
readOnlyMakes the component non editable and non clickable. The browser defaults to false.boolean
refRef for the wrapping element.Ref<HTMLInputElement>
requiredIndicate if the field is required. The browser defaults to false.boolean
showDecimal/** Determines whether decimal places should be shown. The value is rounded if true.trueboolean
showGroupSeparatorsDetermines whether group separators should be shown.trueboolean
statusSet visual state based on a validation state.
'error' |'pending' |'success' |'warning' 
stepA stepping interval to use when using up and down arrows to adjust the value.1number
unitDefines unit of the number, like 'kg', 'miles' or '%'.string
valueCurrencyInput input value. Requires an onChange handler to update value.string
variantComponent variation. Might be rendered as regular input or stepper.'default'
'default' |'stepper'