NumberInput

Capture numeric input from user with increment/decrement controls. This is a custom wrapper in @tidbcloud/uikit based on react-number-format.

Import

import { NumberInput } from '@tidbcloud/uikit'

Basic Usage

import { NumberInput } from '@tidbcloud/uikit'
 
function Demo() {
  return <NumberInput label="Enter a number" placeholder="Your number" />
}

Controlled

import { useState } from 'react'
import { NumberInput } from '@tidbcloud/uikit'
 
function Demo() {
  const [value, setValue] = useState<string | number>('')
  return <NumberInput value={value} onChange={setValue} />
}

Min and Max

import { NumberInput } from '@tidbcloud/uikit'
 
function Demo() {
  return <NumberInput label="Value between 10 and 20" min={10} max={20} />
}

Prefix and Suffix

import { NumberInput } from '@tidbcloud/uikit'
 
function Demo() {
  return (
    <>
      <NumberInput label="Price" prefix="$" defaultValue={100} />
      <NumberInput label="Percentage" suffix="%" defaultValue={50} mt="md" />
    </>
  )
}

Decimal Configuration

import { NumberInput } from '@tidbcloud/uikit'
 
function Demo() {
  return (
    <>
      <NumberInput label="No decimals" allowDecimal={false} />
      <NumberInput label="2 decimal places" decimalScale={2} fixedDecimalScale defaultValue={2.5} mt="md" />
    </>
  )
}

Thousand Separator

import { NumberInput } from '@tidbcloud/uikit'
 
function Demo() {
  return <NumberInput label="With thousand separator" thousandSeparator="," defaultValue={1000000} />
}

Hide Controls

import { NumberInput } from '@tidbcloud/uikit'
 
function Demo() {
  return <NumberInput label="No controls" hideControls />
}

Key Props

PropTypeDescription
valuestring | numberControlled value
onChange(value: string | number) => voidCalled when value changes
minnumberMinimum value
maxnumberMaximum value
stepnumberIncrement/decrement step
prefixstringString before value
suffixstringString after value
allowDecimalbooleanAllow decimal values
decimalScalenumberMax decimal places
thousandSeparatorstring | booleanThousand separator
hideControlsbooleanHide increment/decrement buttons
allowNegativebooleanAllow negative numbers
clampBehavior'blur' | 'strict' | 'none'How to clamp values
labelReactNodeInput label
errorReactNodeError message
disabledbooleanDisable input

Custom Addon Props (@tidbcloud/uikit)

PropTypeDescription
leftAddonReactNodeContent displayed as styled addon on the left side
rightAddonReactNodeContent displayed as styled addon on the right side
leftAddonPropsTypographyPropsProps passed to the left addon Typography wrapper
rightAddonPropsTypographyPropsProps passed to the right addon Typography wrapper