Modal сomponent
Overview
The Modal UI component implements a secondary window that opens on top of the main window. It uses the modal widget.
Similar to the widget’s configuration, the component’s configuration allows you to set the window type and the behavior of action buttons (including linking action buttons to methods of the other UI components).
The Modal component can be used for both Admin and storefronts.
For recommendations about modal windows usage from the UX point of view, see the corresponding topic in the Magento Admin pattern library.
Structure
The modal UI component comprises the following files:
- JS component:
<Magento_Ui_module_dir>/view/base/web/js/modal/modal-component.js
- Template:
<Magento_Ui_module_dir>/view/base/web/templates/modal/modal-component.html
Options
Component’s options are set in the configuration .xml
file as follows:
Extends UiCollection configuration.
Modal-specific configuration:
Option | Description | Type | Default |
---|---|---|---|
modalClass |
CSS class applied to the root node of the component's .html template. |
String | modal-component |
onCancel |
Name of the method invoked when a user attempts to close the modal window. | String | closeModal |
options |
Configuration passed to the modal widget. | Object | |
subTitle |
Subtitle of the modal window. | String | |
template |
Path to the component's .html template. | String | ui/modal/modal-component |
title |
Label displayed in the header of the modal window. | String |
Example of the Modal component configuration
The following sample is an example of the configuration for a simple modal window containing one text field and a standard set of action buttons (Cancel, Clear, Done):
Public API (JS)
actionCancel()
: returns all modal’s child components to the state they had on modal open and closes the modal window.actionDone()
: validates the changes in the modal’s child components and, if valid, closes the modal.closeModal()
: closes the modal window.openModal()
: opens the modal window.setPrevValues(elem)
: returns allelem
’s child components to the state they had on modal open.setTitle()
: sets modal title.setSubTitle()
: sets modal sub title.toggleModal()
: toggles the modal window state (open/close).