Custom Modals
New modals can be added to the system via the extension registry. This article goes through how this is done.
This page is a work in progress and may undergo further revisions, updates, or amendments. The information contained herein is subject to change without notice.
There are two parts to creating a custom modal:
First, you need to create a modal element which you need to register in the extension registry.
Second, you need to create and export a modal token.
Create a modal token
A modal token is a string that identifies a modal. This is the modal extension alias. It is used to open a modal and is also to set default options for the modal. It should also have a unique alias to avoid conflicts with other modals.
A modal token is a generic type that takes two type arguments. The first is the type of the data that is passed to the modal when it is opened. The second is the type of the value that is returned when the modal is closed.
Create a modal element
A modal element is a web component that is used to render the modal. It should implement the UmbModalExtensionElement
interface. The modal context is injected into the element when the modal is opened in the modalContext
property. The modal context is used to close the modal, update the value and submit the modal.
Additionally, the modal element can see its data parameters through the modalContext
property. In this example, the modal data is of type MyModalData
and the modal value is of type MyModalValue
. The modal context is of type UmbModalContext<MyModalData, MyModalValue>
. We are using the data to render a headline and the value to update the value and submit the modal.
Register in the extension registry
The modal element needs to be registered in the extension registry. This is done by defining the modal in the manifest file. The element
property should point to the file that contains the modal element.
Open the modal
To open the modal, you need to consume the UmbModalManagerContext
and then use the modal manager context to open a modal. This example shows how to consume the Modal Manager Context:
Last updated