Search results

Close Dialog when click outside of its region in React Dialog component

18 Jan 2022 / 2 minutes to read

By default, dialog can be closed by pressing Esc key and clicking the close icon on the right of dialog header. It can also be closed by clicking outside of the dialog using hide method. Set the CloseOnEscape property value to false to prevent closing of the dialog when pressing Esc key.

In the following sample, dialog is closed when clicking outside the dialog area using hide method.

Copied to clipboard
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import App  from './App';

ReactDOM.render(<App />, document.getElementById('container'));
Copied to clipboard
<!DOCTYPE html>
<html lang="en">

    <title>Syncfusion React Dialog</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Essential JS 2 for React Components" />
    <meta name="author" content="Syncfusion" />
    <link href="styles.css" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <link href="//" rel="stylesheet" />
    <script src=""></script>
    <script src="systemjs.config.js"></script>

    <div id='container'>
        <div id="dialog">
            <div id='loader'>Loading....</div>

Copied to clipboard
import { DialogComponent } from '@syncfusion/ej2-react-popups';
import * as React from "react";
import './App.css';
class App extends React.Component {
    constructor() {
        this.settings = { effect: 'Zoom', duration: 400, delay: 0 };
        this.buttons = [{
                buttonModel: {
                    content: 'Close',
                    cssClass: 'e-flat',
                    isPrimary: true,
                'click': () => {
    handleClick() {;
    componentDidMount() {
        document.onclick = (args) => {
            if ( === 'dialog-target') {
    render() {
        return (<div className="App" id='dialog-target'>
    <button className='e-control e-btn' id='targetButton1' role='button' onClick={this.handleClick = this.handleClick.bind(this)}>Open</button>
    <DialogComponent header='Delete Multiple Items' showCloseIcon={true} visible={true} animationSettings={this.settings} width='300px' buttons={this.buttons} closeOnEscape={true} content='Are you sure you want to permanently delete all of these items?' ref={dialog => this.dialogInstance = dialog} target='#dialog-target'/>
export default App;