The dialog component provides built-in utility functions to render the alert and confirm dialogs with the minimal code. The following options are used as an argument on calling the utility functions:
Options | Description |
---|---|
title | Specifies the title of dialog like the header property. |
content | Specifies the value that can be displayed in dialog’s content area like the content property. |
isModal | Specifies the Boolean value whether the dialog can be displayed as modal or non-modal. For more details, refer to the isModal property. |
position | Specifies the value where the alert or confirm dialog is positioned within the document. For more details, refer to the position property { X: ‘center’, Y: ‘center’} |
okButton | Configures the OK button that contains button properties with the click events. okButton:{ icon:'prefix icon to the button', cssClass:'custom class to the button', click: 'action for OK button click', text: 'Yes' // <-- Default value is 'OK' } |
cancelButton | Configures the Cancel button that contains button properties with the click events. cancelButton:{ icon:'prefix icon to the button', cssClass:'custom class to the button', click: 'action for ‘Cancel’ button click', text: 'No' // <-- Default value is 'Cancel'} |
isDraggable | Specifies the value whether the alert or confirm dialog can be dragged by the user. |
showCloseIcon | When set to true, the close icon is shown in the dialog component. |
closeOnEscape | When set to true, you can close the dialog by pressing ESC key. |
animationSettings | Specifies the animation settings of the dialog component. |
cssClass | Specifies the CSS class name that can be appended to the dialog. |
zIndex | Specifies the order of the dialog, that is displayed in front or behind of another component. |
open | Event which is triggered after the dialog is opened. |
Close | Event which is triggered after the dialog is closed. |
An alert dialog box is used to display warning like messages to the users. Use the following code to render a simple alert dialog in an application.
import { DialogUtility } from '@syncfusion/ej2-popups';
import * as React from "react";
class App extends React.Component {
buttonClick() {
DialogUtility.alert('This is an Alert Dialog!');
}
render() {
return (<button className="e-control e-btn" onClick={this.buttonClick} id="targetButton" role="button">Open Alert Dialog</button>);
}
}
export default App;
import { DialogUtility } from '@syncfusion/ej2-popups';
import * as React from "react";
class App extends React.Component<{}, {}> {
public buttonClick(): void {
DialogUtility.alert('This is an Alert Dialog!');
}
public render() {
return (
<button className="e-control e-btn" onClick={this.buttonClick} id="targetButton" role="button">Open Alert Dialog</button>);
}
}
export default App;
import { DialogUtility } from '@syncfusion/ej2-popups';
import * as React from "react";
class App extends React.Component {
buttonClick() {
DialogUtility.alert({
animationSettings: { effect: 'Zoom' },
closeOnEscape: true,
content: "This is an Alert Dialog!",
okButton: { text: 'OK', click: this.okClick.bind(this) },
showCloseIcon: true,
title: 'Alert Dialog'
});
}
okClick() {
alert('you clicked OK button');
}
render() {
return (<button className="e-control e-btn" onClick={this.buttonClick = this.buttonClick.bind(this)} id="targetButton" role="button">Open Alert Dialog</button>);
}
}
export default App;
import { DialogUtility } from '@syncfusion/ej2-popups';
import * as React from "react";
class App extends React.Component<{}, {}> {
public buttonClick(): void {
DialogUtility.alert({
animationSettings: { effect: 'Zoom' },
closeOnEscape: true,
content: "This is an Alert Dialog!",
okButton: { text: 'OK', click: this.okClick.bind(this) },
showCloseIcon: true,
title: 'Alert Dialog'
});
}
public okClick(): void {
alert('you clicked OK button');
}
public render() {
return (
<button className="e-control e-btn" onClick={this.buttonClick = this.buttonClick.bind(this)} id="targetButton" role="button">Open Alert Dialog</button>);
}
}
export default App;
A confirm dialog displays a specified message along with ‘OK’ and ‘Cancel’ button.
import { DialogUtility } from '@syncfusion/ej2-popups';
import * as React from "react";
class App extends React.Component {
buttonClick() {
DialogUtility.confirm('This is a Confirmation Dialog!');
}
render() {
return (<button className="e-control e-btn" onClick={this.buttonClick = this.buttonClick.bind(this)} id="targetButton" role="button">Open Confirm Dialog</button>);
}
}
export default App;
import { DialogUtility } from '@syncfusion/ej2-popups';
import * as React from "react";
class App extends React.Component<{}, {}> {
public buttonClick(): void {
DialogUtility.confirm('This is a Confirmation Dialog!');
}
public render() {
return (
<button className="e-control e-btn" onClick={this.buttonClick = this.buttonClick.bind(this)} id="targetButton" role="button">Open Confirm Dialog</button>
);
}
}
export default App;
import { DialogUtility } from '@syncfusion/ej2-popups';
import * as React from "react";
class App extends React.Component {
buttonClick() {
DialogUtility.confirm({
animationSettings: { effect: 'Zoom' },
cancelButton: { text: 'Cancel', click: this.cancelClick.bind(this) },
closeOnEscape: true,
content: "This is a Confirmation Dialog!",
okButton: { text: 'OK', click: this.okClick.bind(this) },
showCloseIcon: true,
title: ' Confirmation Dialog',
});
}
okClick() {
alert('you clicked OK button');
}
cancelClick() {
alert('you clicked Cancel button');
}
render() {
return (<button className="e-control e-btn" onClick={this.buttonClick = this.buttonClick.bind(this)} id="targetButton" role="button">Open Confirm Dialog</button>);
}
}
export default App;
import { DialogUtility } from '@syncfusion/ej2-popups';
import * as React from "react";
class App extends React.Component<{}, {}> {
public buttonClick(): void {
DialogUtility.confirm({
animationSettings: { effect: 'Zoom' },
cancelButton: { text: 'Cancel', click: this.cancelClick.bind(this) },
closeOnEscape: true,
content: "This is a Confirmation Dialog!",
okButton: { text: 'OK', click: this.okClick.bind(this) },
showCloseIcon: true,
title: ' Confirmation Dialog',
});
}
public okClick(): void {
alert('you clicked OK button');
}
public cancelClick(): void {
alert('you clicked Cancel button');
}
public render() {
return (
<button className="e-control e-btn" onClick={this.buttonClick = this.buttonClick.bind(this)} id="targetButton" role="button">Open Confirm Dialog</button>
);
}
}
export default App;
When rendering an Alert and Confirmation dialog through utility methods, You can close the dialog using the following ways.
You can also manually close the Dialogs by creating an instance to the dialog and call the hide method.
Below sample demonstrates the different ways of hiding the utility dialog.
import { DialogUtility } from '@syncfusion/ej2-popups';
import * as React from "react";
const DialogObj;
class App extends React.Component {
buttonClick() {
DialogObj = DialogUtility.confirm({
animationSettings: { effect: 'Zoom' },
cancelButton: { text: 'Cancel', click: this.cancelClick.bind(this) },
closeOnEscape: true,
content: "This is a Confirmation Dialog!",
okButton: { text: 'OK', click: this.okClick.bind(this) },
showCloseIcon: true,
title: ' Confirmation Dialog',
});
}
okClick() {
alert('you clicked OK button');
}
cancelClick() {
//Hide the dialog
DialogObj.hide();
}
render() {
return (<button className="e-control e-btn" onClick={this.buttonClick = this.buttonClick.bind(this)} id="targetButton" role="button">Open Confirm Dialog</button>);
}
}
export default App;
import { DialogUtility } from '@syncfusion/ej2-popups';
import * as React from "react";
const DialogObj;
class App extends React.Component<{}, {}> {
public buttonClick(): void {
DialogObj = DialogUtility.confirm({
animationSettings: { effect: 'Zoom' },
cancelButton: { text: 'Cancel', click: this.cancelClick.bind(this) },
closeOnEscape: true,
content: "This is a Confirmation Dialog!",
okButton: { text: 'OK', click: this.okClick.bind(this) },
showCloseIcon: true,
title: ' Confirmation Dialog',
});
}
public okClick(): void {
alert('you clicked OK button');
}
public cancelClick(): void {
//Hide the dialog
DialogObj.hide();
}
public render() {
return (
<button className="e-control e-btn" onClick={this.buttonClick = this.buttonClick.bind(this)} id="targetButton" role="button">Open Confirm Dialog</button>
);
}
}
export default App;