{% include '@bolt-elements-button/button.twig' with {
content: 'Open Modal',
attributes: {
type: 'button',
'data-bolt-modal-target': '.js-target-name',
}
} only %}
{% include '@bolt-components-modal/modal.twig' with {
content: 'This is a modal',
attributes: {
class: 'js-target-name'
},
} only %}
Prop Name | Description | Type | Default Value | Option(s) |
---|---|---|---|---|
attributes
|
A Drupal attributes object. Used to apply additional HTML attributes to the outer <bolt-modal> tag. |
object
| — |
|
width
|
Controls the width of the modal container. |
string
|
optimal
|
|
spacing
|
Controls the spacing around the modal container. |
string
|
medium
|
|
persistent
|
Enables the modal to be persistent. This will eliminate ways to close the modal and it is up to the author to provide a custom link to close the modal or redirect to another page within the modal content. Must be used in tandem with the |
boolean
|
false
|
|
persistent_return_url
|
The URL to be used on a return link. If a modal is persistent, a return link is required to provide the user a way out. Must be used in tandem with the |
string
| — |
|
theme
|
Controls the color theme of the modal container. |
string
|
xlight
|
|
scroll
|
Controls the scrolling area. |
string
|
container
|
|
uuid
|
Unique ID for modal, randomly generated if not provided. |
string
| — |
|
npm install @bolt/components-modal
This is the modal container's header.
This is the modal container's body.
This is the modal container's footer.
width
prop. The default is set to optimal
.
full
modal takes up the full width of the screen minus the gutters (about 2rem on left and right).regular
modal is 10 out 12 columns wide, about 80% of the screen width.optimal
modal is about 75 characters wide, close to optimal reading length.auto
modal adjusts to the width of the modal content. In most cases, the user must define a max-width in absolute value (do not use relative value such as %) on the modal content to get the desired results. Recommended for advanced usage.width
prop only applies to viewports equal to or above the small breakpoint (~600px).width
attribute defined (e.g. 640) in tandem with auto width modal will allow the image inside the modal to be responsive but does not stretch beyond the specified width
.{% include '@bolt-components-modal/modal.twig' with {
content: 'This is a modal set to full width.',
width: 'full',
attributes: {
class: 'js-bolt-modal--width-full',
},
} only %}
spacing
prop. The default is set to medium
.
none
prop removes the spacing inside the modal container.small
, medium
, and large
props add the respective spacing around the modal content.spacing
prop only applies to viewports equal to or above the small breakpoint (~600px).{% include '@bolt-components-modal/modal.twig' with {
content: 'This is a modal set to small spacing.',
spacing: 'small',
attributes: {
class: 'js-bolt-modal--spacing-small',
},
} only %}
theme
prop. The default is set to xlight
.
none
prop makes the modal container transparent.xlight
, light
, dark
, and xdark
props adds the respective theme to the modal container.theme
prop only applies to viewports equal to or above the small breakpoint (~600px).{% include '@bolt-components-modal/modal.twig' with {
content: 'This is a modal with a xlight theme.',
theme: 'xlight',
attributes: {
class: 'js-bolt-modal--theme-xlight',
},
} only %}
scroll
prop. The default is set to container
.
overall
prop makes the overall viewport area scrollable.container
prop makes the modal container itself scrollable.scroll
prop only applies to viewports equal to or above the small breakpoint (~600px).{% include '@bolt-components-modal/modal.twig' with {
content: 'This is a modal set to overall scrolling.',
scroll: 'overall',
attributes: {
class: 'js-bolt-modal--scroll-overall',
},
} only %}
{# Button element #}
{% include '@bolt-elements-button/button.twig' with {
content: 'Button trigger',
size: 'small',
attributes: {
type: 'button',
'data-bolt-modal-target': '.js-bolt-modal--trigger-button',
},
} only %}
{% include '@bolt-components-modal/modal.twig' with {
content: 'This modal is triggered by a button.',
attributes: {
class: 'js-bolt-modal--trigger-button'
},
} only %}
{# Image element and Trigger component #}
{% set trigger_content %}
{% include '@bolt-elements-image/image.twig' with {
attributes: {
src: '/images/placeholders/tout-4x3-climber.jpg',
alt: 'A Rock Climber',
loading: 'lazy',
style: 'max-width: 320px',
width: '640',
height: '480'
}
} only %}
{% endset %}
{% set modal_content %}
{% include '@bolt-elements-image/image.twig' with {
attributes: {
src: '/images/placeholders/tout-4x3-climber.jpg',
alt: 'A Rock Climber',
width: '640',
height: '480'
}
} only %}
{% endset %}
{% include '@bolt-components-trigger/trigger.twig' with {
content: trigger_content,
cursor: 'zoom-in',
display: 'inline',
attributes: {
'data-bolt-modal-target': '.js-bolt-modal--trigger-image',
},
} only %}
{% include '@bolt-components-modal/modal.twig' with {
content: modal_content,
spacing: 'none',
theme: 'none',
scroll: 'overall',
width: 'auto',
attributes: {
class: 'js-bolt-modal--trigger-image'
},
} only %}
{# Text Link element #}
{% include '@bolt-elements-text-link/text-link.twig' with {
content: 'Text link trigger',
attributes: {
type: 'button',
'data-bolt-modal-target': '.js-bolt-modal--trigger-link',
},
} only %}
{% include '@bolt-components-modal/modal.twig' with {
content: 'This modal is triggered by a text link.',
attributes: {
class: 'js-bolt-modal--trigger-link'
},
} only %}
data-bolt-modal-target
data attribute to a trigger element, or by calling the Modal's show()
and hide()
methods directly via JavaScript.data-bolt-modal-target
on a trigger element to toggle a modal. The value of the data attribute must be a valid CSS selector that matches your target modal. When you click the trigger the modal will show if currently hidden or it will hide if currently shown.
data-bolt-modal-target
data attribute.show()
and hide()
methods to toggle a modal. Before calling any methods on the modal you must first wait for the Modal component to be ready. See the demo below for reference.
show()
method.hide()
method will be called when you click the button below.<script>
const modal = document.querySelector('.js-bolt-modal--js-demo');
const showButton = document.querySelector('.js-bolt-modal-trigger--open');
const hideButton = document.querySelector('.js-bolt-modal-trigger--close');
// Promise ensures Modal is defined before calling hide/show
customElements.whenDefined('bolt-modal').then(() => {
showButton.addEventListener('click', () => {
modal.show();
})
hideButton.addEventListener('click', () => {
modal.hide();
})
});
</script>
data-bolt-modal-target
attribute. The value of this attribute is the target modal's class. There is JS that will handle the opening on target modal based on the attribute's value.video-js
requires a couple of attributes to delay the initialization. There are four attributes that are required, three of these replace the default Brightcove attributes.full_bleed
prop must be set to false
.This is a paragraph. Suspendisse dictum feugiat nisl ut dapibus. Mauris iaculis porttitor posuere. Praesent id metus massa, ut blandit odio. Proin quis tortor orci. Etiam at risus et justo dignissim congue. Donec congue lacinia dui, a porttitor lectus condimentum laoreet. Nunc eu ullamcorper orci. Quisque eget odio ac lectus vestibulum faucibus eget in metus. In pellentesque faucibus vestibulum. Nulla at nulla justo, eget luctus tortor. Nulla facilisi. Duis aliquet egestas purus in blandit. Curabitur vulputate, ligula lacinia scelerisque tempor, lacus lacus ornare ante, ac egestas est urna sit amet arcu. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed molestie augue sit amet leo consequat posuere. Vestibulum ante.
width
to full
to maximize space. For example, you can build a multi-column layout with the grid, band, and card components.This Is an Eyebrow
This Is a Subheadline
This is a paragraph. Suspendisse dictum feugiat nisl ut dapibus. Mauris iaculis porttitor posuere. Praesent id metus massa, ut blandit odio. Proin quis tortor orci. Etiam at risus et justo dignissim congue. Donec congue lacinia dui, a porttitor lectus condimentum laoreet. Nunc eu ullamcorper orci. Quisque eget odio ac lectus vestibulum faucibus eget in metus. In pellentesque faucibus vestibulum. Nulla at nulla justo, eget luctus tortor. Nulla facilisi. Duis aliquet egestas purus in blandit. Curabitur vulputate, ligula lacinia scelerisque tempor, lacus lacus ornare ante, ac egestas est urna sit amet arcu. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed molestie augue sit amet leo consequat posuere. Vestibulum ante.
persistent
and persistent_return_url
. When a modal is persistent, the default close button is not shown, the only ways to close the modal is through filling out the form, hitting the return link, or hitting the escape key on the keyboard (which acts exactly like the return link).Modal content can be anything. Content authors are free to set up single or multiple column layouts. The recommended format is text content on the left and form on the right. The return link is required, which is in its own cell under both the text content and form cells. It should not be part of the free-form authorable content, instead two required fields are required for content authors to input: return link url and return link text.
(all fields are required)
<bolt-modal>
in the markup to make it render. In the following examples, we use data-bolt-modal-target
to trigger the modal. However, the same options shown on the Usage Javascript page are also available on the web component.
<button type="button" class="e-bolt-button" data-bolt-modal-target=".js-bolt-modal-demo">
Open Modal
</button>
<bolt-modal class="js-bolt-modal-demo">
This is a modal.
</bolt-modal>
header
, default
, footer
. To pass content to either the header or footer, slot
must be defined.
<button type="button" class="e-bolt-button" data-bolt-modal-target=".js-bolt-modal-basic-demo">
Open Modal
</button>
<bolt-modal class="js-bolt-modal-basic-demo">
<bolt-text slot="header">This is the header</bolt-text>
<bolt-text>This is the body (default).</bolt-text>
<bolt-text slot="footer">This is the footer</bolt-text>
</bolt-modal>
<bolt-modal>
element. Use unique combinations to customize a modal to your liking.
<button type="button" class="e-bolt-button" data-bolt-modal-target=".js-bolt-modal-advanced-demo">
Open Modal
</button>
<bolt-modal width="optimal" spacing="none" theme="none" scroll="overall" class="js-bolt-modal-advanced-demo">
<bolt-image src="/images/content/backgrounds/background-robotics-customer-service.jpg" alt="This is an image"></bolt-image>
</bolt-modal>