Dialog

Dialogs, sometimes called “modals”, appear above the page and require the user’s immediate attention.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Close Open Dialog

Use the —width custom property to set the dialog’s width.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Close Open Dialog

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.

Scroll down and give it a try! 👇

Close
Open Dialog

The header shows a functional close button by default. You can use the header-actions slot to add additional icon buttons if needed.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Close Open Dialog

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. Close Open 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.

Close Open Dialog
import '@ods/components/web.dialog';

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.

Slots

NameDescription
(default)The dialog's main content.
labelThe dialog's label. Alternatively, you can use the `label` attribute.
header-actionsOptional actions to add to the header. Works best with `<ods-icon-button>`.
footerThe 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/AttributeReflectsTypeDefault
modal
new Modal(this)
open
booleanfalse
label
string''
noHeader
no-header
booleanfalse

Events

React EventDescriptionEvent Detail
ods-dialog-showEmitted when the dialog opens.--
ods-dialog-after-showEmitted after the dialog opens and all animations are complete.--
ods-dialog-hideEmitted when the dialog closes.--
ods-dialog-after-hideEmitted after the dialog closes and all animations are complete.--
ods-dialog-initial-focusEmitted 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-closeEmitted 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

NameDescriptionArguments
show()Shows the dialog.--
hide()Hides the dialog--

Parts

NameDescription
baseThe component's base wrapper.
overlayThe overlay that covers the screen behind the dialog.
panelThe dialog's panel (where the dialog and its content are rendered).
headerThe dialog's header. This element wraps the title and header actions.
header-actionsOptional actions to add to the header. Works best with `<ods-icon-button>`.
titleThe dialog's title.
close-buttonThe close button, an `<ods-icon-button>`.
close-button__baseThe close button's exported `base` part.
bodyThe dialog's body.
footerThe dialog's footer.

Dependencies

This component automatically imports the following dependencies.

  • ods-icon
  • ods-icon-button

Search