Search results

Open a dialog on popup item click

This section explains about how to open a dialog on SplitButton popup item click. This can be achieved by handling dialog open in select event of the SplitButton.

In the following example, Dialog will open while selecting Update... item.

Source
Preview
app.tsx
index.html
style.css
app.jsx
import { enableRipple } from '@syncfusion/ej2-base';
import { DialogComponent } from '@syncfusion/ej2-react-popups';
import { ItemModel, MenuEventArgs, SplitButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';

enableRipple(true);

// To render SplitButton.
class App extends React.Component<{}, {}> {
    public dialog: DialogComponent;
    public items: ItemModel[] = [
    {
        text: 'Help'
    },
    {
        text: 'About'
    },
    {
        text: 'Update...'
    }];

    public alertDlgButtons: any [] = [{
        buttonModel: {
            content: 'Ok',
            isPrimary: true
        },
        'click': () => {
            this.hide();
        }
    },
    {
        buttonModel: {
            content: 'Cancel',
            isPrimary: true
        },
        'click': () => {
            this.hide();
        }
    }];
    constructor(props: any) {
        super(props);
        this.select = this.select.bind(this);
    }
    public hide() {
        this.dialog.hide();
    }
    public select (args: MenuEventArgs) {
        if (args.item.text === 'Update...') {
            this.dialog.show();
        }
    }

  public render() {
    return (
    <div>
       <DialogComponent ref={dialog => this.dialog = dialog as DialogComponent} width='250px' id='dialog' content='Are you sure want to update?' header='Software Update' buttons={this.alertDlgButtons} visible={false}/>
       <SplitButtonComponent items = {this.items} select={this.select}>Help</SplitButtonComponent>
      </div>
    );
  }
}
ReactDom.render(<App />,document.getElementById('button'));
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Syncfusion React SplitButton</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="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
	<link href="style.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='button'>
            <div id='loader'>Loading....</div>
        </div>
</body>

</html>
#loader {
  color: #008cff;
  height: 40px;
  left: 45%;
  position: absolute;
  top: 45%;
  width: 30%;
}
import { enableRipple } from '@syncfusion/ej2-base';
import { DialogComponent } from '@syncfusion/ej2-react-popups';
import { SplitButtonComponent } from '@syncfusion/ej2-react-splitbuttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
enableRipple(true);
// To render SplitButton.
class App extends React.Component {
    constructor(props) {
        super(props);
        this.items = [
            {
                text: 'Help'
            },
            {
                text: 'About'
            },
            {
                text: 'Update...'
            }
        ];
        this.alertDlgButtons = [{
                buttonModel: {
                    content: 'Ok',
                    isPrimary: true
                },
                'click': () => {
                    this.hide();
                }
            },
            {
                buttonModel: {
                    content: 'Cancel',
                    isPrimary: true
                },
                'click': () => {
                    this.hide();
                }
            }];
        this.select = this.select.bind(this);
    }
    hide() {
        this.dialog.hide();
    }
    select(args) {
        if (args.item.text === 'Update...') {
            this.dialog.show();
        }
    }
    render() {
        return (<div>
       <DialogComponent ref={dialog => this.dialog = dialog} width='250px' id='dialog' content='Are you sure want to update?' header='Software Update' buttons={this.alertDlgButtons} visible={false}/>
       <SplitButtonComponent items={this.items} select={this.select}>Help</SplitButtonComponent>
      </div>);
    }
}
ReactDom.render(<App />, document.getElementById('button'));