Skip to content
Related Articles

Related Articles

React Suite Dropdown Dropdown with Icon

Improve Article
Save Article
  • Last Updated : 28 Jun, 2022
Improve Article
Save Article

React Suite is a popular front-end library with a set of React components that are designed for the middle platform and back-end products. The dropdown component allows the user to provide navigation that uses a select picker if you want to select a value. 

Dropdown with Icon will help us to add an image as per the dropdown item. This will add more attractiveness towards our items.

Syntax:

<Dropdown title="GFG">
    <Dropdown.Item icon={Icon}>{Options} </Dropdown.Item>
</Dropdown>

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 rsuite

Project Structure: It will look like the following.

 

Example 1: Now write down the following code in the App.js file. Here, App is our default component where we have written our code. In this example, we will simply create a dropdown menu and add icons to them. We have imported icons from rsuite resources https://rsuitejs.com/resources/icons/

Javascript




import React from 'react';
import Dropdown from 'rsuite/Dropdown';
import 'rsuite/dist/rsuite.min.css';
import CodeIcon from '@rsuite/icons/Code';
import PageIcon from '@rsuite/icons/Page';
import DetailIcon from '@rsuite/icons/Detail';
import FolderFillIcon from '@rsuite/icons/FolderFill';
import FileDownloadIcon from '@rsuite/icons/FileDownload';
import FileUploadIcon from '@rsuite/icons/FileUpload';
  
function App() {
    return (
        <div>
            <h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
            <h3>React Suite Dropdown Dropdown with Icon</h3>
            <Dropdown title="GeeksforGeeks" icon={<CodeIcon />}>
                <Dropdown.Item icon={<PageIcon />}>
                    New File
                </Dropdown.Item>
                <Dropdown.Item icon={<FolderFillIcon />}>
                    New File with Current Profile
                </Dropdown.Item>
                <Dropdown.Item icon={<FileDownloadIcon />}>
                    Download As...
                </Dropdown.Item>
                <Dropdown.Item icon={<DetailIcon />}>
                    Export PDF
                </Dropdown.Item>
                <Dropdown.Item icon={<FileUploadIcon />}>
                    File Upload
                </Dropdown.Item>
                <Dropdown.Item icon={<DetailIcon />}>
                    Exit
                </Dropdown.Item>
            </Dropdown>
        </div>
    )
}
  
export default App;


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:

 

Example 2: In this example, we will learn how can we use a colored icon with the Dropdown menu.

Javascript




import React from 'react';
import Dropdown from 'rsuite/Dropdown';
import 'rsuite/dist/rsuite.min.css';
import CodeIcon from '@rsuite/icons/Code';
import PageIcon from '@rsuite/icons/Page';
import DetailIcon from '@rsuite/icons/Detail';
import FolderFillIcon from '@rsuite/icons/FolderFill';
import FileDownloadIcon from '@rsuite/icons/FileDownload';
import FileUploadIcon from '@rsuite/icons/FileUpload';
  
function App() {
    return (
        <div>
            <h1 style={{ color: 'green' }}>
                GeeksforGeeks
            </h1>
            <h3>React Suite Dropdown  with Icon</h3>
              
            <Dropdown title="GeeksforGeeks"
                icon={<CodeIcon style={{ color: 'red' }} />}>
                <Dropdown.Item icon={<PageIcon 
                    style={{ color: 'green' }} />}>New File
                </Dropdown.Item>
                <Dropdown.Item icon={<FolderFillIcon 
                    style={{ color: 'violet' }} />}>
                    New File with Current Profile
                </Dropdown.Item>
                <Dropdown.Item icon={<FileDownloadIcon 
                    style={{ color: 'orange' }} />}>
                    Download As...
                </Dropdown.Item>
                <Dropdown.Item icon={<DetailIcon 
                    style={{ color: 'yellow' }} />}>Export PDF
                </Dropdown.Item>
                <Dropdown.Item icon={<FileUploadIcon 
                    style={{ color: 'blue' }} />}>File Upload
                </Dropdown.Item>
                <Dropdown.Item icon={<DetailIcon 
                    style={{ color: 'pink' }} />}>Exit
                </Dropdown.Item>
            </Dropdown>
        </div>
    )
}
  
export default App;


Output:

 

Reference: https://rsuitejs.com/components/dropdown/#dropdown-with-icon


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!