Modal is a dialog box or popup window that is displayed on top of the current page.
Modal has many events according to its state. You can listen to these events to trigger some actions.
Most important event is the dds-close event, which is triggered when the modal is closed.
The events detail properry contains the source of the event. This can be ok-button, cancel-button, close-button, overlay, or esc.
There is a know issue in Safari when using React. When the modal is opened, safari does not recognize the content in the modal content slot, and the content is not resized to the new height. This is a known Safari bug. I this case you can set the modal to a fixed size, or use the the followin css:
#modal::part(panel) {
height: auto;
}
import { DapDSModal } from 'dap-design-system'
import { DapDSModalReact } from 'dap-design-system/react'
For optimal bundle sizes, use the tree-shakeable import syntax:
import { DapDSModal } from 'dap-design-system/components'
| Property | Type | Default | Description |
|---|---|---|---|
bottomFooter | boolean | true | Pushes the footer to bottom. |
open | boolean | The open state of the modal. | |
fullScreen | boolean | The full screen version of the modal. | |
size | 'sm', 'lg' | The size of the modal. Default is 'sm'. | |
wideFooter | boolean | Wide layout mode for footer. | |
closeOnEsc | boolean | Whether the modal should close on pressing the escape key. Default is true. | |
closeOnOverlayClick | boolean | Whether the modal should close on clicking the overlay. Default is true. | |
closeButton | string | Whether the modal should have a close button. Default is true. | |
title | string | The title of the modal. | |
description | string | The description of the modal. | |
okButtonLabel | string | The label of the OK button. | |
cancelButtonLabel | string | The label of the Cancel button. | |
okButtonDisabled | boolean | Whether the OK button should be disabled. | |
cancelButtonDisabled | boolean | Whether the Cancel button should be disabled. | |
cancelButtonDanger | boolean | Whether the Cancel button should be a danger button. | |
okButtonDanger | boolean | Whether the OK button should be a danger button. | |
hideOkButton | boolean | Whether the OK button should be hidden. | |
hideCancelButton | boolean | Whether the Cancel button should be hidden. | |
footer | string | Whether the modal should have a footer. Default is true. | |
header | string | Whether the modal should have a header. Default is true. | |
useNativeFocus | boolean | Whether the modal should use native focus. Default is false. |
| Name | Description |
|---|---|
(default) | The content of the modal. |
title | The title of the modal. |
description | The description of the modal. |
footer | The footer of the modal. |
| Event Name | Description | Type |
|---|---|---|
dds-before-open | Fires before the modal opens. | {void } |
dds-opened | Fires after the modal opens. | {void } |
dds-before-close | Fires before the modal closes. | {void } |
dds-closed | Fires after the modal closed. | {void } |
dds-close | Fires when the modal is closes. You can prevent the modal from closing by calling `event.preventDefault()`. | {void } |
dds-ok | Fires when the OK button is clicked. You can prevent the modal from closing by calling `event.preventDefault()`. | {void } |
dds-cancel | Fires when the Cancel button is clicked. You can prevent the modal from closing by calling `event.preventDefault()`. | {void } |
| Part Name | Description |
|---|---|
base | The main modal container. |
panel | The panel of the modal. |
header | The header of the modal. |
title | The title of the modal. |
description | The description of the modal. |
footer | The footer of the modal. |
content | The body of the modal. |
closebutton | The close button of the modal. |
You can style CSS parts using the ::part() pseudo-element selector:
/* Target a specific part */
.my-custom-dap-ds-modal::part(base) {
/* Your custom styles */
}
/* Target multiple parts */
.my-custom-dap-ds-modal::part(base),
.my-custom-dap-ds-modal::part(panel) {
/* Shared styles */
}
Example usage:
<dap-ds-modal class="my-custom-dap-ds-modal">
Modal
</dap-ds-modal>
.my-custom-dap-ds-modal::part(base) {
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.
| Property Name | Description |
|---|---|
--dds-modal-max-block-size | Maximum height of the modal. Default: 80vh. |
--dds-modal-max-inline-size | Maximum width of the modal. Default: 600px. |
--dds-modal-padding-sm | Padding inside the modal. Default: var(--dds-spacing-600). |
--dds-modal-padding-lg | Padding inside the modal. Default: var(--dds-spacing-1200). |
--dds-modal-transform-amount | Amount to transform for entrance animation. Default: 2rem. |
--dds-modal-transition-speed | Speed of transition animations. Default: var(--dds-transition-fast). |
--dds-modal-transition-timing | Timing function for transitions. Default: var(--dds-easing-ease-in-out). |
--dds-modal-border-width | Border width of the modal. Default: var(--dds-border-width-base). |
--dds-modal-border-color | Border color of the modal. Default: var(--dds-border-neutral-divider). |
--dds-modal-border-radius | Border radius of the modal. Default: var(--dds-radius-large, 16px). |
--dds-modal-background | Background color of the modal. Default: var(--dds-background-neutral-subtle). |
--dds-modal-header-margin-sm | Margin below the header. Default: var(--dds-spacing-400). |
--dds-modal-header-margin-lg | Margin below the header. Default: var(--dds-spacing-600). |
--dds-modal-footer-margin-sm | Margin above the footer. Default: var(--dds-spacing-400). |
--dds-modal-footer-margin-lg | Margin above the footer. Default: var(--dds-spacing-600). |
--dds-modal-footer-gap | Gap between footer elements. Default: var(--dds-spacing-200). |
--dds-modal-close-margin | Margin for the close button. Default: var(--dds-spacing-300). |
CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:
Method 1: Inline styles (Quick customization)
<dap-ds-modal
style="--dds-modal-max-block-size: value; --dds-modal-max-inline-size: value;">
Modal
</dap-ds-modal>
Method 2: CSS classes (Reusable styles)
.my-custom-dap-ds-modal {
--dds-modal-max-block-size: value;
--dds-modal-max-inline-size: value;
--dds-modal-padding-sm: value;
}
<dap-ds-modal class="my-custom-dap-ds-modal">
Modal
</dap-ds-modal>
Method 3: Global theme customization
/* Apply to all instances */
dap-ds-modal {
--dds-modal-max-block-size: value;
--dds-modal-max-inline-size: value;
}
CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.