diff options
| author | Johann-S <[email protected]> | 2017-09-02 09:09:41 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-09-02 09:09:41 +0200 |
| commit | 10ff1c70ceacbec6c23bf5c428ebca19009dc6b7 (patch) | |
| tree | 1aea0b75a55ce027c2acfae6e5a5a59f2e45eab1 /js | |
| parent | 56e415d57d342d23163346bf41c00479617d5f3a (diff) | |
| parent | 37e105333dace2812cedef88ac2aa31a17b38b66 (diff) | |
| download | bootstrap-10ff1c70ceacbec6c23bf5c428ebca19009dc6b7.tar.xz bootstrap-10ff1c70ceacbec6c23bf5c428ebca19009dc6b7.zip | |
Merge pull request #23718 from techdavid/fix-unwanted-padding-on-modal
Fix unwanted body padding when a modal is opened
Diffstat (limited to 'js')
| -rw-r--r-- | js/src/modal.js | 3 | ||||
| -rw-r--r-- | js/tests/unit/modal.js | 28 |
2 files changed, 29 insertions, 2 deletions
diff --git a/js/src/modal.js b/js/src/modal.js index 2ff93342d..4068471cd 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -427,7 +427,8 @@ const Modal = (() => { } _checkScrollbar() { - this._isBodyOverflowing = document.body.clientWidth < window.innerWidth + const rect = document.body.getBoundingClientRect() + this._isBodyOverflowing = rect.left + rect.right < window.innerWidth this._scrollbarWidth = this._getScrollbarWidth() } diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index 5b265df15..735dc4f0c 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -21,6 +21,8 @@ $(function () { document.body.removeChild(scrollDiv) return scrollbarWidth } + // Simulate scrollbars in PhantomJS + $('html').css('padding-right', '16px') }, beforeEach: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode @@ -391,6 +393,30 @@ $(function () { .bootstrapModal('show') }) + QUnit.test('should not adjust the inline body padding when it does not overflow', function (assert) { + assert.expect(1) + var done = assert.async() + var $body = $(document.body) + var originalPadding = $body.css('padding-right') + + // Hide scrollbars to prevent the body overflowing + $body.css('overflow', 'hidden') // real scrollbar (for in-browser testing) + $('html').css('padding-right', '0px') // simulated scrollbar (for PhantomJS) + + $('<div id="modal-test"/>') + .on('shown.bs.modal', function () { + var currentPadding = $body.css('padding-right') + assert.strictEqual(currentPadding, originalPadding, 'body padding should not be adjusted') + $(this).bootstrapModal('hide') + + // restore scrollbars + $body.css('overflow', 'auto') + $('html').css('padding-right', '16px') + done() + }) + .bootstrapModal('show') + }) + QUnit.test('should adjust the inline padding of fixed elements when opening and restore when closing', function (assert) { assert.expect(2) var done = assert.async() @@ -525,7 +551,7 @@ $(function () { $('<div id="modal-test"/>') .on('hidden.bs.modal', function () { - assert.ok(!$body.attr('style'), 'body does not have inline padding set') + assert.strictEqual($body.attr('style').indexOf('padding-right'), -1, 'body does not have inline padding set') $style.remove() done() }) |
