Skip to main content
Kaleidoscope

NumberInput

Allow users to input numbers, currencies, and anything number-like that is internally stored as a plain number.

Default

An input for numerical values.

Editable example

Best practices

  1. It's preferable to use a NumberInput over a <TextInput type="number" /> for consistency of ergonomics when inputting numbers.
  2. Provide a visual label unless the purpose of the input is communicated or implied from its context, in which case a label still must be provided but can be hidden visually using the labelHidden prop.
  3. Avoid mixing and matching sizes. If a medium sized NumberInput is used, don't use a large SegmentedControl next to it.

Format and parse value

Define how the number is formatted and parsed in the input, useful for cases like currency inputs. You can use the formatValue prop to define how the number gets formatted into a string within the input. If you need to parse the internal value back to a number in a particular way different to the default you can use the parseValue prop as well.

Editable example

Min and max

Use the error prop to communicate invalid inputs to the user. Avoid displaying validation as the user is typing. The preferred interaction is to validate on blur if the user has typed something. Any errors should also be displayed on inputs when a form is attempted to be submitted.

Editable example

Step and snap

Define how much to increment by, and whether to snap to the nearest multiple of that increment with step and snap props. By default, number inputs will step by 1.

Editable example

Hide stepper

Hide the stepper arrow buttons.

Editable example

Label

Use a label to indicate what the number is for e.g. Quantity, Price etc. If the purpose of the input is communicated by its context, the labelHidden prop can be used to hide it visually but keep it accessible by assistive technology.

Editable example

Size

Use larger sizes for forms and smaller sizes for contextual or compact interfaces. Typically all inputs in a given context should all share a consistent size between them.

Editable example

Theme

Use the dark theme when placed on a dark surface such as a dark popover or card.

Editable example

Start/end elements

The startElement and endElement props take any ReactNode. This is useful for placing an icon or button at the start/end of an input. The size of the element will automatically adjust the padding inside the input so that the text won't be overlapped by the elements.

Editable example

Variants

In most cases the default bordered input should be used. For standalone inputs that are part of smaller or tightly packed components (such as an image card overlay or within a navbar) the Underlined variant works best. Use the Borderless variant in areas where the input needs to seamlessly fit within another component, for example an input that sits within a Toolbar.

Editable example

Disabled

Use the disabled prop to communicate that an input exists, but cannot be interacted with.

Editable example

Accessibility

  • Always provide a descriptive label even when using the labelHidden prop. This will be read by screen readers when the input is focused even when it's not visibly shown.