Wednesday, July 3, 2024
HomeLanguagesReactReact Suite Dropdown Used with Popover

React Suite Dropdown Used with Popover

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' }}>neveropen</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' }}>neveropen</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

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!

Dominic Rubhabha Wardslaus
Dominic Rubhabha Wardslaushttps://neveropen.dev
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments