Documentation
Feedback
Guides
VTEX IO Apps

VTEX IO Apps
Layout Apps
Modal Layout
Official extension
Version: 0.14.1
Latest version: 0.14.1

{"base64":"  ","img":{"width":110,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","url":"https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square"}}

The Modal Layout app provides blocks to help you create modals in your store.

{"base64":"  ","img":{"width":2880,"height":1586,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":1310565,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/vtex-modal-layout-0.png"}}

Configuration

  1. Add the Modal Layout app to your theme dependencies in the manifest.json:

_10
"dependencies": {
_10
+ "vtex.modal-layout": "0.x"
_10
}

Now, you can use all blocks exported by the modal-layout app. See the full list below:

Block nameDescription
modal-trigger
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","url":"https://img.shields.io/badge/-Mandatory-red"}}
Defines how the modal content will be triggered through its children blocks.
modal-layout
{"base64":"  ","img":{"width":69,"height":20,"type":"svg","mime":"image/svg+xml","wUnits":"px","hUnits":"px","url":"https://img.shields.io/badge/-Mandatory-red"}}
Defines how the modal content will be rendered through its children blocks. You can declare the modal-header and modal-content blocks, described below, as children to create a modal with a header and footer.
modal-headerRenders a close button and the blocks listed as its children, building a modal header. Note that it does not automatically render a header for your modal. Instead, you should create the modal header as you desire using the children list of this block.
modal-contentDefines how the modal content will be rendered through its children blocks. Preferably, this block should be used along with the modal-header block in order to create a modal with a header and a footer.
modal-actionsLogical block that only renders its child blocks that, in turn, render call-to-action buttons inside the modal, such as a confirmation button.
modal-actions.closeButton that closes the modal when clicked. It is extremely useful when your modal only has a form or a disclaimer box providing information to the users.
  1. Add the modal-trigger block in any store template you choose. In the example below, it will be added to the homepage:

_10
{
_10
"store.home": {
_10
"children": [
_10
"modal-trigger#example"
_10
]
_10
},

  1. Declare the modal-trigger block using its prop and configure the children blocks. The first child block of modal-trigger must be a block you choose to trigger the modal content. Then, a sibling block called modal-layout will be needed to effectively define the modal content through its child block list. For example:

_21
{
_21
"store.home": {
_21
"children": ["modal-trigger#example"]
_21
},
_21
"modal-trigger#example": {
_21
"children": ["rich-text#example", "modal-layout#example"]
_21
},
_21
"rich-text#example": {
_21
"props": {
_21
"text": "Click me"
_21
}
_21
},
_21
"modal-layout#example": {
_21
"children": ["rich-text#modal-content"]
_21
},
_21
"rich-text#modal-content": {
_21
"props": {
_21
"text": "Hello"
_21
}
_21
}
_21
}

In the example above, the Rich Text block renders the Click me text that will trigger the modal content when clicked. The modal content, in turn, is defined by the modal-layout block. Based on the example above, the modal content triggered by the Click me Rich Text would be a Hello text.

Prop nameTypeDescriptionDefault value
triggerenumDefines whether the modal content should be triggered by user click (click), when the page is fully loaded (load), or when the page is fully loaded, but the modal will appear just once per session (load-session).click
customPixelEventIdstringStore event ID that triggers the modal-trigger block (hence triggering the opening of modal-layout blocks on the interface as well).undefined
customPixelEventNamestringStore event name that triggers the modal-trigger block (hence triggering the opening of modal-layout blocks on the interface as well). Some event examples are 'addToCart' and 'removeFromCart'. Note that using this prop will make the associated modal-layout open in every event with the specified name if no customPixelEventId is set.undefined
Prop nameTypeDescriptionDefault value
scrollenumDefines how users should scroll the modal. Possible values are: body (users can scroll the whole modal by normally scrolling the page) and content (users can scroll the modal content when hovering over it).content
blockClassstringUnique block ID to be used in CSS customizations.undefined
disableEscapeKeyDownbooleanDefines whether the modal should be closed when pressing the Esc key (true) or not (false).false
fullScreenbooleanDefines whether the modal should fill the whole screen (true) or not (false). This prop is responsive, i.e., it adapts to the device breakpoints.false
backdropenumDefines whether the modal will have a clickable backdrop (clickable) or no backdrop at all (none). This prop is responsive, i.e., it adapts to the device breakpoints.clickable
customPixelEventIdstringStore event ID that triggers the modal-layout block (hence triggering the closing of modal-layout blocks on the interface as well).undefined
customPixelEventNamestringStore event name that triggers the modal-layout block (hence triggering the closing of modal-layout blocks on the interface as well). Some event examples are 'addToCart' and 'removeFromCart'. Note that using this prop will make the associated modal-layout close in every event with the specified name if no customPixelEventId is set.undefined
Prop nameTypeDescriptionDefault value
showCloseButtonbooleanDefines whether the close icon button should be rendered in the modal header (true) or not (false).true
iconCloseSizenumberSize (in pixels) of the close icon button in the modal header.32
Prop nameTypeDescriptionDefault value
labelstringDefines the text to be rendered in the close button. The default value of this prop depends on the store's default language, which is set according to the website binding.Cancel, Cancelar, or Cancelar for stores whose default language is, respectively, English, Spanish, or Portuguese.

Customization

To apply CSS customizations in this and other blocks, follow the instructions given in the recipe on Using CSS handles for store customization.

CSS handles
modal
backdropContainer
backdrop
closeButtonContainer
closeButton
container
contentContainer
headerContainer
headerContent
paper
topRow
triggerContainer
See also
VTEX App Store
VTEX IO Apps