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

Commit 5a28ff7

Browse files
committed
feat(modal): add ability to change class on body
- Add support for `openedClass` to allow overriding the default modal class added & removed on the `body` element (`modal-open`) Closes #2633 Closes #4132
1 parent f081fab commit 5a28ff7

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

Diff for: src/modal/docs/readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The `$modal` service has only one method: `open(options)` where available option
1717
* `windowClass` - additional CSS class(es) to be added to a modal window template
1818
* `windowTemplateUrl` - a path to a template overriding modal's window template
1919
* `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`
20+
* `openedClass` - class added to the `body` element when the modal is opened. Defaults to `modal-open`
2021

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

Diff for: src/modal/modal.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ angular.module('ui.bootstrap.modal', [])
272272
openedWindows.remove(modalInstance);
273273

274274
removeAfterAnimate(modalWindow.modalDomEl, modalWindow.modalScope, function() {
275-
body.toggleClass(OPENED_MODAL_CLASS, openedWindows.length() > 0);
275+
body.toggleClass(modalInstance.openedClass || OPENED_MODAL_CLASS, openedWindows.length() > 0);
276276
});
277277
checkRemoveBackdrop();
278278

@@ -385,7 +385,8 @@ angular.module('ui.bootstrap.modal', [])
385385
renderDeferred: modal.renderDeferred,
386386
modalScope: modal.scope,
387387
backdrop: modal.backdrop,
388-
keyboard: modal.keyboard
388+
keyboard: modal.keyboard,
389+
openedClass: modal.openedClass
389390
});
390391

391392
var body = $document.find('body').eq(0),
@@ -419,7 +420,7 @@ angular.module('ui.bootstrap.modal', [])
419420
openedWindows.top().value.modalDomEl = modalDomEl;
420421
openedWindows.top().value.modalOpener = modalOpener;
421422
body.append(modalDomEl);
422-
body.addClass(OPENED_MODAL_CLASS);
423+
body.addClass(modal.openedClass || OPENED_MODAL_CLASS);
423424
$modalStack.clearFocusListCache();
424425
};
425426

@@ -621,7 +622,8 @@ angular.module('ui.bootstrap.modal', [])
621622
backdropClass: modalOptions.backdropClass,
622623
windowClass: modalOptions.windowClass,
623624
windowTemplateUrl: modalOptions.windowTemplateUrl,
624-
size: modalOptions.size
625+
size: modalOptions.size,
626+
openedClass: modalOptions.openedClass
625627
});
626628

627629
}, function resolveError(reason) {

Diff for: src/modal/test/modal.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,29 @@ describe('$modal', function () {
767767

768768
});
769769

770+
describe('openedClass', function () {
771+
772+
it('should add the modal-open class to the body element by default', function () {
773+
open({
774+
template: '<div>dummy modal</div>'
775+
});
776+
777+
expect($document.find('body')).toHaveClass('modal-open');
778+
});
779+
780+
it('should add the custom class to the body element', function () {
781+
open({
782+
template: '<div>dummy modal</div>',
783+
openedClass: 'foo'
784+
});
785+
786+
var body = $document.find('body');
787+
788+
expect(body).toHaveClass('foo');
789+
expect(body).not.toHaveClass('modal-open');
790+
});
791+
});
792+
770793
});
771794

772795
describe('multiple modals', function () {

0 commit comments

Comments
 (0)