Skip to content

Commit

Permalink
MDL-78274 modal: Enable modals to be vertically centered
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocolate-lightning committed Jun 21, 2023
1 parent 1b1a15a commit 0fb1152
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/amd/build/modal.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/amd/build/modal.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/amd/build/modal_factory.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/amd/build/modal_factory.min.js.map

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions lib/amd/src/modal.js
Expand Up @@ -561,6 +561,18 @@ export default class Modal {
this.getModal().addClass('modal-lg');
}

/**
* Mark the modal as a centered modal.
*
* @method setVerticallyCentered
*/
setVerticallyCentered() {
if (this.isVerticallyCentered()) {
return;
}
this.getModal().addClass('modal-dialog-centered');
}

/**
* Check if the modal is a large modal.
*
Expand All @@ -571,6 +583,16 @@ export default class Modal {
return this.getModal().hasClass('modal-lg');
}

/**
* Check if the modal is vertically centered.
*
* @method isVerticallyCentered
* @return {bool}
*/
isVerticallyCentered() {
return this.getModal().hasClass('modal-dialog-centered');
}

/**
* Mark the modal as a small modal.
*
Expand Down
5 changes: 5 additions & 0 deletions lib/amd/src/modal_factory.js
Expand Up @@ -165,6 +165,7 @@ const createFromType = (registryConf, templateContext) => {
export const create = (modalConfig, triggerElement) => {
const type = modalConfig.type || types.DEFAULT;
const isLarge = modalConfig.large ? true : false;
const isVerticallyCentered = modalConfig.verticallyCentered ? true : false;
// If 'scrollable' is not configured, set the modal to be scrollable by default.
const isScrollable = modalConfig.hasOwnProperty('scrollable') ? modalConfig.scrollable : true;

Expand Down Expand Up @@ -199,6 +200,10 @@ export const create = (modalConfig, triggerElement) => {
modal.setLarge();
}

if (isVerticallyCentered) {
modal.setVerticallyCentered();
}

if (typeof modalConfig.removeOnClose !== 'undefined') {
// If configured remove the modal when hiding it.
modal.setRemoveOnClose(modalConfig.removeOnClose);
Expand Down

0 comments on commit 0fb1152

Please sign in to comment.