Skip to main content

Modal

The Modal component is used as a dialog for bringing focus to information with an overlay on primary content.

Import

// with @dhl-official/react-library:
import { DhlModal } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlModal } from "@dhl-official/ui-libraries/react-library"

Usage

The Modal utilizes the Card component and accepts the same header and footer slot configuration (which refers to the Card header and footer)

A Modal can be triggered:

  • By attaching a state trigger through the isOpen prop or is-open attribute.

Please ensure a dataId / data-id is supplied to the Modal for initialisation

Code

Please note, the below code-snippets are specific to the Modal itself - see above for information on how to trigger a Modal.

<DhlModal>  
<DhlHeadline slot="header" designLevel="4" noMargin dataId="dialog-headline">
Header
</DhlHeadline>
<DhlText>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean
commodo ligula eget dolor. Aenean massa. Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur.
</DhlText>
<DhlButton slot="footer">Button</DhlButton>
</DhlModal>

Interactive Demo

Migrating from DUIL 1.0

  • Rename onClose to handleOnClose
  • Rename isStatic to trapFocus
  • Add handleOnShow prop for function call when dialog open

Readme

Properties

PropertyAttributeDescriptionTypeDefault
closeButtonAriaLabelclose-button-aria-labelAn optional prop defining the text read by the screen reader to represent the inner Modal close Button.stringundefined
dataAriaDescribedbydata-aria-describedbyAn optional prop defining the list of reference IDs (separated by spaces), recommended when you want to an error message on your field.stringundefined
dataAriaLabelledbydata-aria-labelledbyAn optional ariaLabelledby prop that establishes the relationships between objects and their label(s), and its value should be one or more element IDs, which refer to elements that have the text needed for labelling. List multiple element IDs in a space delimited fashion.stringundefined
dataCardAriaLabeldata-card-aria-labelAn optional prop defining the text read by the screen reader to represent the Card within the Modal.stringundefined
dataClassNamedata-class-nameAn optional class name prop for the component.stringundefined
dataIddata-idAn optional prop. Gives a valid HTML ID attribute value for the component.stringdhl-modal-${getRandomString()}
dataTestiddata-testidAn optional prop. The test id attached to the component as a data-testid attribute.stringundefined
handleOnClose--An optional function to be called when the Modal is closed.() => voidundefined
handleOnShow--An optional function to be called when the Modal is shown.() => voidundefined
isOpenis-openAn optional boolean prop used to toggle the visibility of the Modalbooleanfalse
overlayColoroverlay-colorAn optional prop used to set the css background color of the Modal overlaystringdefaultOverlayColor
shouldShowCloseButtonshould-show-close-buttonAn optional boolean prop used to toggle the visibility of the close button. The Modal retains ability to be closed through esc key, or overlay click (unless trapFocus is set to true)booleantrue
trapFocustrap-focusAn optional prop used to prevent Modal closing through an overlay click. If set, Modal can only be closed via the inner close icon or by a custom implementation.booleanfalse

Events

EventDescriptionType
dhlModalHideEvent emitted when the modal is hiddenCustomEvent<any>
dhlModalShowEvent emitted when the modal is shownCustomEvent<any>

Slots

SlotDescription
"footer"used for elements intended to be positioned as the DhlCard footer within DhlModal
"header"used for elements intended to be positioned as the DhlCard header within DhlModal
"unnamed"unnamed children slot for Modal content

Dependencies

Depends on

Graph


Built by DHL User Interface Library Team!