Skip to content
Related Articles
Open in App
Not now

Related Articles

React Suite Dropdown Used with Popover

Improve Article
Save Article
  • Last Updated : 18 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. 

The dropdown component with popover basically opens a dropdown menu as a pop-up box when user click the button.

Syntax

<PopOver>
    <Dropdown.Menu>
          <Dropdown.Item>Item </Dropdown.Item>
   </Dropdown.Menu>
</PopOver>

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 create a simple popover and add dropdown options to it.

Javascript




import react from 'react'
import 'rsuite/dist/rsuite.min.css';
import Dropdown from 'rsuite/Dropdown';
import Popover from 'rsuite/Popover';
import Whisper from 'rsuite/Whisper';
import Button from '@mui/material/Button';
  
export default function App() {
    const speaker = (
        <Popover full>
            <Dropdown.Menu >
                <Dropdown.Menu title="New File">
                    <Dropdown.Item >New File</Dropdown.Item>
                    <Dropdown.Item >
                        New File with Current Profile
                    </Dropdown.Item>
                </Dropdown.Menu>
                <Dropdown.Item >Download As...</Dropdown.Item>
                <Dropdown.Item >Export PDF</Dropdown.Item>
                <Dropdown.Item >Export HTML</Dropdown.Item>
                <Dropdown.Item >Settings</Dropdown.Item>
                <Dropdown.Item >About</Dropdown.Item>
            </Dropdown.Menu>
        </Popover>
    )
    return (
        <div className="App">
            <h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
            <h3>React Suite Dropdown Used With Popover</h3>
            <Whisper placement="bottomStart" 
                trigger="click" speaker={speaker}>
                <Button variant="contained">File</Button>
            </Whisper>
        </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:

 

Example 2: In this example, we will change the placement of popovers. We can set the placement in Whisper component. Here you will get dropdown popover in LeftStart and RightEnd direction

Javascript




import react from 'react'
import 'rsuite/dist/rsuite.min.css';
import Dropdown from 'rsuite/Dropdown';
import Popover from 'rsuite/Popover';
import Whisper from 'rsuite/Whisper';
import Button from '@mui/material/Button';
  
export default function App() {
    const speaker = (
        <Popover full >
            <Dropdown.Menu >
                <Dropdown.Menu title="India">
                    <Dropdown.Item >UP</Dropdown.Item>
                    <Dropdown.Item >Delhi</Dropdown.Item>
                </Dropdown.Menu>
                <Dropdown.Item >America</Dropdown.Item>
                <Dropdown.Item >Russia</Dropdown.Item>
                <Dropdown.Item >Australia</Dropdown.Item>
                <Dropdown.Item >Africa</Dropdown.Item>
                <Dropdown.Item >China</Dropdown.Item>
            </Dropdown.Menu>
        </Popover>
    )
  
    return (
        <div className="App">
            <h1 style={{ color: 'green' }}>GeeksforGeeks</h1>
            <h3>React Suite Dropdown Used With Popover</h3>
            <center>
                <Whisper placement="leftStart" 
                    trigger="click" speaker={speaker}>
                    <Button variant="contained" >Left Start</Button>
                </Whisper>
            </center>
            <br />
            <center>
                <Whisper placement="rightEnd" trigger="click" 
                    speaker={speaker}>
                    <Button variant="contained" 
                        color="success">Right End</Button>
                </Whisper></center>
        </div>
    );
}


Output:

 

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


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!