Friday, February 6, 2026
HomeLanguagesReactJS UI Ant Design Input Component

ReactJS UI Ant Design Input Component

Ant Design Library has this component pre-built, and it is very easy to integrate as well. Input Component is used to create a basic widget for getting the user input is a text field. We can use the following approach in ReactJS to use the Ant Design Input Component.

Input Props:

  • addonAfter: It is used to denote the label text displayed after the input field.
  • addonBefore: It is used to denote the label text displayed before the input field.
  • allowClear: It is used to remove input content with a clear icon if it is set to true.
  • bordered: It is used to indicate whether it has border style or not.
  • defaultValue: It is used to denote the initial input content.
  • disabled: It is used to indicate whether the input is disabled or not.
  • id: It is used to denote the ID for input.
  • maxLength: It is used to denote the max length.
  • prefix: It is used to denote the prefix icon for the Input.
  • size: It is used to denote the size of the input box.
  • suffix: It is used to denote the suffix icon for the Input.
  • type: It is used to denote the type of input.
  • value: It is used to denote the input content value.
  • onChange: It is the callback function that is triggered when user input changes.
  • onPressEnter: It is the callback function that is triggered when Enter key is pressed.

Input.TextArea Props:

  • allowClear: It is used to remove input content with a clear icon if it is set to true.
  • autoSize: It is used to denote the Height autosize feature.
  • bordered: It is used to indicate whether it has border style or not.
  • defaultValue: It is used to denote the initial input content.
  • maxLength: It is used to denote the max length.
  • showCount: It is used to indicate whether show text counts or not.
  • value: It is used to denote the input content value.
  • onPressEnter: It is the callback function that is triggered when Enter key is pressed.
  • onResize: It is the callback function that is triggered when resize happens.

Input.Search Props:

  • enterButton: It is used to indicate whether to show an enter button after an input or not.
  • loading: It is used to indicate whether to show search box with loading effect or not.
  • onSearch: It is the callback function that is triggered when you press enter key or click on the search-icon, clear-icon.

 

Input.Group Props:

  • compact: It is used to indicate whether to use compact style or not.
  • size: It is used to denote the size of the included Input fields.

 Input.Password Props:

  • iconRender: It is used for the custom toggle button.
  • visibilityToggle: It is used to indicate whether to show the toggle button or not.

Input Methods:

  • blur(): This function is used to remove focus.
  • focus(): This function is used to get focus.

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 { Input } from 'antd';
  
export default function App() {
  
  const [name, setName] = useState('')
  
  return (
    <div style={{
      display: 'block', width: 700, padding: 30
    }}>
      <h4>ReactJS Ant-Design Input Component</h4>
      <>
        <Input
          placeholder="Enter your Name"
          onChange={(e) => setName(e.target.value)}
        />
      Name: {name}
      </>
    </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/

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
32489 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12073 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6930 POSTS0 COMMENTS