logoAnt Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
YouMindTRACTIANLobeHub
6.4.3
  • Components Overview
  • Changelog
    v6.4.3
  • General
    • Button
    • FloatButton
    • Icon
    • Typography
  • Layout
    • Divider
    • Flex
    • Grid
    • Layout
    • Masonry
      6.0.0
    • Space
    • Splitter
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
    • Tabs
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPicker
    • DatePicker
    • Form
    • Input
    • InputNumber
    • Mentions
    • Radio
    • Rate
    • Select
    • Slider
    • Switch
    • TimePicker
    • Transfer
    • TreeSelect
    • Upload
  • Data Display
    • Avatar
    • Badge
    • Calendar
    • Card
    • Carousel
    • Collapse
    • Descriptions
    • Empty
    • Image
    • List
      DEPRECATED
    • Popover
    • QRCode
    • Segmented
    • Statistic
    • Table
    • Tag
    • Timeline
    • Tooltip
    • Tour
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
  • Other
    • Affix
    • App
    • BorderBeam
      6.4.0
    • ConfigProvider
    • Util
When To Use
Examples
Basic
Sizes
Disabled
High precision decimals
Formatter
Keyboard
Wheel
Variants
Spinner
Out of range
Prefix / Suffix
Status
Focus
Custom semantic dom styling
API
Ref
Semantic DOM
Design Token
Notes
FAQ
Why value can exceed min or max in control?
Why dynamic change min or max which makes value out of range will not trigger onChange?
Why onBlur or other event can not get correct value?
Why changeOnWheel unable to control whether the mouse scroll wheel changes value?

InputNumber

