Back to Shark UI

Number Input

docs/components/number-input

latest9.6 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Number Input

Copy Markdown

Numeric input for entering values.

DocsAPI

PreviewCode

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/number-input

Anatomy#

NumberInput
└── NumberInputGroup
    ├── NumberInputDecrement
    ├── NumberInputInput
    ├── NumberInputIncrement
    └── NumberInputScrubber

Usage#

import { 
  NumberInput, 
  NumberInputGroup, 
  NumberInputInput, 
  NumberInputIncrement, 
  NumberInputDecrement 
} from "@/comopnents/ui/number-input";
<NumberInput>
  <NumberInputGroup>
    <NumberInputInput />
    <NumberInputIncrement />
    <NumberInputDecrement />
  </NumberInputGroup>
</NumberInput>

Controlled#

Use value and onValueChange to control the number input. Keep the value as a string when using formatOptions to preserve locale formatting.

PreviewCode

Select the number 3

States#

Disabled#

Use the disabled prop to disable the number input.

PreviewCode

Invalid#

Use the invalid prop to mark the number input as invalid.

PreviewCode

Sizes#

Use the size prop to change the input height.

Small#

PreviewCode

Medium#

PreviewCode

Large#

PreviewCode

Examples#

Field Only#

PreviewCode

With Field#

Use Field components for a labeled number input with helper text.

PreviewCode

Quantity

0 - 100 only

With Input Group#

Use InputGroup, InputGroupAddon, and InputGroupText to add prefix or suffix.

PreviewCode

EUR

With Scrub#

Use the NumberInputScrubber to drag the label to change the value.

PreviewCode

Quantity

With Range#

Pass min and max to restrict the value to the specified range.

Use clampValueOnBlur={false} to allow typing outside range until blur.

PreviewCode

With Formatted Value#

Use formatOptions with Intl.NumberFormatOptions to format the displayed value.

PreviewCode

With Step#

Use the step prop to set the increment/decrement amount.

PreviewCode

Step 5

Step 0.1

Mouse Wheel#

Use the allowMouseWheel prop to increment or decrement the value with the mouse wheel.

PreviewCode

API Reference#

NumberInput#

Root component. Manages numeric value and stepper controls.

PropTypeDefault
size`"sm""md"
scrubberbooleanfalse
defaultValuestring-
valuestring-
minnumberNumber.MIN_SAFE_INTEGER
maxnumberNumber.MAX_SAFE_INTEGER
stepnumber1
formatOptionsIntl.NumberFormatOptions-
disabledboolean-
invalidboolean-
focusInputOnChangebooleantrue
clampValueOnBlurbooleantrue
allowMouseWheelbooleanfalse
onValueChange(details: ValueChangeDetails) => void-
classNamestring-
asChildbooleanfalse

NumberInputGroup#

Wraps the input and increment/decrement buttons.

PropTypeDefault
classNamestring-
asChildbooleanfalse

NumberInputDecrement#

Decreases the value by the step amount.

PropTypeDefault
classNamestring-
asChildbooleanfalse

NumberInputIncrement#

Increases the value by the step amount.

PropTypeDefault
classNamestring-
asChildbooleanfalse

NumberInputInput#

Numeric input. Accepts number or direct typing.

PropTypeDefault
size`"sm""md"
classNamestring-
asChildbooleanfalse

NumberInputScrubber#

Drag area for scrubbing the value.

PropTypeDefault
classNamestring-
asChildbooleanfalse

For a complete list of props, see the Ark UI documentation.

[

Previous page

Native Select ](/docs/components/native-select)[

Next page

Pagination ](/docs/components/pagination)

On This Page

InstallationAnatomyUsageControlledStatesDisabledInvalidSizesSmallMediumLargeExamplesField OnlyWith FieldWith Input GroupWith ScrubWith RangeWith Formatted ValueWith StepMouse WheelAPI ReferenceNumberInputNumberInputGroupNumberInputDecrementNumberInputIncrementNumberInputInputNumberInputScrubber