Dialog
Example Code
<!-- For this example, we've defined a global variable '$dialog' pointing to the dialog element. -->
<button class="button" onclick="$dialog.showModal()">
Open Dialog
</button>
<dialog id="dialog1">
<header class="dialog-header">
<h1>Leave Without Saving?</h1>
<button
class="close button"
onclick="$dialog.close()"
></button>
</header>
<div class="dialog-body">
<p>
You have unsaved edits. What would you like to do?
</p>
</div>
<div class="dialog-footer">
<button
class="primary red button"
onclick="$dialog.close()"
>
Discard Changes
</button>
<button class="button" onclick="$dialog.close()">
Keep Editing
</button>
</div>
</dialog>
Result
Options
Size
A dialog can optionally have a size, which controls the maximum width of the dialog. If the contents of the dialog are small, then the dialog might not take up the whole width it is allowed.
To set the size of a dialog, add one of the following classes:
small
medium
large
If you don't add any of the above, the dialog will be as wide as necessary to fit the content without extending past the edge of the screen.
Drawer
A dialog can optionally be displayed as a drawer. In this case, it is docked to one side of the screen and takes the whole height (if docked to the side) or width (if docked to the top or bottom).
To turn a dialog into a drawer, add the class drawer
, along
with the side of the screen the drawer should slide out from. Valid
sides are:
left
right
top
bottom
Drawers also support the same size classes as normal dialogs.