Wednesday, January 21, 2026
HomeLanguagesReactJS UI Ant Design InputNumber Component

ReactJS UI Ant Design InputNumber Component

Ant Design Library has this component pre-built, and it is very easy to integrate as well. InputNumber Component allows the user to enter a number within a certain range with the help of a keyboard or mouse. We can use the following approach in ReactJS to use the Ant Design InputNumber Component.

InputNumber Methods:

  • blur(): This method is used to remove the focus from the element.
  • focus(): This method is used to get the focus on the element.

InputNumber Props:

  • autoFocus: It is used to get the focus when the component is mounted.
  • bordered: It is used to specify whether it has border style or not.
  • decimalSeparator: It is used to indicate the decimal separator.
  • defaultValue: It is used to specify the initial value.
  • disabled: It is used to disable the input.
  • formatter: It is used to specify the format of the value presented.
  • keyboard: It is used to enable keyboard behavior.
  • max: It is used to denote the maximum value.
  • min: It is used to denote the minimum value.
  • parser: It is used to specify the extracted value from formatter.
  • precision: It is used to denote the precision of input value.
  • readOnly: It is used to make the input read-only.
  • size: It is used to indicate the height of the input box.
  • step: It is used to denote the number to which the current value is decreased or increased.
  • stringMode: It is used to set value as string to support decimals of high precision.
  • value: It is used to denote the current value.
  • onChange: It is the callback function which is triggered when the value is changed.
  • onPressEnter: It is the callback function which is triggered when the user press the enter key.
  • onStep: It is the callback function which is triggered when the user clicks up or down buttons.

Creating React Application And Installing Module:

  • Step 1: Create a React application using the following command:

    npx create-react-app foldername
  • Step 2: After creating your project folder i.e. foldername, move to it using the following command:

    cd foldername
  • Step 3: After creating the ReactJS application, Install the required module using the following command:

    npm install antd

Project Structure: It will look like the following.

Project Structure

Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.

App.js




import React, { useState } from 'react'
import "antd/dist/antd.css";
import { InputNumber } from 'antd';
  
export default function App() {
  
  // Our state to hold current value of input
  const [currentValue, setCurrentValue] = useState(0)
  
  return (
    <div style={{ display: 'block', width: 700, padding: 30 }}>
      <h4>ReactJS Ant-Design InputNumber Component</h4>
      <InputNumber min={0} defaultValue={0}
        onChange={(value) => {
          setCurrentValue(value)
        }} /> <br />
      Current Entered Value : {currentValue}
    </div>
  );
}


Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Reference: https://ant.design/components/input-number/

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
119 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12064 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7220 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS