Skip to content

Dialog

A dialog is a modal window that appears in front of app content to provide critical information or ask for a decision. Dialogs disable all app functionality when they appear, and remain on screen until confirmed, dismissed, or a required action has been taken.

<div data-role="dialog" id="myDialog"></div>
// Create a dialog dynamically
Metro.dialog.create({
title: "Dialog Title",
content: "This is the dialog content.",
closeButton: true,
defaultActions: true
});
// Use an existing dialog element
const dialog = Metro.getPlugin('#myDialog', 'dialog');
dialog.setTitle('My Dialog Title');
dialog.setContent('This is the dialog content.');
dialog.open();
const customButtons = [
{
text: "Yes, proceed",
cls: "js-dialog-close success",
onclick: function(){
console.log("User clicked Yes");
}
},
{
text: "No, cancel",
cls: "js-dialog-close",
onclick: function(){
console.log("User clicked No");
}
}
];
Metro.dialog.create({
title: "Confirmation",
content: "Do you want to continue?",
closeButton: true,
defaultActions: false,
customButtons: customButtons
});
ParameterTypeDefaultDescription
dialogDeferrednumber0Delay before dialog initialization
closeButtonbooleanfalseShow close button in the top-right corner
leaveOverlayOnClosebooleanfalseKeep overlay when dialog is closed
toTopbooleanfalsePosition dialog at the top of the screen
toBottombooleanfalsePosition dialog at the bottom of the screen
titlestring""Dialog title
contentstring""Dialog content
customButtonsarraynullArray of custom button objects
actionsAlignstring”right”Alignment of action buttons (“left”, “center”, “right”)
defaultActionsbooleantrueShow default action buttons
defaultActionButtonsstring”ok,cancel,help”Comma-separated list of default buttons to show
overlaybooleantrueShow overlay behind dialog
overlayColorstring”#000000”Color of the overlay
overlayAlphanumber0.5Opacity of the overlay
overlayClickClosebooleanfalseClose dialog when clicking on overlay
widthstring”auto”Width of the dialog
heightstring”auto”Height of the dialog
closeActionbooleantrueEnable close action for elements with class js-dialog-close
clsDialogstring""Additional CSS class for dialog element
clsTitlestring""Additional CSS class for title element
clsContentstring""Additional CSS class for content element
clsActionstring""Additional CSS class for actions element
clsDefaultActionstring""Additional CSS class for default action buttons
clsOverlaystring""Additional CSS class for overlay element
autoHidenumber0Auto hide dialog after specified milliseconds (0 = disabled)
removeOnClosebooleanfalseRemove dialog element from DOM when closed
showbooleanfalseShow dialog immediately after initialization
  • setTitle(title) - Set the dialog title.
  • setContent(content) - Set the dialog content.
  • open() - Open the dialog.
  • close() - Close the dialog.
  • toggle() - Toggle the dialog between open and closed states.
  • isOpen() - Check if the dialog is open.
  • hide(callback) - Hide the dialog with optional callback.
  • show(callback) - Show the dialog with optional callback.
  • setPosition() - Set the position of the dialog.
  • Metro.dialog.isDialog(el) - Check if element is a dialog.
  • Metro.dialog.open(el, content, title) - Open a dialog with optional content and title.
  • Metro.dialog.close(el) - Close a dialog.
  • Metro.dialog.toggle(el) - Toggle a dialog.
  • Metro.dialog.isOpen(el) - Check if a dialog is open.
  • Metro.dialog.remove(el) - Remove a dialog from the DOM.
  • Metro.dialog.create(options) - Create a new dialog with options.
const dialog = Metro.getPlugin('#myDialog', 'dialog');
dialog.setTitle('Updated Title');
dialog.setContent('Updated content text');
dialog.open();
// Later, close the dialog
dialog.close();
EventDescription
onOkTriggered when the OK button is clicked
onCancelTriggered when the Cancel button is clicked
onHelpTriggered when the Help button is clicked
onShowTriggered when the dialog is shown
onHideTriggered when the dialog is hidden
onOpenTriggered when the dialog is opened
onCloseTriggered when the dialog is closed
onDialogCreateTriggered when the dialog is created
VariableDefault (Light)Dark ModeDescription
--dialog-border-radius6px6pxBorder radius of the dialog
--dialog-background#f7f8fa#2b2d30Background color of the dialog
--dialog-color#191919#dbdfe7Text color of the dialog
--dialog-border-color#aaaaaa#414245Border color of the dialog
--dialog-closer-backgroundinheritinheritBackground color of the close button
--dialog-closer-colorinheritinheritColor of the close button
--dialog-closer-background-hovervar(—color-alert)var(—color-alert)Background color of the close button on hover
--dialog-closer-color-hovervar(—color-light)var(—color-light)Color of the close button on hover
#myDialog {
--dialog-background: #e0f0ff;
--dialog-color: #003366;
--dialog-border-color: #0066cc;
--dialog-border-radius: 10px;
}
  • .dialog - Main dialog container
  • .dialog-title - Dialog title container
  • .dialog-content - Dialog content container
  • .dialog-actions - Dialog actions container
  • .closer - Close button
  • .text-left - Align action buttons to the left
  • .text-center - Align action buttons to the center
  • .text-right - Align action buttons to the right
  • .js-dialog-close - Elements with this class will close the dialog when clicked

The dialog supports all Metro UI accent colors:

  • .primary, .secondary, .success, .alert, .warning, .yellow, .info, .light, etc.
  • The dialog is positioned in the center of the screen by default, but can be positioned at the top or bottom using the toTop and toBottom options.
  • The dialog can be closed by clicking on the close button, clicking on elements with the .js-dialog-close class, or by clicking on the overlay if overlayClickClose is set to true.
  • Custom buttons can be added to the dialog using the customButtons option, which takes an array of button objects with text, cls, and onclick properties.
  • The dialog can be automatically hidden after a specified time using the autoHide option.
  • Use dialogs sparingly, as they interrupt the user’s workflow.
  • Keep dialog content concise and focused on a single task or decision.
  • Provide clear and descriptive button labels that indicate the action that will be taken.
  • Use appropriate color classes to indicate the type of dialog (e.g., .alert for warnings, .success for confirmations).
  • Consider using the removeOnClose option for dynamically created dialogs to prevent memory leaks.
  • For complex forms or large content, consider using a different component like a sidebar or panel instead of a dialog.