Search docs

Number Input

Numeric text field with increment/decrement triggers and locale-aware formatting.

Number Input implements the WAI-ARIA APG Spinbutton pattern, providing keyboard stepping, Intl.NumberFormat formatting and parsing, clamping, and form reset support.

import { component$, useStyles$ } from '@builder.io/qwik';
import { NumberInput } from '@leve-ui/number-input';
import { LuMinus, LuPlus } from '@qwikest/icons/lucide';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);

  return (
    <NumberInput.Root defaultValue={1} class="number-input-default">
      <NumberInput.DecrementTrigger
        class="number-input-default-trigger"
        aria-label="Decrement quantity"
      >
        <LuMinus class="number-input-default-icon" aria-hidden="true" />
      </NumberInput.DecrementTrigger>
      <NumberInput.Input class="number-input-default-input" aria-label="Quantity" />
      <NumberInput.IncrementTrigger
        class="number-input-default-trigger"
        aria-label="Increment quantity"
      >
        <LuPlus class="number-input-default-icon" aria-hidden="true" />
      </NumberInput.IncrementTrigger>
    </NumberInput.Root>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/number-input

Anatomy#

import { NumberInput } from '@leve-ui/number-input'; // or '@leve-ui/core'

<NumberInput.Root>
  <NumberInput.DecrementTrigger>-</NumberInput.DecrementTrigger>
  <NumberInput.Input />
  <NumberInput.IncrementTrigger>+</NumberInput.IncrementTrigger>
</NumberInput.Root>
PartElementDescription
NumberInput.Root<div>Wraps the parts, manages the numeric state, and provides context.
NumberInput.Input<input>Spinbutton text input (role="spinbutton", inputMode="decimal").
NumberInput.IncrementTrigger<button>Button (tabIndex={-1}) that increments the value by step.
NumberInput.DecrementTrigger<button>Button (tabIndex={-1}) that decrements the value by step.

Examples#

Controlled#

Control the numeric value with bind:value.

Value: 10

Min, Max, and Step#

Configure min, max, step, and largeStep (for PageUp / PageDown).

Formatted#

Pass locale and formatOptions (such as currency or percentage) to format and parse numbers with Intl.NumberFormat.

Disabled#

disabled on the Root disables both the input and the trigger buttons.

Read Only#

readOnly prevents editing and stepping while keeping the input focusable.

With Field#

Inside a Field.Root, Field.Label, Field.Description, Field.ErrorMessage, and the disabled / readOnly / required / invalid states are wired automatically.

Choose between 1 and 10 seats.

With Form#

Works with native <form> submission and resets to defaultValue on <form> reset.

Submitted: None

API Reference#

Root#

PropDefaultType
ids–{ input?: string }

Overrides the element IDs of the parts. Only used outside a Field.

defaultValuenullnumber | null

The initial numeric value (uncontrolled).

bind:value–Signal<number | null>

A signal with the numeric value (controlled).

onValueChange$–QRL<(value: number | null) => void>

Called when the numeric value changes.

min–number

Minimum allowed value.

max–number

Maximum allowed value.

step1number

Amount to increment or decrement on ArrowUp / ArrowDown or trigger click.

largeStepstep * 10number

Amount to increment or decrement on PageUp / PageDown.

locale'en-US'string

BCP 47 locale tag used by Intl.NumberFormat for formatting and parsing.

formatOptions–Intl.NumberFormatOptions

Formatting options passed to Intl.NumberFormat.

clampValueOnBlurtrueboolean

Whether to clamp out-of-range typed values to [min, max] on blur or Enter.

disabledfalseboolean

Disables the input and trigger buttons. Inside a Field or Fieldset, inherited disabled also applies.

readOnlyfalseboolean

Marks the number input as read-only. Inside a Field, the Field's readOnly also applies.

requiredfalseboolean

Marks the number input as required. Inside a Field, the Field's required also applies.

invalidfalseboolean

Marks the number input as invalid. Inside a Field, the Field's invalid also applies.

Also accepts all <div> attributes.

Data attributeValue
data-leve-number-inputAlways present
data-state"empty" | "filled"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

The numeric value is uncontrolled with defaultValue, or controlled with bind:value. onValueChange$ is called when the committed value changes.

Inside a Field, the input ID comes from the Field and ids is ignored (ADR 0024).

Input#

No props of its own. Accepts all <input> attributes.

Data attributeValue
data-leve-number-input-inputAlways present
data-state"empty" | "filled"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

IncrementTrigger#

No props of its own. Accepts all <button> attributes.

Data attributeValue
data-leve-number-input-increment-triggerAlways present
data-disabledPresent when disabled, read-only, or at max

DecrementTrigger#

No props of its own. Accepts all <button> attributes.

Data attributeValue
data-leve-number-input-decrement-triggerAlways present
data-disabledPresent when disabled, read-only, or at min

Accessibility#

Follows the WAI-ARIA APG Spinbutton pattern.

  • Provide an accessible name for NumberInput.Input via Field.Label, aria-label, or aria-labelledby.
  • NumberInput.Input sets role="spinbutton", aria-valuenow, aria-valuemin, aria-valuemax, and aria-valuetext (when the formatted text differs from the plain number string).
  • IncrementTrigger and DecrementTrigger are excluded from the tab order (tabIndex={-1}) and prevent mousedown default so clicking them keeps focus on the input. They default aria-label to "Increment" and "Decrement".

Keyboard Interactions#

KeyDescription
ArrowUpIncrements the value by step.
ArrowDownDecrements the value by step.
PageUpIncrements the value by largeStep.
PageDownDecrements the value by largeStep.
HomeSets the value to min (when min is defined).
EndSets the value to max (when max is defined).
EnterParses, clamps (if clampValueOnBlur is true), commits, and formats the input value.