Skip to main content
ninna-ui

NumberInput

A numeric input component with increment/decrement controls and validation.

import { NumberInput } from "@ninna-ui/forms"
pnpm add @ninna-ui/forms

Requires @ninna-ui/core (auto-installed) + CSS setup.

View source

Usage

Import and use the NumberInput component in your application.

import { NumberInput } from "@ninna-ui/forms";
export default function Example() {
return (
<NumberInput
min={0}
max={100}
step={1}
defaultValue={50}
/>
);
}

Basic

Basic number input with stepper controls.

Sizes

NumberInput in different sizes.

Min/Max

Constrain values within a range.

Value clamped between 0 and 100

Min/Max/Step

Constrain values with custom step increments.

Min: 0, Max: 10
Step: 5
Step: 0.1

Stepper Positions

Different stepper button layouts.

Stepper on Right (default)

Stepper on Sides

No Stepper

Precision

Decimal precision for floating point numbers.

2 decimal places, step by 0.01

Formatting

Custom format and parse functions for display.

Precision: 2 decimals
Currency format
Percentage format

States

NumberInput in different states: disabled, invalid, read-only.

Normal
Disabled
Invalid
Read-only

React Hook Form

NumberInput works with React Hook Form using the Controller pattern.

Select between 1 and 100

API Reference

Complete list of props for the NumberInput component.

Props

PropTypeDefaultDescription
size'xs' | 'sm' | 'md' | 'lg' | 'xl''md'Size of the input
valuenumber-Controlled value
defaultValuenumber-Default value (uncontrolled)
onChange(value: number) => void-Callback when value changes
minnumber-Minimum value
maxnumber-Maximum value
stepnumber1Step increment
precisionnumber-Decimal places
showStepperbooleantrueShow stepper buttons
stepperPosition'right' | 'sides''right'Stepper position
disabledbooleanfalseDisabled state
invalidbooleanfalseInvalid state
readOnlybooleanfalseRead-only state
requiredbooleanfalseWhether the input is required
allowKeyboardInputbooleantrueAllow typing values directly
format(value: number) => string-Custom format function for display value
parse(value: string) => number-Custom parse function for input value
namestring-Name for form submission
idstring-ID for the input element
incrementLabelstring'Increase value'Accessible label for the increment button
decrementLabelstring'Decrease value'Accessible label for the decrement button

Accessibility

  • Uses role="spinbutton" with aria-valuemin, aria-valuemax, and aria-valuenow
  • Stepper buttons have customizable labels via incrementLabel and decrementLabel props
  • Arrow Up/Down keys increment/decrement the value
  • Proper aria-invalid, aria-disabled, and aria-required states
  • Supports all native input ARIA attributes via props spread