ModalDialog
ModalDialog creates overlay dialogs that appear on top of the main interface, ideal for forms, confirmations, detailed views, or any content that requires focused user attention. Dialogs are programmatically opened using the open() method and can receive parameters for dynamic content.
Key features:
- Overlay presentation: Appears above existing content with backdrop dimming
- Programmatic control: Open and close via exposed methods like
open()andclose() - Parameter passing: Accept data when opened for dynamic dialog content
- Focus management: Automatically handles focus trapping and accessibility
- Form integration: When containing Form components, automatically closes on form submission or cancellation (unless overridden)
Using the Component
When using the examples in this article, pop them out to the full screen to check how they work.
Opening and closing the modal dialog can be done in two ways depending on circumstances.
With Imperative API
Event-driven display of the ModalDialog dialog is also possible using imperative API.
This method is a good way to toggle the display of the ModalDialog if no deep linking is necessary.
It also lends to itself that these events can be triggered programmatically from codebehind.
Note the id property of the ModalDialog in the example below and how it is used to call the open and close
operations of the component in the onClick event handlers.
<App>
<ModalDialog id="dialog" title="Example Dialog">
<Button label="Close Dialog" onClick="dialog.close()" />
</ModalDialog>
<Button label="Open Dialog" onClick="dialog.open()" />
</App><App>
<ModalDialog id="dialog" title="Example Dialog">
<Button label="Close Dialog" onClick="dialog.close()" />
</ModalDialog>
<Button label="Open Dialog" onClick="dialog.open()" />
</App>The imperative approach is perhaps the most intuitive way to display and hide modal dialogs.
With when
The when property accepts a primitive boolean or a binding expression resolving to a boolean value to toggle the display of a component.
Using the when property in a ModalDialog dialog component is commonly used with deep linking:
showing the modal in conjunction with an updated URL so that the opened state of the modal dialog is referable.
<App>
<variable name="isDialogShown" value="{false}"/>
<Button label="Open Dialog" onClick="isDialogShown = true" />
<ModalDialog
when="{isDialogShown}"
title="Example Dialog"
onClose="isDialogShown = false" />
</App>Click on the button in the demo below to open the modal dialog. Click anywhere outside the opened dialog or the close button to close it.
<App>
<variable name="isDialogShown" value="{false}"/>
<Button label="Open Dialog" onClick="isDialogShown = true" />
<ModalDialog
when="{isDialogShown}"
title="Example Dialog"
onClose="isDialogShown = false" />
</App>Click on the button in the demo below to open the modal dialog. Click anywhere outside the opened dialog or the close button to close it.
Setting the when property is the most straightforward way for deep-linked modals. If you use deep links with query parameters to show a particular dialog, you can set the when property to show or hide the dialog according to parameter values.
The ModalDialog as a Container
The ModalDialog component is also a container such as the Card, that it also accepts child components.
<App>
<Button label="Open Dialog" onClick="dialog.open()" />
<ModalDialog id="dialog" title="Example Dialog">
<Form data="{{ firstName: 'Billy', lastName: 'Bob' }}">
<FormItem bindTo="firstName" required="true" />
<FormItem bindTo="lastName" required="true" />
</Form>
</ModalDialog>
</App><App>
<Button label="Open Dialog" onClick="dialog.open()" />
<ModalDialog id="dialog" title="Example Dialog">
<Form data="{{ firstName: 'Billy', lastName: 'Bob' }}">
<FormItem bindTo="firstName" required="true" />
<FormItem bindTo="lastName" required="true" />
</Form>
</ModalDialog>
</App>When a form is nested into a modal dialog, closing the form (canceling it or completing its submit action) automatically closes the dialog.
Context variables available during execution:
$param: First parameter passed to theopen()method$params: Array of all parameters passed toopen()method (access with$params[0],$params[1], etc.)
Behaviors
This component supports the following behaviors:
| Behavior | Properties |
|---|---|
| Animation | animation, animationOptions |
| Bookmark | bookmark, bookmarkLevel, bookmarkTitle, bookmarkOmitFromToc |
| Component Label | label, labelPosition, labelWidth, labelBreak, required, enabled, shrinkToLabel, style, readOnly |
| Publish/Subscribe | subscribeToTopic |
| Tooltip | tooltip, tooltipMarkdown, tooltipOptions |
| Styling Variant | variant |
Properties
closeButtonVisible
default: true
Shows (true) or hides (false) the visibility of the close button on the dialog.
<App>
<Button label="Open Dialog" onClick="dialog.open()" />
<ModalDialog id="dialog" closeButtonVisible="false" title="Example Dialog" />
</App>Click outside the dialog to close it.
<App>
<Button label="Open Dialog" onClick="dialog.open()" />
<ModalDialog id="dialog" closeButtonVisible="false" title="Example Dialog" />
</App>Click outside the dialog to close it.
fullScreen
default: false
Toggles whether the dialog encompasses the whole UI (true) or not and has a minimum width and height (false).
<App>
<Button label="Open Dialog" onClick="dialog.open()" />
<ModalDialog id="dialog" fullScreen="true" title="Example Dialog" />
</App>Click the button to display a full-screen dialog. The icon at the top-right corner of the dialog allows you to close it.
<App>
<Button label="Open Dialog" onClick="dialog.open()" />
<ModalDialog id="dialog" fullScreen="true" title="Example Dialog" />
</App>Click the button to display a full-screen dialog. The icon at the top-right corner of the dialog allows you to close it.
title
Provides a prestyled heading to display the intent of the dialog.
<App>
<Button label="Open Dialog" onClick="dialog.open()" />
<ModalDialog id="dialog" title="Example Title" />
</App><App>
<Button label="Open Dialog" onClick="dialog.open()" />
<ModalDialog id="dialog" title="Example Title" />
</App>titleTemplate
A custom template to render the dialog title.
Events
close
This event is fired when the close button is pressed or the user clicks outside the ModalDialog.
Signature: close(): void
In this example, the close event counts how many times you closed the dialog:
<App>
<Button label="Open Dialog" onClick="myDialog.open()" />
<ModalDialog
id="myDialog"
title="Example Dialog"
var.counter="{0}"
onClose="counter++">
<Text value="Dialog closed {counter} number of times." />
</ModalDialog>
</App>Open and close the dialog several times to test that it changes the counter.
<App>
<Button label="Open Dialog" onClick="myDialog.open()" />
<ModalDialog
id="myDialog"
title="Example Dialog"
var.counter="{0}"
onClose="counter++">
<Text value="Dialog closed {counter} number of times." />
</ModalDialog>
</App>Open and close the dialog several times to test that it changes the counter.
open
This event is fired when the ModalDialog is opened either via a when or an imperative API call (open()).
Signature: open(...params: any[]): void
params: Parameters passed to the open() method, accessible via $param and $params context variables.
In this example, the open event counts how many times you opened the dialog:
<App>
<Button label="Open Dialog" onClick="myDialog.open()" />
<ModalDialog
id="myDialog"
title="Example Dialog"
var.counter="{0}"
onOpen="counter++">
<Text value="Dialog opened {counter} number of times." />
</ModalDialog>
</App>Open and close the dialog several times to test that it changes the counter.
<App>
<Button label="Open Dialog" onClick="myDialog.open()" />
<ModalDialog
id="myDialog"
title="Example Dialog"
var.counter="{0}"
onOpen="counter++">
<Text value="Dialog opened {counter} number of times." />
</ModalDialog>
</App>Open and close the dialog several times to test that it changes the counter.
Exposed Methods
close
This method is used to close the ModalDialog. Invoke it using modalId.close() where modalId refers to a ModalDialog component.
Signature: close(): void
See the `With Imperative API` subsection for an example.
open
This method imperatively opens the modal dialog. You can pass an arbitrary number of parameters to the method. In the ModalDialog instance, you can access those with the $param and $params context values.
Signature: open(...params: any[]): void
params: An arbitrary number of parameters that can be used to pass data to the dialog.
See the `With Imperative API` subsection for an example.
Parts
The component has some parts that can be styled through layout properties and theme variables separately:
content: The main content area of the modal dialog.title: The title area of the modal dialog.
Styling
Theme Variables
| Variable | Default Value (Light) | Default Value (Dark) |
|---|---|---|
| backgroundColor-ModalDialog | $backgroundColor-primary | $backgroundColor-primary |
| backgroundColor-ModalDialog | $backgroundColor-primary | $backgroundColor-primary |
| backgroundColor-overlay-ModalDialog | $backgroundColor-overlay | $backgroundColor-overlay |
| backgroundColor-overlay-ModalDialog | $backgroundColor-overlay | $backgroundColor-overlay |
| backgroundColor-title-ModalDialog | none | none |
| borderRadius-ModalDialog | $borderRadius | $borderRadius |
| borderRadius-ModalDialog | $borderRadius | $borderRadius |
| direction-title-ModalDialog | none | none |
| fontFamily-ModalDialog | $fontFamily | $fontFamily |
| fontFamily-ModalDialog | $fontFamily | $fontFamily |
| fontFamily-title-ModalDialog | none | none |
| fontSize-title-ModalDialog | $fontSize-2xl | $fontSize-2xl |
| fontStretch-title-ModalDialog | none | none |
| fontStyle-title-ModalDialog | none | none |
| fontVariant-title-ModalDialog | none | none |
| fontWeight-title-ModalDialog | none | none |
| letterSpacing-title-ModalDialog | none | none |
| lineBreak-title-ModalDialog | none | none |
| lineHeight-title-ModalDialog | none | none |
| marginBottom-title-ModalDialog | 0 | 0 |
| marginBottom-title-ModalDialog | 0 | 0 |
| maxWidth-ModalDialog | 450px | 450px |
| maxWidth-ModalDialog | 450px | 450px |
| minWidth-ModalDialog | none | none |
| padding-ModalDialog | $space-7 | $space-7 |
| padding-overlay-ModalDialog | none | none |
| paddingBottom-ModalDialog | $paddingVertical-ModalDialog | $paddingVertical-ModalDialog |
| paddingBottom-overlay-ModalDialog | none | none |
| paddingHorizontal-ModalDialog | none | none |
| paddingHorizontal-overlay-ModalDialog | none | none |
| paddingLeft-ModalDialog | $paddingHorizontal-ModalDialog | $paddingHorizontal-ModalDialog |
| paddingLeft-overlay-ModalDialog | none | none |
| paddingRight-ModalDialog | $paddingHorizontal-ModalDialog | $paddingHorizontal-ModalDialog |
| paddingRight-overlay-ModalDialog | none | none |
| paddingTop-ModalDialog | $paddingVertical-ModalDialog | $paddingVertical-ModalDialog |
| paddingTop-overlay-ModalDialog | none | none |
| paddingVertical-ModalDialog | none | none |
| paddingVertical-overlay-ModalDialog | none | none |
| textAlign-title-ModalDialog | none | none |
| textAlignLast-title-ModalDialog | none | none |
| textColor-ModalDialog | $textColor-primary | $textColor-primary |
| textColor-ModalDialog | $textColor-primary | $textColor-primary |
| textColor-title-ModalDialog | none | none |
| textDecorationColor-title-ModalDialog | none | none |
| textDecorationLine-title-ModalDialog | none | none |
| textDecorationStyle-title-ModalDialog | none | none |
| textDecorationThickness-title-ModalDialog | none | none |
| textIndent-title-ModalDialog | none | none |
| textShadow-title-ModalDialog | none | none |
| textTransform-title-ModalDialog | none | none |
| textUnderlineOffset-title-ModalDialog | none | none |
| wordBreak-title-ModalDialog | none | none |
| wordSpacing-title-ModalDialog | none | none |
| wordWrap-title-ModalDialog | none | none |
| writingMode-title-ModalDialog | none | none |