DocsBlog

Get Started

Components

Data Grid

Signals

Styling

Theming

↑↓Navigate
↵Select
EscClose
  • 1.8.0

  • Day

    Night

    Preview

    Switch mode
  • cerberus

    acheron

    elysium

    oceanus

Get Started
Components
Data Grid
Signals
Styling
Theming

Concepts

OverviewCompositionCerberus ContextTesting

Layout

Aspect RatioBleedBoxCenterContainerContainer QueryDividerFlexFloatGridGroupLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTA ModalDate PickerDialogFieldFieldsetFile UploaderIconButtonInputLoading StatesMarqueeMenuNotificationsNumber InputPaginationPin InputPopoverProgress IndicatorsPrompt ModalRadioRatingSelectSliderSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFormat Relative TimeFrameHighlightJSON Tree ViewLocalePortalPresenceShowSwapsplitPropsTheme

Number Input

The Number Input component is used to manage numeric input fields.

  • npm
  • source
  • recipe
  • Ark
View as Markdown
Open this page in Markdown
Anthropic
Open in Claude
Ask questions about this page
OpenAI
Open in ChatGPT
Ask questions about this page

Import

import { NumberInput } from '@cerberus/react'

Usage

The NumberInput component provides a way to create input fields specifically for numeric values. It includes features such as increment and decrement buttons, and can be easily integrated with form libraries.

Loading example...

Scrubber

The NumberInput supports the scrubber interaction pattern. To use this pattern, use the scrubber prop. It uses the Pointer lock API and tracks the pointer movement. It also renders a virtual cursor which mimics the real cursor's pointer

Loading example...

Sizes

The NumberInput component supports different sizes to accommodate various design requirements. You can specify the size using the size prop.

Loading example...

Custom

You can customize the NumberInput component using the primitive components or style props.

Loading example...

Primitives

You can utilize the primitive components or the css prop to customize the number input.

ComponentDescription
NumberInputRootThe context provider for the NumberInput parts
NumberInputLabelThe label of the NumberInput
NumberInputControlThe wrapper of the NumberInput contents
NumberInputInputThe input of the NumberInput
NumberInputIncrementTriggerThe increment button of the NumberInput
NumberInputDecrementTriggerThe decrement button of the NumberInput
NumberInputScrubberThe scrubber of the NumberInput

Parts

The NumberInputParts API is an Object containing the full family of components.

Note

It is best to only use the NumberInputParts if you are building a custom solution. Importing Object based components will ship every property it includes into your bundle, regardless if you use it or not.

NameDescription
RootThe NumberInputRoot component which is the Provider for the family.
LabelThe NumberInputLabel component which displays the label and "required" notice.
InputThe NumberInputInput component which is the input field.
ControlThe NumberInputControl component which is the wrapper for the input and buttons.
IncrementTriggerThe NumberInputIncrementTrigger component which is the increment button.
DecrementTriggerThe NumberInputDecrementTrigger component which is the decrement button.
ScrubberThe NumberInputScrubber component which is the scrubber control.

API

Props

Root

Props

PropTypeRequiredDefaultDescription
allowMouseWheelbooleanfalseundefinedWhether to allow mouse wheel to change the value
allowOverflowbooleanfalsetrueWhether to allow the value overflow the min/max range
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.
clampValueOnBlurbooleanfalsetrueWhether to clamp the value when the input loses focus (blur)
defaultValuestringfalseundefinedThe initial value of the input when rendered.
Use when you don't need to control the value of the input.
disabledbooleanfalseundefinedWhether the number input is disabled.
focusInputOnChangebooleanfalsetrueWhether to focus input when the value changes
formstringfalseundefinedThe associate form of the input element.
formatOptionsNumberFormatOptionsfalseundefinedThe options to pass to the Intl.NumberFormat constructor
idstringfalseundefinedThe unique identifier of the machine.
idsPartial<{ root: string, label: string, input: string, incrementTrigger: string, decrementTrigger: string, scrubber: string }>falseundefinedThe ids of the elements in the number input. Useful for composition.
inputModeInputModefalse"decimal"Hints at the type of data that might be entered by the user. It also determines
the type of keyboard shown to the user on mobile devices
invalidbooleanfalseundefinedWhether the number input value is invalid.
largeStepnumberfalse10 * stepThe amount to increment or decrement the value by when the Shift key is held.
localestringfalse"en-US"The current locale. Based on the BCP 47 definition.
maxnumberfalseNumber.MAX_SAFE_INTEGERThe maximum value of the number input
minnumberfalseNumber.MIN_SAFE_INTEGERThe minimum value of the number input
namestringfalseundefinedThe name attribute of the number input. Useful for form submission.
onFocusChange(details: FocusChangeDetails) => voidfalseundefinedFunction invoked when the number input is focused
onValueChange(details: ValueChangeDetails) => voidfalseundefinedFunction invoked when the value changes
onValueCommit(details: ValueChangeDetails) => voidfalseundefinedFunction invoked when the value is committed (when the input is blurred or the Enter key is pressed)
onValueInvalid(details: ValueInvalidDetails) => voidfalseundefinedFunction invoked when the value overflows or underflows the min/max range
patternstringfalse"-?[0-9]*(.[0-9]+)?"The pattern used to check the <input> element's value against
readOnlybooleanfalseundefinedWhether the number input is readonly
requiredbooleanfalseundefinedWhether the number input is required
smallStepnumberfalsestep / 10The amount to increment or decrement the value by when the Alt key is held.
spinOnPressbooleanfalsetrueWhether to spin the value when the increment/decrement button is pressed
stepnumberfalse1The amount to increment or decrement the value by
translationsIntlTranslationsfalseundefinedSpecifies the localized strings that identifies the accessibility elements and their states
valuestringfalseundefinedThe controlled value of the input

