By design, a dialog’s height will never exceed that of the viewport. As such, dialogs will not scroll with the page ensuring the header and footer are always accessible to the user.
By default, dialogs will close when the user clicks the close button, clicks the overlay, or presses the Escape key. In most cases, the default behavior is the best behavior in terms of UX. However, there are situations where this may be undesirable, such as when data loss will occur.
To keep the dialog open in such cases, you can cancel the ods-request-close event. When canceled, the dialog will remain open and pulse briefly to draw the user’s attention to it.
You can use event.detail.source to determine what triggered the request to close. This example prevents the dialog from closing when the overlay is clicked, but allows the close button or Escape to dismiss it.
This dialog will not close when you click on the overlay.
CloseOpen Dialog
By default, the dialog’s panel will gain focus when opened. This allows a subsequent tab press to focus on the first tabbable element in the dialog. If you want a different element to have focus, add the autofocus attribute to it as shown below.
CloseOpen Dialog
<ods-dialoglabel="Dialog"class="dialog-focus">
<ods-inputautofocusplaceholder="I will have focus when the dialog is opened"></ods-input>
Note: You only need to import a web component once in your code, as it registers itself globally when defined, allowing you to use it anywhere within your application without needing to re-import it each time you want to use the component.
This component is still in development and cannot be imported at this time.
Slots
Name
Description
(default)
The dialog's main content.
label
The dialog's label. Alternatively, you can use the `label` attribute.
header-actions
Optional actions to add to the header. Works best with `<ods-icon-button>`.
footer
The dialog's footer, usually one or more buttons representing various options.
Properties
Please note, both DOM properties and HTML attributes are shown in the table below. Unless otherwise specified, the property and attribute names are identical.
Property/Attribute
Reflects
Type
Default
modal
new Modal(this)
open
boolean
false
label
string
''
noHeader
no-header
boolean
false
Events
React Event
Description
Event Detail
ods-dialog-show
Emitted when the dialog opens.
--
ods-dialog-after-show
Emitted after the dialog opens and all animations are complete.
--
ods-dialog-hide
Emitted when the dialog closes.
--
ods-dialog-after-hide
Emitted after the dialog closes and all animations are complete.
--
ods-dialog-initial-focus
Emitted when the dialog opens and is ready to receive focus. Calling `event.preventDefault()` will prevent focusing and allow you to set it on a different element, such as an input.
--
ods-dialog-request-close
Emitted when the user attempts to close the dialog by clicking the close button, clicking the overlay, or pressing escape. Calling `event.preventDefault()` will keep the dialog open. Avoid using this unless closing the dialog will result in destructive behavior such as data loss.
--
Methods
Name
Description
Arguments
show()
Shows the dialog.
--
hide()
Hides the dialog
--
Parts
Name
Description
base
The component's base wrapper.
overlay
The overlay that covers the screen behind the dialog.
panel
The dialog's panel (where the dialog and its content are rendered).
header
The dialog's header. This element wraps the title and header actions.
header-actions
Optional actions to add to the header. Works best with `<ods-icon-button>`.
title
The dialog's title.
close-button
The close button, an `<ods-icon-button>`.
close-button__base
The close button's exported `base` part.
body
The dialog's body.
footer
The dialog's footer.
Dependencies
This component automatically imports the following dependencies.