Skip to content
Nana UI

Forms & Inputs

Number Input

A numeric field with its own increment and decrement controls, bounded by min, max and step.

View .md Download

A numeric field with its own stepper buttons. The value is held as text while you type, so a half-entered number survives; it is clamped and rounded once the field is left.

npm install @nana-tec/ui-components
import "@nana-tec/ui-components/number-input";

min and max close the range. The button that would do nothing is disabled rather than silently ignored, so the limit is visible before it is hit.

step sets how far one move travels. Decimal steps keep their precision rather than drifting — stepping 0.1 by 0.2 lands on 0.3, not 0.30000000000000004.

Set precision to fix the number of decimal places kept when stepping and on blur.

Typing is left alone until focus leaves. Enter 42 into a field capped at 10 and it stays 42 while you are in it, then settles to 10. Text that is not a number is cleared the same way.

KeyResult
↑One step up
↓One step down

Properties

PropertyAttributeTypeDefaultDescription
disableddisabledbooleanfalse
helperhelperstring''Line under the field.
labellabelstring''Visible label.
maxmaxnumber | undefined—Largest accepted value.
minminnumber | undefined—Smallest accepted value.
namenamestring''
placeholderplaceholderstring''
precisionprecisionnumber | undefined—Decimal places kept when stepping and on blur.
readonlyreadonlybooleanfalse
requiredrequiredbooleanfalse
stepstepnumber1How far one step moves.
valuevaluestring''The field's text, so a partially typed number is not thrown away.

Events

EventDescription
nana-inputWhile typing; detail: { value: number | undefined }
nana-changeOnce the value settles; detail: { value: number | undefined }

CSS parts

PartDescription
::part(base)The field wrapper
::part(input)The text field
::part(decrement)The decrement button
::part(increment)The increment button
::part(label)The field label
::part(helper)The helper or error line

CSS custom properties

PropertyDescription
--nana-number-input-bgField background
--nana-number-input-colorField text colour
--nana-number-input-radiusCorner radius
--nana-number-input-border-colorBorder colour
--nana-number-input-heightField height
--nana-number-input-button-widthWidth of each stepper button
EventTypeDescription
nana-inputCustomEventWhile typing; detail.value is the number, or undefined.
nana-changeCustomEventOnce the value settles; detail.value is the number, or undefined.

The field is a spinbutton carrying aria-valuenow, aria-valuemin and aria-valuemax. The stepper buttons are labelled and kept out of the tab order, so a keyboard reaches the value directly and moves it with the arrow keys.

  • Input — a single free-text field
  • Range — the same bounded value as a slider