Dialogs

Any page can be presented as a modal dialog that appears to be suspended above the page by adding an attribute to the link that leads to the dialog page.

Note: The dialog widget is deprecated in 1.4 and will be removed in 1.5. The page widget now has the dialog option which, when set to true will apply dialog styling to a page.

Basics

Any page can be presented as a modal dialog by adding the data-dialog="true" attribute to the page. When the "dialog" attribute is applied, the framework adds styles to add rounded corners, margins around the page and a dark background to make the "dialog" appear to be suspended above the page. By default the framework will also add a close button if the dialog has a header.

<a href="dialog.html" class="ui-shadow ui-button ui-corner-all ui-button-inline" data-transition="pop">Open dialog</a>

Open dialog

Transitions

By default, the dialog will open with the same transition as a regular page. Like all pages, you can specify any page transition you want on the dialog by adding the data-transition attribute to the link. To make it feel more dialog-like, we recommend specifying a transition of "pop", "slidedown" or "flip".

<a href="dialog.html" role="button" class="ui-shadow ui-button ui-corner-all ui-button-inline" data-transition="slidedown">data-transition="slidedown"</a>
data-transition="slidedown" data-transition="flip"

Closing dialogs

When any link is clicked within a dialog, the framework will automatically close the dialog and transition to the requested page, just as if the dialog were a normal page. Nevertheless, dialogs can also be chained, as explained below under "Chaining Dialogs". Similarly, a link that opens a popup will also leave the dialog in place.

If the dialog has a header the framework will add a close button at the left side of the header. You can change the position by adding data-close-button="right" to the dialog container. If you don't want a close button in the header or if you want to add a custom close button, you can use data-close-button="none".

Right close button No close button

To create a "cancel" button in a dialog, just link to the page that triggered the dialog to open and add the data-rel="back" attribute to your link. This pattern of linking to the previous page is also usable in non-JS devices as well.

For JavaScript-generated links, you can simply set the href attribute to "#" and use the data-rel="back" attribute.

Setting the close button text

Just like the page plugin, you can set a dialog's close button text through an option or data attribute. This option is used to customize the text of the close button which is helpful for translating this into different languages. This is displayed as an icon-only button by default so the text isn't visible on-screen, but is read by screen readers so this is an important accessibility feature. The option can be configured for all dialogs by binding to the mobileinit event and setting the $.mobile.dialog.prototype.options.closeBtnText property to a string of your choosing, or you can place the data attribute data-close-button-text to configure the text from your markup.

Chaining Dialogs

Please note: If a dialog opens another dialog (chaining), closing the last one with a link of type data-rel="back" will always navigate to the previous dialog until the root-page of type data-role="page" is reached. This guarantees a consistent navigation between dialogs.

Styling & theming

Dialogs can be styled with different theme swatches, just like any page by adding data-theme attributes to the header, content, or footer containers. Here is an example of a different dialog design:

An alternate color scheme

By default dialogs have rounded corners. The option corners can be set to false by adding data-corners="false" to the dialog container:

No rounded corners

Dialogs appear to be floating above an overlay layer. This overlay adopts the swatch "a" content color by default, but the data-overlay-theme attribute can be added to the page wrapper to set the overlay to any swatch letter. Here is an example of a dialog with the overlay set to swatch "e":

Custom overlay swatch

Dialogs can also be used more like a control sheet to offer multiple buttons if you simply remove the top margin from the dialog's inner container element. For example, if your dialog page had a class of my-dialog, you could add this CSS to pin that dialog to the top: .ui-page-dialog.my-dialog .ui-page-dialog-contain { margin-top: 0 }, or you could just apply that style to all dialogs with .ui-page-dialog .ui-page-dialog-contain { margin-top: 0 }.

Share photos...

Dialog width and margins

For the sake of readability, dialogs have a default width of 92.5% and a max-width of 500 pixels. There is also a 10% top margin to give dialogs larger top margin on larger screens, but collapse to a small margin on smartphones. The dialog's inner container is shifted towards the top with 15px to hide the corner styling if a dialog is used as a control sheet (see above). To override these styles, add the following CSS override rule to your stylesheet and tweak as needed:


.ui-page-dialog-contain {
	width: 92.5%;
	max-width: 500px;
	margin: 10% auto 15px auto;
	padding: 0;
	position: relative;
	top: -15px;
}