Open In App

React.js Blueprint Popover2 Closing on click

Blueprint is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex and data-dense for desktop applications.

In this article, we’ll discuss React.js Blueprint Popover2 Closing on click. Popovers help in displaying the floating content next to the target element. Closing on click is used in dismissing a popover element and also its nested children element.



BluePrint Popover2 Closing on click classes:

 



React.js BluePrint Popover2 Props:

Syntax:

<div className={Classes.POPOVER2_DISMISS}>
   <button>Dismiss</button>
   <button disabled={true}>I can't dismiss</button>
   <div className={Classes.POPOVER2_DISMISS_OVERRIDE}>
       <button>I also not dismiss</button>
   </div>
</div>

Creating React Application And Installing Module:

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

npm create-react-app appname

Step 2: After creating your project folder i.e. appname, move to it using the following command:

cd appname

Step 3: After creating the ReactJS application, Install the required module using the following command:

npm install @blueprintjs/core

Project Structure:

 

Example 1: The below example demonstrates the usage of the POPOVER2_DISMISS class of popover2.




import React from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import { Button } from "@blueprintjs/core";
import { Popover2, Classes } from "@blueprintjs/popover2";
import "@blueprintjs/popover2/lib/css/blueprint-popover2.css";
  
function App() {
    return (
        <center>
            <div style={{ padding: 20, textAlign: "center"
                color: "green" }}>
                <h1>GeeksforGeeks</h1>
                <h2>
                    ReactJS BluePrint Popover2 Closing on click
                </h2>
            </div>
            <Popover2
                position="bottom"
                content={
                    <div
                        className={Classes.POPOVER2_DISMISS}
                        style={{ backgroundColor: "#F0EFEF"
                            padding: 20 }}
                    >
                        <Button intent="danger">
                            Dismiss
                        </Button>
                    </div>
                }
                renderTarget={({ isOpen, ref, ...targetProps }) => (
                    <Button
                        {...targetProps}
                        elementRef={ref}
                        text="Delete"
                        intent="danger"
                    />
                )}
            />
        </center>
    );
}
  
export default App;

Output:

 

Example 2: The below example demonstrates the usage of the POPOVER2_DISMISS_OVERRIDE class of popover2.




import React from "react";
import "@blueprintjs/core/lib/css/blueprint.css";
import { Button, Callout } from "@blueprintjs/core";
import { Popover2, Classes } from "@blueprintjs/popover2";
import "@blueprintjs/popover2/lib/css/blueprint-popover2.css";
  
function App() {
    return (
        <center>
            <div style={{ padding: 20, textAlign: "center"
                color: "green" }}>
                <h1>GeeksforGeeks</h1>
                <h2>ReactJS BluePrint Popover2 Closing on click</h2>
            </div>
            <Popover2
                position="bottom"
                content={
                    <div
                        className={Classes.POPOVER2_DISMISS}
                        style={{ backgroundColor: "#F0EFEF"
                            padding: 20 }}
                    >
                        <Button intent="danger">Dismiss</Button>
                        <Callout intent="warning" className=
                            {Classes.POPOVER2_DISMISS}>
                            <p>Click callout to dismiss.</p>
                            <div>
                                <Button
                                    className=
                                    {Classes.POPOVER2_DISMISS_OVERRIDE}
                                    intent="success"
                                    text="Dismiss override"
                                />
                            </div>
                        </Callout>
                    </div>
                }
                renderTarget={({ isOpen, ref, ...targetProps }) => (
                    <Button
                        {...targetProps}
                        elementRef={ref}
                        text="Delete"
                        intent="danger"
                    />
                )}
            />
        </center>
    );
}
  
export default App;

Output:

 

Reference: https://blueprintjs.com/docs/#popover2-package/popover2.closing-on-click


Article Tags :