Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bootstrap
bootstrap
Commits
10ff1c70
Commit
10ff1c70
authored
7 years ago
by
Johann-S
Committed by
GitHub
7 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #23718 from techdavid/fix-unwanted-padding-on-modal
Fix unwanted body padding when a modal is opened
parents
56e415d5
37e10533
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/src/modal.js
+2
-1
js/src/modal.js
js/tests/unit/modal.js
+27
-1
js/tests/unit/modal.js
with
29 additions
and
2 deletions
+29
-2
js/src/modal.js
+
2
-
1
View file @
10ff1c70
...
@@ -427,7 +427,8 @@ const Modal = (() => {
...
@@ -427,7 +427,8 @@ const Modal = (() => {
}
}
_checkScrollbar
()
{
_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
()
this
.
_scrollbarWidth
=
this
.
_getScrollbarWidth
()
}
}
...
...
This diff is collapsed.
Click to expand it.
js/tests/unit/modal.js
+
27
-
1
View file @
10ff1c70
...
@@ -21,6 +21,8 @@ $(function () {
...
@@ -21,6 +21,8 @@ $(function () {
document
.
body
.
removeChild
(
scrollDiv
)
document
.
body
.
removeChild
(
scrollDiv
)
return
scrollbarWidth
return
scrollbarWidth
}
}
// Simulate scrollbars in PhantomJS
$
(
'
html
'
).
css
(
'
padding-right
'
,
'
16px
'
)
},
},
beforeEach
:
function
()
{
beforeEach
:
function
()
{
// Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode
// 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 () {
...
@@ -391,6 +393,30 @@ $(function () {
.
bootstrapModal
(
'
show
'
)
.
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
)
{
QUnit
.
test
(
'
should adjust the inline padding of fixed elements when opening and restore when closing
'
,
function
(
assert
)
{
assert
.
expect
(
2
)
assert
.
expect
(
2
)
var
done
=
assert
.
async
()
var
done
=
assert
.
async
()
...
@@ -525,7 +551,7 @@ $(function () {
...
@@ -525,7 +551,7 @@ $(function () {
$
(
'
<div id="modal-test"/>
'
)
$
(
'
<div id="modal-test"/>
'
)
.
on
(
'
hidden.bs.modal
'
,
function
()
{
.
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
()
$style
.
remove
()
done
()
done
()
})
})
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets