Open In App

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:



Dropdown.Button Props:

Creating React Application And Installing Module:



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.




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/


Article Tags :