NumberField

A number field is a specialized input that allows a user to enter a number.

Usage

Disabled

A number field in a disabled state shows that an input field exists, but is not available in that circumstance. This can be used to maintain layout continuity and communicate that a field may become available later.

ReadOnly

The isReadOnly prop makes the number field's content immutable. Unlike isDisabled, the number field remains focusable and the contents can still be copied. See the MDN docs for more information.

Sizes

Number fields have multiple sizes to choose from.

Labeling

If a visible label isn't specified, an aria-label must be provided to the number field for accessibility. If the field is labeled by a separate element, an aria-labelledby prop must be provided using the ID of the labeling element instead.

Description

A number field with a helper message.

Icon Prefix

An icon can be displayed at the start of the input.

Text Prefix

A short text can be displayed at the start of the input.

Error

A number field can be displayed in an error state to indicate that the user input is invalid.

Min Max

A number field can have a minimum and maximum value.

Formatting

A number field can be formatted using this format.

Fluid

A number field can take the width of its container.

Props

prefix?

An icon or text to display at the start of the input.

isFluid?

If true, the NumberField will take all available width.

Defaults to false.
inputRef?

A ref for the HTML input element.

inputGroupProps?

The props for the InputGroup.

style?

The inline style for the element. A function may be provided to compute the style based on component state.

validationBehavior?

Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA.

Defaults to 'native'.
formatOptions?

Formatting options for the value displayed in the number field. This also affects what characters are allowed to be typed by the user.

isDisabled?

Whether the input is disabled.

isReadOnly?

Whether the input can be selected but not changed by the user.

isRequired?

Whether user input is required on the input before form submission.

isInvalid?

Whether the input value is invalid.

validate?

A function that returns an error message if a given value is invalid. Validation errors are displayed to the user when the form is submitted if validationBehavior="native". For realtime validation, use the isInvalid prop instead.

autoFocus?

Whether the element should receive focus on render.

value?

The current value (controlled).

defaultValue?

The default value (uncontrolled).

onChange?

Handler that is called when the value changes.

minValue?

The smallest value allowed for the input.

maxValue?

The largest value allowed for the input.

step?

The amount that the input value changes with each increment or decrement "tick".

id?

The element's unique identifier. See MDN.

className?

The CSS className for the element. A function may be provided to compute the class based on component state.

name?

The name of the input element, used when submitting an HTML form. See MDN.

description?

The helper message of the field.

errorMessage?

The error message of the field.

label?

The label of the field.

necessityIndicator?

Whether the required state should be shown as an asterisk or a label, which would display (Optional) on all non required field labels.

size?

A CheckboxGroup can vary in size.

Defaults to md.

Migration Notes

  • Boolean props are now prefixed by is.
  • There is no longer a loading state.
  • icon prop has been renamed to prefix.
  • wrapperProps is not supported.
  • validationState was renamed to isInvalid.
  • min and max props have been renamed to minValue and maxValue.