NumberField

Alpha

An accessible numeric input with increment/decrement buttons, min/max/step constraints, and precision control.

Import

import { NumberField } from "@compa11y/react";

Usage

Example.tsx
import { useState } from "react";
import { NumberField, Text } from "@compa11y/react";

function QuantityPicker() {
  const [qty, setQty] = useState(1);

  return (
    <NumberField
      value={qty}
      onValueChange={setQty}
      min={1}
      max={99}
      label="Quantity"
    />
  );
}

function PriceInput() {
  const [price, setPrice] = useState(9.99);

  return (
    <NumberField
      value={price}
      onValueChange={setPrice}
      min={0}
      step={0.01}
      precision={2}
      label="Price ($)"
    />
  );
}

Features

  • role='spinbutton' with aria-valuemin, aria-valuemax, aria-valuenow
  • Increment/decrement stepper buttons
  • Min, max, and step constraints
  • Decimal precision control
  • Keyboard: Arrow Up/Down to increment/decrement
  • Screen reader announcements for value changes

Props

NumberField component props
PropTypeDefaultDescription
valuenumber-Controlled value
onValueChange(value: number) => void-Called when value changes
minnumber-Minimum value
maxnumber-Maximum value
stepnumber1Step increment
precisionnumber-Number of decimal places
disabledbooleanfalseDisables the field
labelstring-Label text

Keyboard Interactions

Accessibility
All keyboard interactions follow WAI-ARIA best practices and work without any additional configuration.
Keyboard shortcuts for NumberField
KeyAction
ArrowUpIncrements the value by one step
ArrowDownDecrements the value by one step
HomeSets value to minimum
EndSets value to maximum