Thursday, September 4, 2025
HomeLanguagesReactJS UI Ant Design Dropdown Component

ReactJS UI Ant Design Dropdown Component

Ant Design Library has this component pre-built, and it is very easy to integrate as well. Dropdown Component is used to provide a dropdown list, and it is used when the user has more than a few options to choose from. We can use the following approach in ReactJS to use the Ant Design Dropdown Component.

Dropdown Props:

  • arrow: It is used to indicate whether the dropdown arrow should be visible or not.
  • disabled: It is used to indicate whether the dropdown menu is disabled or not.
  • getPopupContainer: It is used to set the container of the dropdown menu.
  • overlay: It is the dropdown menu.
  • overlayClassName: It is used to pass the class name of the dropdown root element.
  • overlayStyle: It is used for the style of the dropdown root element.
  • placement: It is used for the placement of the popup menu.
  • trigger: It is the trigger mode that executes the dropdown action.
  • visible: It is used to indicate whether the dropdown menu is currently visible or not.
  • onVisibleChange: It is a callback function that is called when the visible state is changed.

Dropdown.Button Props:

  • buttonsRender: It is used for the custom buttons inside Dropdown.Button.
  • disabled: It is used to indicate whether the dropdown menu is disabled or not
  • icon: It is used to pass the Icon which appears on the right.
  • overlay: It is the dropdown menu.
  • placement: It is used for the placement of the popup menu.
  • size: It is used to denote the size of the button.
  • trigger: It is the trigger mode that executes the dropdown action.
  • type: It is used to denote the type of the button.
  • visible: It is used to indicate whether the dropdown menu is currently or not.
  • onClick: It is a callback function that is called when you click the button on the left.
  • onVisibleChange: It is a callback function that is called when the visible state is changed.

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 from 'react'
import "antd/dist/antd.css";
import { Menu, Dropdown } from 'antd';
  
export default function App() {
  
  return (
    <div style={{
      display: 'block', width: 700, padding: 30
    }}>
      <h4>ReactJS Ant-Design Dropdown Component</h4>
      <>
        <Dropdown
          overlay={(
            <Menu>
              <Menu.Item key="0">
                Menu Item One
              </Menu.Item>
              <Menu.Item key="1">
              Menu Item Two
              </Menu.Item>
              <Menu.Item key="1">
              Menu Item Three
              </Menu.Item>
            </Menu>
          )}
          trigger={['click']}>
          <a className="ant-dropdown-link" 
             onClick={e => e.preventDefault()}>
            Open Dropdown
          </a>
        </Dropdown>
      </>
    </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/dropdown/

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
32261 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6695 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS