NumberInput

NumberInput is a component used to obtain numeric input from the user.

Usage

import { NumberInput } from "@yamada-ui/react"
<NumberInput />

Change Variant

Change Size

Set Default Value

To set a default value, set a string or number to defaultValue.

Set Minimum and Maximum Values

To set minimum and maximum values, set a number to min or max.

Set Step Value

To set a step value, set a number to step.

Set Decimal Points

To set decimal points, set a number to precision.

Disable Clamping Value on Blur

By default, the component accepts any numeric input from the user, but values exceeding min or max are automatically adjusted on blur. To disable this automatic adjustment, set clampValueOnBlur to false.

Allow Out-of-Range Values

To allow out-of-range values, set keepWithinRange to false.

Disable

To disable the component, set disabled to true.

Read-Only

To make the component read-only, set readOnly to true.

Invalid

To make invalid, set invalid to true.

Change Border Color

To change the border color, set a color to focusBorderColor or errorBorderColor.

Change Placeholder Color

To change the placeholder color, set _placeholder to the value.

Customize Stepper

To customize the stepper, set props to incrementProps or decrementProps.

Customize Component

To customize the component, use useNumberInput.

Control

Props

Accessibility

The NumberInput follows the WAI-ARIA - Spinbutton Pattern for accessibility.

If you are not using Field.Root, set aria-label or aria-labelledby to NumberInput.

<NumberInput aria-label="Age" />
<VStack gap="sm">
  <Text as="h3" id="label">
    Age
  </Text>

  <NumberInput aria-labelledby="label" />
</VStack>

Keyboard Navigation

KeyDescriptionState
ArrowUpIncreases the value based on step value.-
ArrowDownDecreases the value based on step value.-
HomeSets to min value.-
EndSets to max value.-
Shift + ArrowUpIncreases the value by 10x the step.-
Shift + ArrowDownDecreases the value by 10x the step.-
Meta + ArrowUp, Ctrl + ArrowUpIncreases the value by 0.1x the step.-
Meta + ArrowDown, Ctrl + ArrowDownDecreases the value by 0.1x the step.-

ARIA Roles and Attributes

ComponentRoles and AttributesUsage
NumberInputrole="spinbutton"Indicates that this is a spinbutton.
aria-valueminSets to min value.
aria-valuemaxSets to max value.
aria-valuenowSets to current value.
aria-valuetextSets to current value.
aria-invalidSets to "true" if invalid is set or if the value is out of range.
aria-describedbyIf NumberInput is within a Field.Root and Field.Root has an errorMessage, helperMessage, or a Field.ErrorMessage, Field.HelperMessage, sets its id.
aria-disabledSets to "true" if disabled is set.
aria-readonlySets to "true" if readOnly is set.
aria-requiredSets to "true" if required is set.
NumberInputIncrementButtonaria-labelSets to "Increase".
NumberInputDecrementButtonaria-labelSets to "Decrease".