<vega-modal
size="400"
backdrop="static"
open=false
id = "my-modal">
<p>This content will appear in the modal.</p>
<div>
<vega-button data-dismiss="modal">
Close
</vega-button>
</div>
</vega-modal>
<vega-button data-target="my-modal">Launch modal</vega-button>
<vega-modal id="handle-close-modal-template" modal-title="Demo modal">
<div class="v-font-h6 v-text-secondary v-mb-size-12">Try to click the close button on top right.</div>
</vega-modal>
<vega-button data-target="handle-close-modal-template">Launch modal</vega-button>
const modal = document.querySelector('#handle-close-modal-template');
modal.handleClose = () => {
if (confirm('Confirm you will close the modal')) {
return true; // Will close the modal if the callback return true, otherwise do nothing
}
};
The vega-modal
is a dialogue window which appears on top of the parent screen. Unlike pop-up windows, these disable the parent screen, but keep it visible. The modal window
may open when a user presses a button on the page which triggers this action, and a user must interact with this screen before returning to the main/parent screen.
Modal windows are used when it becomes necessary to interrupt the user’s attention for an action that needs to be taken.
Name | Description | Default |
---|---|---|
backdrop | The backdrop property determines whether the modal will close when clicking on the background. The default setting and null allow the modal to close on click, whereas the static setting will disable this functionality and will require that the user interact directly with the modal to disregard it. Setting this to “none” will render no backdrop. static |
"" |
size | This specifies the size of the modal. The options that can be set as number or ResponsiveType. Note. There are different maximum widths for modal windows depending on the viewport size. If size exceeds the maximum width the maximum modal width will be used in its place. | - |
open | The open property is a boolean value which determines whether the modal is open or closed by default. It is set as false by default. Optional | false |
animation | Controls whether animation applies when modal appears. Optional | false |
modal-title | the modal title. string | |
backdrop-color | The backdrop-color property determines the background of the modal. Options include ‘default’,‘semi’,and ‘none’ | default |
is-vertically-center | set modal vertically center.Optional | false |
show-close-button | boolean indicating if the modal will show or hide the close button. Optional | true |
padding | This specifies the padding within the modal. It can be set as ResponsiveType or any spacing token | size-24 |
content-max-height | This specifies the max height of the modal content. The content can be scrolled if this value is set. It may be set as ResponsiveType. | object |
handle-close | A callback function that can be called if a user clicks the “close” button on the upper right. It will close the modal if the callback returns true. boolean |
<vega-modal
size="any number | { [key in default|S|M|L|XL]?: any number }"
backdrop="static|''"
open=true|false
animation=true|false
modal-title=""
backdrop-color="default|semi|none"
is-vertically-center=true|false
show-close-button=true|false
>
<!--Content-->
</vega-modal>
For more details, view in Storybook.
Note: Vega modal has a default maximum width dependent on screen size. If
size
exceeds the maximum width, the maximum modal width will be used instead.
Note re: scrolling: If the modal content is too long, a scroll bar will appear and the body cannot be scrolled. For iOS, the body content of the scrolling modal will occasionally appear to scroll. This problem also appears in:
You may use slots to set the modal header, content, and footer.
Example:
<vega-modal>
<div slot='modal-title'></div>
<div slot='modal-content'></div>
<div slot='modal-footer'></div>
</vega-modal>
You may use the vega-modal
without JavaScript by making use of the data-target
data attribute. Note that the data-target
id must match the id
of the vega-modal
.
<vega-button data-target="modalID">Launch modal</vega-button>
You may use a single line of JavaScript to call a modal:
document.getElementById('my-modal').modal(option);
You may hide a modal using .modal("hide")
or show it using .modal("show")
.
Both methods return to the caller before the modal has been shown or hidden.
Vega modals dispatch two events:
vegaOpen
is dispatched when the modal is opened and rendered.document.getElementById("modal_id").addEventListener("vegaOpen", (e) => { console.log(e.currentTarget.value)
})
vegaClose
is dispatched when the modal is closed. document.getElementById("modal_id").addEventListener("vegaClose", (e) => { console.log(e.currentTarget.value)
})
Do
Don't