Skip to content
Cojeev UI

Number input

Forms

A number field with readable formatting, a native editing caret and expressive stepping.

React · copy into your project · light and dark themes

Try it

Loading preview…

Take it with you

Copy the example, API and usage notes for your editor or AI assistant.

Add to your project

Terminal
npx shadcn@latest add https://luv-jeri.github.io/cojeev-ui/r/number-input.json

The command includes the component’s shared dependencies. Your project keeps editable source files.

Include the complete example

This example also composes button, typography. Install its parts together:

Terminal
npx shadcn@latest add https://luv-jeri.github.io/cojeev-ui/r/number-input.json https://luv-jeri.github.io/cojeev-ui/r/button.json https://luv-jeri.github.io/cojeev-ui/r/typography.json

Using number input

  • Use defaultValue for internal state or value/onValueChange for controlled values. null represents an empty field.

  • Set min, max and step for adjustments. Editing uses a native text input with decimal input mode; blur and Enter normalize valid values, while Escape restores the current value.

  • Choose locale and Intl.NumberFormatOptions for display. The animated formatted layer gives way to the real input while editing.

  • Choose count, roll or steps for value transitions. The input ref targets the actual input; className and style apply to the outer field.

API

Compose the exported parts below. The prop types are read from the React source during the registry build.

Native element or underlying primitive props are inherited where declared, including accessible labels, event handlers and refs.

NumberInputProps

PropTypeRequired
valuenumber | nullNo
defaultValuenumber | nullNo
onValueChange(value: number | null) => voidNo
minnumberNo
maxnumberNo
stepnumberNo
localestringNo
formatIntl.NumberFormatOptionsNo
treatmentAnimatedNumberProps["treatment"]No
durationnumberNo
decrementLabel

Accessible labels for the two native step buttons.

stringNo
incrementLabelstringNo

Accessibility

  • Associate a Label with id, or supply aria-label. The native input exposes spinbutton values and supports ArrowUp/ArrowDown.

  • Both step buttons have accessible labels and respect disabled/readOnly and bounds. Quiet settings show final values without motion.

States and appearance

resteditingsteppinginvalidemptydisabledreadonlyreduced-motion

For conditional content, keep a MotionPresence boundary around keyed MotionSurface children. The shared entrance and exit states work with native primitives and respect your motion preference.

Try pointer and keyboard interaction, and switch the appearance control in the navigation to compare light and dark mode. Motion respects reduced motion preferences.