The Ignite UI for Web Components Dialog component is used to display some information or prompt the user for an action or confirmation. It is shown in a modal window, which means that the user is not allowed to interact with the main app until a certain action is performed that closes the dialog.
Ignite UI for Web Components Dialog Example
This sample demonstrates how to create a Dialog component in Web Components.
<html><head><title>Dialog Overview</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png"><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-buttononclick="dialog.show()"variant="contained">Show Dialog</igc-button><igc-dialogid="dialog"title="Confirmation"><p>Are you sure you want to delete the Annual_Report_2016.pdf and Annual_Report_2017.pdf files?</p><igc-buttonslot="footer"onclick="dialog.hide()"variant="flat">Cancel</igc-button><igc-buttonslot="footer"onclick="dialog.hide()"variant="flat">OK</igc-button></igc-dialog></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %>
<scriptsrc="src/index.ts"></script>
<% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Like this sample? Get access to our complete Ignite UI for Web Components toolkit and start building your own apps in minutes. Download it for free.
Usage
First, you need to install the Ignite UI for Web Components by running the following command:
For a complete introduction to the Ignite UI for Web Components, read the Getting Started topic.
The simplest way to display the dialog component is to use its show method and call it on a button click.
<igc-buttononclick="dialog.show()"variant="contained">Show Dialog</igc-button><igc-dialogid="dialog"title="Confirmation"><p>Are you sure you want to delete the Annual_Report_2016.pdf and Annual_Report_2017.pdf files?</p><igc-buttonslot="footer"onclick="dialog.close()"variant="flat">Cancel</igc-button><igc-buttonslot="footer"onclick="dialog.close()"variant="flat">OK</igc-button></igc-dialog>html
The Dialog component provides an open property, which gives you the ability to configure its state as per your application scenario.
Use the title property to set the title of the dialog. However, if any content is provided in the title slot, it will take precedence over the property.
Action buttons or additional information can be placed in the bottom part of the dialog via the footer slot. If no content is added there, a default OK button will be shown that closes the Dialog when clicked. In case you do not want this button to be shown you can set the hideDefaultAction property to true. The default value is false.
Closing
By default, the Dialog is closed automatically when the user presses ESC. You could prevent this behavior using the keepOpenOnEscape property. The default value is false. If there is an open dropdown (or any other element that should handle ESC internally) in the dialog, pressing ESC once will close the dropdown and pressing it again will close the dialog.
Use the closeOnOutsideClick property to configure if the dialog should be closed when clicking outside of it. The default value is false.
<html><head><title>Dialog Closing Variations</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png"><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-switchid="keepOpenOnEscSwitch"label-position="before">keepOpenOnEscape</igc-switch><igc-switchid="closeOnOutsideClickSwitch"label-position="before">closeOnOutsideClick</igc-switch><igc-buttononclick="dialog.show()"variant="contained">Show Dialog</igc-button><igc-dialogid="dialog"title="Confirmation"><p>Are you sure you want to delete the Annual_Report_2016.pdf and Annual_Report_2017.pdf files?</p><igc-buttonslot="footer"onclick="dialog.hide()"variant="flat">Cancel</igc-button><igc-buttonslot="footer"onclick="dialog.hide()"variant="flat">OK</igc-button></igc-dialog></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %>
<scriptsrc="src/index.ts"></script>
<% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Form
Form elements can close a Dialog if they have the attribute method="dialog". Submitting the form will trigger the closing of the dialog.
<html><head><title>Dialog Form</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png"><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-buttononclick="dialog.show()"variant="contained">Show Dialog</igc-button><igc-dialogid="dialog"title="Login"><formid="form"method="dialog"><igc-inputlabel="Username"><igc-iconname="username"slot="prefix"></igc-icon></igc-input><br><igc-inputtype="password"label="Password"><igc-iconname="password"slot="prefix"></igc-icon></igc-input><br><divstyle="display: flex; justify-content: flex-end;"><igc-buttontype="reset"variant="flat">Reset</igc-button><igc-buttontype="submit"variant="flat">Submit</igc-button></div></form><divslot="footer"><igc-button>Create an account</igc-button></div></igc-dialog></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %>
<scriptsrc="src/index.ts"></script>
<% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Styling
The IgcDialogComponent component exposes several CSS parts to give you full control over its style:
<html><head><title>Dialog Styling</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png"><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css"type="text/css" /></head><body><divid="root"><divclass="container sample center"><igc-buttononclick="dialog.show()"variant="contained">Show Dialog</igc-button><igc-dialogid="dialog"title="Confirmation"><h1slot="title">Styled Title</h1><p>Are you sure you want to delete the Annual_Report_2016.pdf and Annual_Report_2017.pdf files?</p><igc-buttonslot="footer"onclick="dialog.toggle()"variant="flat">Cancel</igc-button><igc-buttonslot="footer"onclick="dialog.toggle()"variant="flat">OK</igc-button></igc-dialog></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %>
<scriptsrc="src/index.ts"></script>
<% } %>
</body></html>html