Open In App

React Suite Dropdown Trigger

A React suite is a library of React components, sensible UI design, and a friendly development experience. It is supported in all major browsers. It provides pre-built components of React which can be used easily in any web application.

In this article, we’ll learn about React suite dropdown trigger. A dropdown trigger sets the trigger event with the trigger attribute and supports the event which can be a click(default), hover, or contextMenu.



Syntax:

// Import Statement
import { Dropdown} from "rsuite/";

// App.Js File
Function App() {
   return (
       <Dropdown>
            <Dropdown.Item trigger="hover || contextMenu 
                || click">...</Dropdown.Item>
         </Dropdown>
   );
}

Dropdown Props:



Dropdown.Item Props:

Dropdown.Menu Props:

Creating React Application And Installing Module:

Step 1: Create a React application using the given command:

npm create-react-app projectname

Step 2: After creating your project, move to it using the given command:

cd projectname

Step 3: Now Install the rsuite node package using the given command:

npm install rsuite

Project Structure: Now your project structure should look like the following:

 

Example 1: Below example demonstrates the dropdown “click” trigger event.

Here, the dropdown lists the menu items after clicking the dropdown button.




import "rsuite/dist/rsuite.min.css";
import { Dropdown } from "rsuite";
  
export default function App() {
  return (
    <center>
      <div>
        <h2>GeeksforGeeks</h2>
        <h4 style={{ color: "green" }}>
          React Suite Dropdown Triggers
        </h4>
  
        <div style={{ marginTop: 20, width: 340 }}>
          <Dropdown title="Courses" trigger="click">
            <Dropdown.Item>Java</Dropdown.Item>
            <Dropdown.Item>C++</Dropdown.Item>
            <Dropdown.Item>DSA Self paced</Dropdown.Item>
          </Dropdown>
        </div>
      </div>
    </center>
  );
}

Output:

 

Example 2: Below example demonstrates the dropdown “hover” trigger event.

Here, the dropdown lists the menu items after hovering over the dropdown button.




import "rsuite/dist/rsuite.min.css";
import { Dropdown } from "rsuite";
  
export default function App() {
  return (
    <center>
      <div>
        <h2>GeeksforGeeks</h2>
        <h4 style={{ color: "green" }}>
          React Suite Dropdown Triggers
        </h4>
  
        <div style={{ marginTop: 20, width: 340 }}>
          <Dropdown title="Courses" trigger="hover">
            <Dropdown.Item>Java</Dropdown.Item>
            <Dropdown.Item>C++</Dropdown.Item>
            <Dropdown.Item>DSA Self paced</Dropdown.Item>
          </Dropdown>
        </div>
      </div>
    </center>
  );
}

Output:

 

Example 3: Below example demonstrates the dropdown “contextMenu” trigger event.

Here, the dropdown lists the menu items after right-clicking the dropdown button.




import "rsuite/dist/rsuite.min.css";
import { Dropdown } from "rsuite";
  
export default function App() {
  return (
    <center>
      <div>
        <h2>GeeksforGeeks</h2>
        <h4 style={{ color: "green" }}>
          React Suite Dropdown Triggers
        </h4>
  
        <div style={{ marginTop: 20, width: 340 }}>
          <Dropdown title="Courses (rightClick)" trigger="contextMenu">
            <Dropdown.Item>Java</Dropdown.Item>
            <Dropdown.Item>C++</Dropdown.Item>
            <Dropdown.Item>DSA Self paced</Dropdown.Item>
          </Dropdown>
        </div>
      </div>
    </center>
  );
}

Output:

 

Reference: https://rsuitejs.com/components/dropdown/#trigger


Article Tags :