Data Attributes

AttributeDescription / Value
data-scopenumber-input
data-partroot
data-disabledPresent when disabled
data-focusPresent when focused
data-invalidPresent when invalid
data-scrubbing

Control

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scopenumber-input
data-partcontrol
data-focusPresent when focused
data-disabledPresent when disabled
data-invalidPresent when invalid
data-scrubbing

DecrementTrigger

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scopenumber-input
data-partdecrement-trigger
data-disabledPresent when disabled
data-scrubbing

IncrementTrigger

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scopenumber-input
data-partincrement-trigger
data-disabledPresent when disabled
data-scrubbing

Input

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scopenumber-input
data-partinput
data-invalidPresent when invalid
data-disabledPresent when disabled
data-scrubbing

Label

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scopenumber-input
data-partlabel
data-disabledPresent when disabled
data-focusPresent when focused
data-invalidPresent when invalid
data-requiredPresent when required
data-scrubbing

RootProvider

Props

PropTypeRequiredDefaultDescription
valueUseNumberInputReturntrueundefinedundefined
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Scrubber

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scopenumber-input
data-partscrubber
data-disabledPresent when disabled
data-scrubbing

ValueText

Props

PropTypeRequiredDefaultDescription
asChildbooleanfalseundefinedUse the provided child element as the default rendered element, combining their props and behavior.

Data Attributes

AttributeDescription / Value
data-scopenumber-input
data-partvalue-text
data-disabledPresent when disabled
data-invalidPresent when invalid
data-focusPresent when focused
data-scrubbing

Context

API:

PropertyTypeDescription
focusedbooleanWhether the input is focused.
invalidbooleanWhether the input is invalid.
emptybooleanWhether the input value is empty.
valuestringThe formatted value of the input.
valueAsNumbernumberThe value of the input as a number.
setValue(value: number) => voidFunction to set the value of the input.
clearValueVoidFunctionFunction to clear the value of the input.
incrementVoidFunctionFunction to increment the value of the input by the step.
decrementVoidFunctionFunction to decrement the value of the input by the step.
setToMaxVoidFunctionFunction to set the value of the input to the max.
setToMinVoidFunctionFunction to set the value of the input to the min.
focusVoidFunctionFunction to focus the input.

Accessibility

Complies with the Spinbutton WAI-ARIA design pattern.

Keyboard Support

KeyDescription
ArrowUpIncrements the value of the number input by a predefined step.
ArrowDownDecrements the value of the number input by a predefined step.
Shift + ArrowUpIncrements the value of the number input by the largeStep amount.
Shift + ArrowDownDecrements the value of the number input by the largeStep amount.
Alt + ArrowUpIncrements the value of the number input by the smallStep amount.
Alt + ArrowDownDecrements the value of the number input by the smallStep amount.
HomeSets the value of the number input to its minimum allowed value.
EndSets the value of the number input to its maximum allowed value.
EnterSubmits the value entered in the number input.

On this page

  • Import
  • Usage
  • Scrubber
  • Sizes
  • Custom
  • Primitives
    • Parts
  • API
    • Props
    • Root
      • Props
      • Data Attributes
    • Control
      • Props
      • Data Attributes
    • DecrementTrigger
      • Props
      • Data Attributes
    • IncrementTrigger
      • Props
      • Data Attributes
    • Input
      • Props
      • Data Attributes
    • Label
      • Props
      • Data Attributes
    • RootProvider
      • Props
    • Scrubber
      • Props
      • Data Attributes
    • ValueText
      • Props
      • Data Attributes
    • Context
  • Accessibility
    • Keyboard Support
Edit this page on Github
Choose your quantity.
Use your mouse wheel to change the value.