Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

feat(modal): add ability to change class on body #4132

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/modal/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The `$modal` service has only one method: `open(options)` where available option
* `windowClass` - additional CSS class(es) to be added to a modal window template
* `windowTemplateUrl` - a path to a template overriding modal's window template
* `size` - optional suffix of modal window class. The value used is appended to the `modal-` class, i.e. a value of `sm` gives `modal-sm`
* `openedClass` - class added to the `body` element when the modal is opened. Defaults to `modal-open`

Global defaults may be set for `$modal` via `$modalProvider.options`.

Expand Down
10 changes: 6 additions & 4 deletions src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ angular.module('ui.bootstrap.modal', [])
openedWindows.remove(modalInstance);

removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, function() {
body.toggleClass(OPENED_MODAL_CLASS, openedWindows.length() > 0);
body.toggleClass(modalInstance.openedClass || OPENED_MODAL_CLASS, openedWindows.length() > 0);
});
checkRemoveBackdrop();

Expand Down Expand Up @@ -385,7 +385,8 @@ angular.module('ui.bootstrap.modal', [])
renderDeferred: modal.renderDeferred,
modalScope: modal.scope,
backdrop: modal.backdrop,
keyboard: modal.keyboard
keyboard: modal.keyboard,
openedClass: modal.openedClass
});

var body = $document.find('body').eq(0),
Expand Down Expand Up @@ -419,7 +420,7 @@ angular.module('ui.bootstrap.modal', [])
openedWindows.top().value.modalDomEl = modalDomEl;
openedWindows.top().value.modalOpener = modalOpener;
body.append(modalDomEl);
body.addClass(OPENED_MODAL_CLASS);
body.addClass(modal.openedClass || OPENED_MODAL_CLASS);
$modalStack.clearFocusListCache();
};

Expand Down Expand Up @@ -619,7 +620,8 @@ angular.module('ui.bootstrap.modal', [])
backdropClass: modalOptions.backdropClass,
windowClass: modalOptions.windowClass,
windowTemplateUrl: modalOptions.windowTemplateUrl,
size: modalOptions.size
size: modalOptions.size,
openedClass: modalOptions.openedClass
});

}, function resolveError(reason) {
Expand Down
23 changes: 23 additions & 0 deletions src/modal/test/modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,29 @@ describe('$modal', function () {

});

describe('openedClass', function () {

it('should add the modal-open class to the body element by default', function () {
open({
template: '<div>dummy modal</div>'
});

expect($document.find('body')).toHaveClass('modal-open');
});

it('should add the custom class to the body element', function () {
open({
template: '<div>dummy modal</div>',
openedClass: 'foo'
});

var body = $document.find('body');

expect(body).toHaveClass('foo');
expect(body).not.toHaveClass('modal-open');
});
});

});

describe('multiple modals', function () {
Expand Down