- Implementation
- Dialog Props
- Dialog.Header Props
- Dialog.Content Props
Common Examples
Opening dialogs
Dialogs should be shown and hidden using theopen prop, rather than conditionally rendering the entire component.This allows us to follow the HTML standard for dialog elements, which is what we render under-the-hood. This also prevents some other issues, such as skipping the exit animation or missing toast messages.Do
Don’t
Rendering content on open
By default, dialog content is rendered on page load, but hidden until the dialog is opened. In some cases, such as making heavy API calls or with content that may require large re-renders based on other user actions, it could be advantageous to wait to render the dialog content.To render dialog content only when it is opened, conditionally render thechildren based on the state used in the Dialog.open prop.Sticky Content
Use thesticky prop on Dialog.Content to keep important UI elements (like search fields or filters) visible while other content scrolls. This is useful for dialogs with long, scrollable content.Closing dialogs
Clicking aDialog.CancelButton or the close button inside of Dialog.Header will trigger the Dialog.onClose to run, where you can add a callback to control the open/close state of the dialog.Closing callbacks
In addition toonClose–which indicates a user has chosen to close a dialog–the component also offers two animation callbacks onCloseAnimationStart and onCloseAnimationComplete.You may use these callbacks to perform additional actions related to the presentation of the Dialog. For example, if you have a dialog containing a form, you may wish to reset the form state after the close animation has played so that the user doesn’t see an empty form briefly when closing the dialog.Dialogs and Toasts
Due to the way the HTMLdialog element renders in the browser’s top layer, the Dialog component includes an internal Toaster for rendering toast messages. This should be unnoticeable to implementors and users, but there may be edge cases the result in toasts not rendering as expected.Please reach out to us in the #ask-designsystem channel on Slack if any edge cases related to dialogs and toasts are found!Anti-Patterns
Conditional rendering
The openness should be controlled by theopen prop and not by conditional rendering — this is an anti-pattern for Dialog.Resetting content
HTML Dialog show/hide content but it doesn’t remove from the DOM which means the reset doesn’t happen automatically. To do the reset, usekey on <Dialog.Content> . Since <Dialog.Content> is always present in DOM, you can add conditional to, or in, the <Dialog.Content> as well.