Enter a number within certain range with the mouse or keyboard.
Importimport { InputNumber } from 'antd';
GitHub
components/input-numberIssueOpen issues
Docs
Edit this pageLLMs.md
contributors
    InputMentions

    Resources

    Ant Design X
    Ant Design Charts
    Ant Design Pro
    Pro Components
    Ant Design Mobile
    Ant Design Mini
    Ant Design Web3
    Ant Design Landing-Landing Templates
    Scaffolds-Scaffold Market
    Umi-React Application Framework
    dumi-Component doc generator
    qiankun-Micro-Frontends Framework
    Ant Motion-Motion Solution
    China Mirror 🇨🇳

    Community

    Awesome Ant Design
    Medium
    X
    yuque logoAnt Design in YuQue
    Ant Design in Zhihu
    Experience Cloud Blog
    seeconf logoSEE Conf-Experience Tech Conference

    Help

    GitHub
    Change Log
    FAQ
    Bug Report
    Issues
    Discussions
    StackOverflow
    SegmentFault

    Ant XTech logoMore Products

    yuque logoYuQue-Document Collaboration Platform
    AntV logoAntV-Data Visualization
    Egg logoEgg-Enterprise Node.js Framework
    Kitchen logoKitchen-Sketch Toolkit
    Galacean logoGalacean-Interactive Graphics Solution
    WeaveFox logoWeaveFox-AI Development with WeaveFox 🦊
    xtech logoAnt Financial Experience Tech
    Theme Editor
    Made with ❤ by
    Ant Group and Ant Design Community
    loading

    When To Use

    When a numeric value needs to be provided.

    Examples

    API

    Common props ref:Common props

    PropertyDescriptionTypeDefaultVersion
    addonAfterThe label text displayed after (on the right side of) the input field, please use Space.Compact insteadReactNode-
    addonBeforeThe label text displayed before (on the left side of) the input field, please use Space.Compact insteadReactNode-
    changeOnBlurTrigger onChange when blur. e.g. reset value in range by blurbooleantrue5.11.0
    changeOnWheelAllows control with mouse wheelboolean-5.14.0
    classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>--
    controlsWhether to show +- controls, or set custom arrow iconsboolean | { upIcon?: React.ReactNode; downIcon?: React.ReactNode; }-
    decimalSeparatorDecimal separatorstring--
    placeholderPlaceholderstring-
    defaultValueThe initial valuenumber--
    disabledIf the input is disabledbooleanfalse-
    formatterSpecifies the format of the value presentedfunction(value: number | string, info: { userTyping: boolean, input: string }): string-
    keyboardIf keyboard behavior is enabledbooleantrue
    maxThe max valuenumberNumber.MAX_SAFE_INTEGER-
    minThe min valuenumberNumber.MIN_SAFE_INTEGER-
    parserSpecifies the value extracted from formatterfunction(string): number--
    precisionThe precision of input value. Will use formatter when config of formatternumber--
    readOnlyIf the input is readonlybooleanfalse-
    statusSet validation status'error' | 'warning'-
    stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>--
    prefixThe prefix icon for the InputReactNode-
    suffixThe suffix icon for the InputReactNode-5.20.0
    sizeThe height of input boxlarge | medium | small--
    stepThe number to which the current value is increased or decreased. It can be an integer or decimalnumber | string1-
    stringModeSet value as string to support high precision decimals. Will return string value by onChangebooleanfalse
    modeShow input or spinner'input' | 'spinner''input'
    valueThe current value of the componentnumber--
    variantVariants of Inputoutlined | borderless | filled | underlinedoutlined5.13.0 | underlined: 5.24.0
    onChangeThe callback triggered when the value is changedfunction(value: number | string | null)--
    onPressEnterThe callback function that is triggered when Enter key is pressedfunction(e)--
    onStepThe callback function that is triggered when click up or down buttons / Keyboard / Wheel(value: number, info: { offset: number, type: 'up' | 'down', emitter: 'handler' | 'keydown' | 'wheel' }) => void-
    borderedWhether has border style, please use variant insteadbooleantrue-

    Ref

    NameDescriptionTypeVersion
    blur()Remove focus-
    focus()Get focus(option?: { preventScroll?: boolean, cursor?: 'start' | 'end' | 'all' })cursor - 5.22.0
    nativeElementThe native DOM element-5.17.3

    Semantic DOM

    Design Token

    Component TokenHow to use?
    Token NameDescriptionTypeDefault Value
    activeBgBackground color when the input box is activatedstring#ffffff
    activeBorderColorActive border colorstring#1677ff
    activeShadowBox-shadow when activestring0 0 0 2px rgba(5,145,255,0.1)
    addonBgBackground color of addonstringrgba(0,0,0,0.02)
    controlWidthWidth of inputnumber90
    errorActiveShadowBox-shadow when active in error statusstring0 0 0 2px rgba(255,38,5,0.06)
    filledHandleBgBackground color of handle in filled variantstring#f0f0f0
    handleActiveBgActive background color of handlestringrgba(0,0,0,0.02)
    handleBgBackground color of handlestring#ffffff
    handleBorderColorBorder color of handlestring#d9d9d9
    handleFontSizeIcon size of control buttonnumber7
    handleHoverColorHover color of handlestring#1677ff
    handleVisibleHandle visibletrue | "auto"auto
    handleWidthWidth of control buttonnumber22
    hoverBgBackground color when the input box hoversstring#ffffff
    hoverBorderColorHover border colorstring#4096ff
    inputFontSizeFont sizenumber14
    inputFontSizeLGFont size of largenumber16
    inputFontSizeSMFont size of smallnumber14
    paddingBlockVertical padding of inputnumber4
    paddingBlockLGVertical padding of large inputnumber7
    paddingBlockSMVertical padding of small inputnumber0
    paddingInlineHorizontal padding of inputnumber11
    paddingInlineLGHorizontal padding of large inputnumber11
    paddingInlineSMHorizontal padding of small inputnumber7
    warningActiveShadowBox-shadow when active in warning statusstring0 0 0 2px rgba(255,215,5,0.1)
    Global TokenHow to use?
    Token NameDescriptionTypeDefault Value
    colorBgContainerContainer background color, e.g: default button, input box, etc. Be sure not to confuse this with `colorBgElevated`.string#ffffff
    colorBgContainerDisabledControl the background color of container in disabled state.stringrgba(0,0,0,0.04)
    colorBorderDefault border color, used to separate different elements, such as: form separator, card separator, etc.string#d9d9d9
    colorBorderDisabledControl the border color of the element in the disabled state.string#d9d9d9
    colorErrorUsed to represent the visual elements of the operation failure, such as the error Button, error Result component, etc.string#ff4d4f
    colorErrorAffixControl the color of form control prefix/suffix in error state.string#ff4d4f
    colorErrorBgThe background color of the error state.string#fff2f0
    colorErrorBgHoverThe hover state background color of the error state.string#fff1f0
    colorErrorBorderHoverThe hover state border color of the error state.string#ffa39e
    colorErrorTextThe default state of the text in the error color.string#ff4d4f
    colorFillSecondaryThe second level of fill color can outline the shape of the element more clearly, such as Rate, Skeleton, etc. It can also be used as the Hover state of the third level of fill color, such as Table, etc.stringrgba(0,0,0,0.06)
    colorFillTertiaryThe third level of fill color is used to outline the shape of the element, such as Slider, Segmented, etc. If there is no emphasis requirement, it is recommended to use the third level of fill color as the default fill color.stringrgba(0,0,0,0.04)
    colorIconWeak action. Such as `allowClear` or Alert close buttonstringrgba(0,0,0,0.45)
    colorTextDefault text color which comply with W3C standards, and this color is also the darkest neutral color.stringrgba(0,0,0,0.88)
    colorTextDisabledControl the color of text in disabled state.stringrgba(0,0,0,0.25)
    colorTextPlaceholderControl the color of placeholder text.stringrgba(0,0,0,0.25)
    colorWarningUsed to represent the warning map token, such as Notification, Alert, etc. Alert or Control component(like Input) will use these map tokens.string#faad14
    colorWarningAffixControl the color of form control prefix/suffix in warning state.string#faad14
    colorWarningBgThe background color of the warning state.string#fffbe6
    colorWarningBgHoverThe hover state background color of the warning state.string#fff1b8
    colorWarningBorderHoverThe hover state border color of the warning state.string#ffd666
    colorWarningTextThe default state of the text in the warning color.string#faad14
    borderRadiusBorder radius of base componentsnumber6
    borderRadiusLGLG size border radius, used in some large border radius components, such as Card, Modal and other components.number8
    borderRadiusSMSM size border radius, used in small size components, such as Button, Input, Select and other input components in small sizenumber4
    fontFamilyThe font family of Ant Design prioritizes the default interface font of the system, and provides a set of alternative font libraries that are suitable for screen display to maintain the readability and readability of the font under different platforms and browsers, reflecting the friendly, stable and professional characteristics.string-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'
    fontSizeThe most widely used font size in the design system, from which the text gradient will be derived.number14
    lineHeightLine height of text.number1.5714285714285714
    lineHeightLGLine height of large text.number1.5
    lineTypeBorder style of base componentsstringsolid
    lineWidthBorder width of base componentsnumber1
    motionDurationMidMotion speed, medium speed. Used for medium element animation interaction.string0.2s
    paddingXXSControl the extra extra small padding of the element.number4

    Notes

    Per issues #21158, #17344, #9421, and documentation about inputs, it appears this community does not support native inclusion of the type="number" in the <Input /> attributes, so please feel free to include it as needed, and be aware that it is heavily suggested that server side validation be utilized, as client side validation can be edited by power users.

    FAQ

    Why value can exceed min or max in control?

    Developer handle data by their own in control. It will make data out of sync if InputNumber changes display value. It also cause potential data issues when use in form.

    Why dynamic change min or max which makes value out of range will not trigger onChange?

    onChange is user trigger event. Auto-triggering would prevent form libraries from detecting the data modification source.

    Why onBlur or other event can not get correct value?

    InputNumber's value is wrapped by internal logic. The event.target.value you get from onBlur or other event is the DOM element's value instead of the actual value of InputNumber. For example, if you change the display format through formatter or decimalSeparator, you will get the formatted string in the DOM. You should always get the current value through onChange.

    Why changeOnWheel unable to control whether the mouse scroll wheel changes value?

    The use of the type attribute is deprecated

    The InputNumber component allows you to use all the attributes of the input element and ultimately pass them to the input element, This attribute will also be added to the input element when you pass in type='number', which will activate native behavior (allowing the mouse wheel to change the value), As a result changeOnWheel cannot control whether the mouse wheel changes the value.

    Basic

    Numeric-only input box.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    Disabled

    Click the button to toggle between available and disabled states.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    Formatter

    Display value within it's situation with formatter, and we usually use parser at the same time.

    Here is a Intl.NumberFormat InputNumber implementation: https://codesandbox.io/s/currency-wrapper-antd-input-3ynzo

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    Wheel

    Control with mouse wheel.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    5.14.0
    Spinner

    Digit spinner.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    6.0.0
    Prefix / Suffix

    Add a prefix or suffix inside input.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    Focus

    Focus with additional option.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    5.22.0
    Sizes

    There are three sizes available to a numeric input box. By default, the size is 32px. The two additional sizes are large and small which means 40px and 24px, respectively.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    High precision decimals

    Use stringMode to support high precision decimals support. onChange will return string value instead. You need polyfill of BigInt if browser not support.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    Keyboard

    Control keyboard behavior by keyboard.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    Variants

    Variants of InputNumber, there are four variants: outlined filled borderless and underlined.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    5.13.0
    Out of range

    Show warning style when value is out of range by control.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    Status

    Add status to InputNumber with status, which could be error or warning.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    Custom semantic dom styling

    You can customize the semantic dom style of the InputNumber by passing objects/functions through classNames and styles.

    CodeSandbox Icon
    Hitu Icon
    codepen icon
    External Link Icon
    Expand Icon
    6.0.0
    ¥
    ¥
    ¥
    RMB
    ¥
    RMB
    • root
      Root element, sets inline-block layout, width, border radius and reset styles
    • prefix
      Prefix wrapper element, sets flex layout, alignment and right margin styles
    • input
      Input element, sets font, line height, text input and interaction styles
    • suffix
      Suffix wrapper element, sets flex layout, margin and transition animation styles
    • actions
      Actions element, sets absolute positioning, width, flex layout and number adjustment button styles
    • action
      Single action button element, sets button styling, hover effects and click interactions