Skip to content

NumberField

Stable

A number box with minus and plus buttons, keyboard stepping, limits and an optional unit.

Also known as number input, numeric input, stepper input, spin button

Install with npm install @tattva/ui (setup), or copy the code from the kit in Downloads.

Quantity with limits

lots

The buttons stop at 1 and 50. Type a number and press Enter or leave the box to apply it.

When to use it

A number the user may know exactly (type it) or want to nudge (step it), such as a quantity or a price, with limits that are enforced for them.

Made of: Decrease button · Number · Unit · Increase button

Use it for

  • A quantity, count or size with a minimum and maximum.
  • A price or other decimal value with a fixed number of places.
  • A value with a unit shown after it.

Not for

  • Digits that are not a quantity, like a phone number or a code: use TextField.
  • A choice between a few named options: use SegmentedControl.
  • Picking from a list of named values: use Select.

Do and avoid

Do. A small count that people step up or down.
Avoid. A phone number is not a count, so the steppers make no sense.

Do

  • Set min and max when the number has real limits.
  • Set precision for money or other fixed decimals.
  • Use unit instead of putting the unit in the label alone.
  • Say the limits in a hint, so people know them before they hit one.

Avoid

  • Do not use it for phone numbers, codes or ids. Use TextField.
  • Do not use it for a huge range where stepping is useless.
  • Do not expect onChange on every key press. Typing is applied on blur and Enter.
  • Do not rely on the buttons alone. The buttons are skipped by the Tab key, because the arrow keys do the same job.

On a phone

  • The box is 44px tall and the minus and plus buttons are at least 44px wide on touch screens.
  • Typing opens the decimal keypad when the minimum is 0 or more, and otherwise the normal keyboard, and the value is checked on Enter or when the field loses focus, so tell users to tap away to confirm.
  • When the minimum is below 0 the field uses the normal keyboard so a minus can be typed; the minus and plus buttons work either way.

Build your next AI screen with Tattva.

Free and open, with the code. Start in one line.

Get started