Search results

Customization of predefined dialogs in React Predefined Dialogs component

25 Jan 2023 / 8 minutes to read

You can customize the predefined dialogs buttons by using below properties.

  • okButton - Use this property to customize OK button text.
  • cancelButton - Use this property to customize Cancel button text.

Use the following code snippet for alert, confirm and prompt to customize the predefined dialogs action buttons.

For alert dialog , customized the default dialog button content as Dismiss by using the text property.

For confirm dialog, customized the default dialog buttons content as Yes and No by using the text property and also customized the dialog button icons by using icon property.

For prompt dialog , customized the default dialog buttons content as Connect and Close by using text property.

Alert action button

[Class-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    buttonClick() {
        DialogUtility.alert({
            title: 'Low Battery',
            content: '10% of battery remaining',
            width: '250px',
            okButton: { text: 'Dismiss' }
        });
    }
    render() {
        return (<div className="App" id='dialog-target'>
   <ButtonComponent id="alertBtn" cssClass="e-danger" onClick={this.buttonClick.bind(this)}>Alert</ButtonComponent>
  </div>);
    }
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

class App extends React.Component<{}, {}> {
constructor(props: {}) {
    super(props);
    this.state = { };
}
public buttonClick() {
DialogUtility.alert({
    title: 'Low Battery',
    content: '10% of battery remaining',
    width : '250px',
    okButton: { text: 'Dismiss'}
});
}
public render() {
  return (
  <div className="App" id='dialog-target'>
   <ButtonComponent id="alertBtn" cssClass="e-danger" onClick={this.buttonClick.bind(this)}>Alert</ButtonComponent>
  </div>);
   }
}
export default App;

[Functional-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
function App() {
    function buttonClick() {
        DialogUtility.alert({
            title: 'Low Battery',
            content: '10% of battery remaining',
            width: '250px',
            okButton: { text: 'Dismiss' }
        });
    }
    return (<div className="App" id='dialog-target'>
    <ButtonComponent id="alertBtn" cssClass="e-danger" onClick={buttonClick.bind(this)}>Alert</ButtonComponent>
</div>);
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

function App() {
  function buttonClick() {
  DialogUtility.alert({
      title: 'Low Battery',
      content: '10% of battery remaining',
      width : '250px',
      okButton: { text: 'Dismiss'}
  });
  }
  return (
<div className="App" id='dialog-target'>
    <ButtonComponent id="alertBtn" cssClass="e-danger" onClick={buttonClick.bind(this)}>Alert</ButtonComponent>
</div>
  );
}
export default App;

Confirm action buttons

[Class-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    buttonClick() {
        DialogUtility.confirm({
            title: 'Delete Multiple Items',
            content: 'Are you sure you want to permanently delete these items?',
            width: '300px',
            okButton: { text: 'Yes', icon: 'e-icons e-check' },
            cancelButton: { text: 'No', icon: 'e-icons e-close' }
        });
    }
    render() {
        return (<div className="App" id='dialog-target'>
   <ButtonComponent id="confirmBtn" cssClass="e-success" onClick={this.buttonClick.bind(this)}>Confirm</ButtonComponent>
  </div>);
    }
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

class App extends React.Component<{}, {}> {
constructor(props: {}) {
    super(props);
    this.state = { };
}
public buttonClick() {
DialogUtility.confirm({
    title: 'Delete Multiple Items',
    content: 'Are you sure you want to permanently delete these items?',
    width:'300px',
    okButton: { text: 'Yes', icon:'e-icons e-check'},
    cancelButton: {text:'No', icon:'e-icons e-close'}
});
}
public render() {
  return (
  <div className="App" id='dialog-target'>
   <ButtonComponent id="confirmBtn" cssClass="e-success" onClick={this.buttonClick.bind(this)}>Confirm</ButtonComponent>
  </div>);
   }
}
export default App;

[Functional-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
function App() {
    function buttonClick() {
        DialogUtility.confirm({
            title: 'Delete Multiple Items',
            content: 'Are you sure you want to permanently delete these items?',
            width: '300px',
            okButton: { text: 'Yes', icon: 'e-icons e-check' },
            cancelButton: { text: 'No', icon: 'e-icons e-close' }
        });
    }
    return (<div className="App" id='dialog-target'>
    <ButtonComponent id="confirmBtn" cssClass="e-success" onClick={buttonClick.bind(this)}>Confirm</ButtonComponent>
</div>);
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

function App() {
  function buttonClick() {
  DialogUtility.confirm({
      title: 'Delete Multiple Items',
      content: 'Are you sure you want to permanently delete these items?',
      width:'300px',
      okButton: { text: 'Yes', icon:'e-icons e-check'},
      cancelButton: {text:'No', icon:'e-icons e-close'}
  });
  }
  return (
<div className="App" id='dialog-target'>
    <ButtonComponent id="confirmBtn" cssClass="e-success" onClick={buttonClick.bind(this)}>Confirm</ButtonComponent>
</div>
  );
}
export default App;

Prompt action buttons

[Class-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    buttonClick() {
        DialogUtility.confirm({
            title: 'Join Chat Group',
            content: '<p>Enter your name:</p><input type="text" name="Required" class="e-input" placeholder="Type here.." />',
            height: '200px',
            okButton: { text: 'Connect' },
            cancelButton: { text: 'Close' }
        });
    }
    render() {
        return (<div className="App" id='dialog-target'>
    <ButtonComponent id="promptBtn" isPrimary onClick={this.buttonClick.bind(this)}>Prompt</ButtonComponent>
  </div>);
    }
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

class App extends React.Component<{}, {}> {
constructor(props: {}) {
    super(props);
    this.state = { };
}
public buttonClick() {
DialogUtility.confirm({
  title: 'Join Chat Group',
  content:
    '<p>Enter your name:</p><input type="text" name="Required" class="e-input" placeholder="Type here.." />',
  height: '200px',
  okButton: { text: 'Connect'},
  cancelButton: {text:'Close'}
});
}
public render() {
  return (
  <div className="App" id='dialog-target'>
    <ButtonComponent id="promptBtn" isPrimary onClick={this.buttonClick.bind(this)}>Prompt</ButtonComponent>
  </div>);
   }
}
export default App;

[Functional-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
function App() {
    function buttonClick() {
        DialogUtility.confirm({
            title: 'Join Chat Group',
            content: '<p>Enter your name:</p><input type="text" name="Required" class="e-input" placeholder="Type here.." />',
            height: '200px',
            okButton: { text: 'Connect' },
            cancelButton: { text: 'Close' }
        });
    }
    return (<div className="App" id='dialog-target'>
      <ButtonComponent id="promptBtn" isPrimary onClick={buttonClick.bind(this)}>Prompt</ButtonComponent>
</div>);
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

function App() {
  function buttonClick() {
  DialogUtility.confirm({
    title: 'Join Chat Group',
    content:
      '<p>Enter your name:</p><input type="text" name="Required" class="e-input" placeholder="Type here.." />',
    height: '200px',
    okButton: { text: 'Connect'},
    cancelButton: {text:'Close'}
  });
  }
  return (
<div className="App" id='dialog-target'>
      <ButtonComponent id="promptBtn" isPrimary onClick={buttonClick.bind(this)}>Prompt</ButtonComponent>
</div>
  );
}
export default App;

Show or hide dialog close button

When rendering the predefined dialogs through utility methods, You can close the dialog using the following ways. The default values of closeOnEscape and showCloseIcon is false.

  • By pressing the escape key if the closeOnEscape property is enabled.
  • By clicking the close button if the showCloseIcon property is enabled.

You can also manually close the Dialogs by creating an instance to the dialog and call the hide method.

Use the following code for alert, confirm and prompt to demonstrates the different ways of hiding the utility dialog.

Alert dialog close button

[Class-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    buttonClick() {
        DialogUtility.alert({
            title: 'Low Battery',
            width: '250px',
            content: '10% of battery remaining',
            showCloseIcon: true,
            closeOnEscape: true
        });
    }
    render() {
        return (<div className="App" id='dialog-target'>
   <ButtonComponent id="alertBtn" cssClass="e-danger" onClick={this.buttonClick.bind(this)}>Alert</ButtonComponent>
  </div>);
    }
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

class App extends React.Component<{}, {}> {
constructor(props: {}) {
    super(props);
    this.state = { };
}
public buttonClick() {
DialogUtility.alert({
    title: 'Low Battery',
    width: '250px',
    content: '10% of battery remaining',
    showCloseIcon : true,
    closeOnEscape : true
});
}
public render() {
  return (
  <div className="App" id='dialog-target'>
   <ButtonComponent id="alertBtn" cssClass="e-danger" onClick={this.buttonClick.bind(this)}>Alert</ButtonComponent>
  </div>);
   }
}
export default App;

[Functional-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
function App() {
    function buttonClick() {
        DialogUtility.alert({
            title: 'Low Battery',
            width: '250px',
            content: '10% of battery remaining',
            showCloseIcon: true,
            closeOnEscape: true
        });
    }
    return (<div className="App" id='dialog-target'>
    <ButtonComponent id="alertBtn" cssClass="e-danger" onClick={buttonClick.bind(this)}>Alert</ButtonComponent>
</div>);
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

function App() {
  function buttonClick() {
  DialogUtility.alert({
      title: 'Low Battery',
      width: '250px',
      content: '10% of battery remaining',
      showCloseIcon : true,
      closeOnEscape : true
  });
  }

  return (
<div className="App" id='dialog-target'>
    <ButtonComponent id="alertBtn" cssClass="e-danger" onClick={buttonClick.bind(this)}>Alert</ButtonComponent>
</div>
  );
}
export default App;

Confirm dialog close button

[Class-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    buttonClick() {
        DialogUtility.confirm({
            title: 'Delete Multiple Items',
            content: 'Are you sure you want to permanently delete these items?',
            width: '300px',
            showCloseIcon: true,
            closeOnEscape: true
        });
    }
    render() {
        return (<div className="App" id='dialog-target'>
   <ButtonComponent id="confirmBtn" cssClass="e-success" onClick={this.buttonClick.bind(this)}>Confirm</ButtonComponent>
  </div>);
    }
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

class App extends React.Component<{}, {}> {
constructor(props: {}) {
    super(props);
    this.state = { };
}
public buttonClick() {
DialogUtility.confirm({
    title: 'Delete Multiple Items',
    content: 'Are you sure you want to permanently delete these items?',
    width:'300px',
    showCloseIcon : true,
    closeOnEscape : true
});
}
public render() {
  return (
  <div className="App" id='dialog-target'>
   <ButtonComponent id="confirmBtn" cssClass="e-success" onClick={this.buttonClick.bind(this)}>Confirm</ButtonComponent>
  </div>);
   }
}
export default App;

[Functional-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
function App() {
    function buttonClick() {
        DialogUtility.confirm({
            title: 'Delete Multiple Items',
            content: 'Are you sure you want to permanently delete these items?',
            width: '300px',
            showCloseIcon: true,
            closeOnEscape: true
        });
    }
    return (<div className="App" id='dialog-target'>
    <ButtonComponent id="confirmBtn" cssClass="e-success" onClick={buttonClick.bind(this)}>Confirm</ButtonComponent>
</div>);
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

function App() {
  function buttonClick() {
  DialogUtility.confirm({
      title: 'Delete Multiple Items',
      content: 'Are you sure you want to permanently delete these items?',
      width:'300px',
      showCloseIcon : true,
      closeOnEscape : true
  });
  }

  return (
<div className="App" id='dialog-target'>
    <ButtonComponent id="confirmBtn" cssClass="e-success" onClick={buttonClick.bind(this)}>Confirm</ButtonComponent>
</div>
  );
}
export default App;

Prompt dialog close button

[Class-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    buttonClick() {
        DialogUtility.confirm({
            title: 'Join Chat Group',
            content: '<p>Enter your name:</p> <input type="text" name="Required" class="e-input" placeholder="Type here.." />',
            width: '300px',
            showCloseIcon: true,
            closeOnEscape: true
        });
    }
    render() {
        return (<div className="App" id='dialog-target'>
    <ButtonComponent id="promptBtn" isPrimary onClick={this.buttonClick.bind(this)}>Prompt</ButtonComponent>
  </div>);
    }
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

class App extends React.Component<{}, {}> {
constructor(props: {}) {
    super(props);
    this.state = { };
}
public buttonClick() {
DialogUtility.confirm({
  title: 'Join Chat Group',
  content:
    '<p>Enter your name:</p> <input type="text" name="Required" class="e-input" placeholder="Type here.." />',
  width: '300px',
  showCloseIcon : true,
  closeOnEscape : true
});
}
public render() {
  return (
  <div className="App" id='dialog-target'>
    <ButtonComponent id="promptBtn" isPrimary onClick={this.buttonClick.bind(this)}>Prompt</ButtonComponent>
  </div>);
   }
}
export default App;

[Functional-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
function App() {
    function buttonClick() {
        DialogUtility.confirm({
            title: 'Join Chat Group',
            content: '<p>Enter your name:</p> <input type="text" name="Required" class="e-input" placeholder="Type here.." />',
            width: '300px',
            showCloseIcon: true,
            closeOnEscape: true
        });
    }
    return (<div className="App" id='dialog-target'>
      <ButtonComponent id="promptBtn" isPrimary onClick={buttonClick.bind(this)}>Prompt</ButtonComponent>
</div>);
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";

function App() {
  function buttonClick() {
  DialogUtility.confirm({
    title: 'Join Chat Group',
    content:
      '<p>Enter your name:</p> <input type="text" name="Required" class="e-input" placeholder="Type here.." />',
    width: '300px',
    showCloseIcon : true,
    closeOnEscape : true
  });
  }

  return (
<div className="App" id='dialog-target'>
      <ButtonComponent id="promptBtn" isPrimary onClick={buttonClick.bind(this)}>Prompt</ButtonComponent>
</div>
  );

}
export default App;

Customize dialog content

You can load custom content in predefined dialogs using the content property.

Use the following code to customize the dialog content to render the custom TextBox component inside the prompt dialog to get the username from the user.

[Class-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
class App extends React.Component {
    constructor(props) {
        super(props);
        this.state = {};
    }
    buttonClick() {
        DialogUtility.confirm({
            title: 'Join Chat Group',
            content: '<p>Enter your name:</p><input class="e-input" placeholder="Type here.." />',
            width: '300px',
        });
    }
    render() {
        return (<div className="App" id='dialog-target'>
    <ButtonComponent id="promptBtn" isPrimary onClick={this.buttonClick.bind(this)}>Prompt</ButtonComponent>
  </div>);
    }
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import { TextBoxComponent } from '@syncfusion/ej2-react-inputs';
import * as React from "react";

class App extends React.Component<{}, {}> {
constructor(props: {}) {
    super(props);
    this.state = { };
}
public buttonClick() {
DialogUtility.confirm({
  title: 'Join Chat Group',
  content:
    '<p>Enter your name:</p><input class="e-input" placeholder="Type here.." />',
  width: '300px',
});
}
public render() {
  return (
  <div className="App" id='dialog-target'>
    <ButtonComponent id="promptBtn" isPrimary onClick={this.buttonClick.bind(this)}>Prompt</ButtonComponent>
  </div>);
   }
}
export default App;

[Functional-component]

Source
Preview
App.jsx
App.tsx
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import * as React from "react";
function App() {
    function buttonClick() {
        DialogUtility.confirm({
            title: 'Join Chat Group',
            content: '<p>Enter your name:</p><input class="e-input" placeholder="Type here.." />',
            width: '300px',
        });
    }
    return (<div className="App" id='dialog-target'>
      <ButtonComponent id="promptBtn" isPrimary onClick={buttonClick.bind(this)}>Prompt</ButtonComponent>
</div>);
}
export default App;
Copied to clipboard
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogUtility } from '@syncfusion/ej2-react-popups';
import { TextBoxComponent } from '@syncfusion/ej2-react-inputs';
import * as React from "react";

function App() {
  function buttonClick() {
  DialogUtility.confirm({
    title: 'Join Chat Group',
    content:
      '<p>Enter your name:</p><input class="e-input" placeholder="Type here.." />',
    width: '300px',
  });
  }

  return (
<div className="App" id='dialog-target'>
      <ButtonComponent id="promptBtn" isPrimary onClick={buttonClick.bind(this)}>Prompt</ButtonComponent>
</div>
  );
}
export default App;