Search results

Template

In Dialog the template support is provided to the header and footer sections. So any text or HTML content can be appending in these sections.

The Dialog header content can be provided through the header property, and it will allow both text and any HTML content as a string. Also in header, close button is provided as built-in support, and this can be enabled through the showCloseIcon property.

The Dialog footer can be enabled by adding built-in buttons or providing any HTML string through the footerTemplate.

The buttons and footerTemplate properties can’t be used at the same time.

The below example demonstrates the usage of header and footer template in the Dialog

Source
Preview
index.tsx
index.html
import { DialogComponent } from '@syncfusion/ej2-react-popups';
    import * as React from "react";
    import * as ReactDOM from "react-dom";

    export class Default extends React.Component {
    public dialogInstance: DialogComponent;
    public buttonInstance: HTMLElement;
    public dialogTextInstance: HTMLSpanElement;

    public handleClick = () => {
        this.dialogInstance.show();
    }

    public header(): JSX.Element {
        return (
        <div>
            <img className="img2" src="https://ej2.syncfusion.com/products/typescript/dialog/template/images/1.png"/>
            <div title="Nancy" className="e-icon-settings dlg-template">Nancy</div>
        </div>
        )
    }

    public footerTemplate(): JSX.Element {
        return (
            <div>
                <input id="inVal" className="e-input" type="text"  placeholder="Enter your message here!"/>

                <button id="sendButton" className="e-control e-btn e-primary" data-ripple="true">Send</button>
            </div>
        )
    }

    public dialogClose = () => {
        this.buttonInstance.style.display='inline-block';
    }

    public dialogOpen = () => {
        this.buttonInstance.style.display='none';
    }

    public keyDown = (e: any) => {
                if (e.keyCode === 13) { this.updateTextValue(); }
    }

    public updateTextValue = () => {
        const enteredVal: HTMLInputElement = document.getElementById('inVal') as HTMLInputElement;
        const dialogTextElement: HTMLElement = document.getElementsByClassName('dialogText')[0] as HTMLElement;
        if ( enteredVal.value !== '') {
            dialogTextElement.innerHTML = enteredVal.value;
        }
        enteredVal.value = '';

    }

    public componentDidMount() {
        setTimeout(() => {
            (document as any).getElementById('sendButton').onkeydown = (e: any) => {
                if (e.keyCode === 13) { this.updateTextValue(); }
            };

            (document as any).getElementById('inVal').onkeydown = (e: any) => {
                if (e.keyCode === 13) { this.updateTextValue(); }
            };

            (document as any).getElementById('sendButton').onclick = (): void => {
                this.updateTextValue();
            };
        });
    }

    public render() {
      return (
      <div className="App" id='container'>
          <button className='e-control e-btn' id='targetButton1' ref={buttonElement => this.buttonInstance = buttonElement!} role='button' onClick={this.handleClick = this.handleClick}>Open</button>

          <DialogComponent width='350px' target='#container' header={this.header} footerTemplate={this.footerTemplate } showCloseIcon={true}
           open= {this.dialogOpen} close= {this.dialogClose}
           ref={dialog => this.dialogInstance = dialog!}>
                <div className="dialogContent">
                        <span className="dialogText"  ref={dialogTextElement => this.dialogTextInstance = dialogTextElement!}>Greetings Nancy! When will you share me the source files of the project?</span>
                </div>
          </DialogComponent>
      </div>);
    }
 }

ReactDOM.render(<Default />, document.getElementById('dialog'));
<!DOCTYPE html>
<html lang="en">

<head>
    <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="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-react-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-inputs/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

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

</html>

See Also