Skip to content

Commit b9bd82b

Browse files
committed
patch dropdowns for twbs#7118
1 parent 37d0a30 commit b9bd82b

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

docs/assets/css/bootstrap.css

+9
Original file line numberDiff line numberDiff line change
@@ -3009,6 +3009,15 @@ table th[class*="span"],
30093009
display: block;
30103010
}
30113011

3012+
.dropdown-backdrop {
3013+
position: fixed;
3014+
top: 0;
3015+
right: 0;
3016+
bottom: 0;
3017+
left: 0;
3018+
z-index: 990;
3019+
}
3020+
30123021
.pull-right > .dropdown-menu {
30133022
right: 0;
30143023
left: auto;

docs/assets/js/bootstrap-dropdown.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
clearMenus()
5353

5454
if (!isActive) {
55+
if ('ontouchstart' in document.documentElement) {
56+
// if mobile we we use a backdrop because click events don't delegate
57+
$('<div class="dropdown-backdrop"/>').insertBefore($(this)).on('click', clearMenus)
58+
}
5559
$parent.toggleClass('open')
5660
}
5761

@@ -104,6 +108,7 @@
104108
}
105109

106110
function clearMenus() {
111+
$('.dropdown-backdrop').remove()
107112
$(toggle).each(function () {
108113
getParent($(this)).removeClass('open')
109114
})
@@ -158,7 +163,6 @@
158163
$(document)
159164
.on('click.dropdown.data-api', clearMenus)
160165
.on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
161-
.on('click.dropdown-menu', function (e) { e.stopPropagation() })
162166
.on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
163167
.on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
164168

docs/assets/js/bootstrap.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,10 @@
685685
clearMenus()
686686

687687
if (!isActive) {
688+
if ('ontouchstart' in document.documentElement) {
689+
// if mobile we we use a backdrop because click events don't delegate
690+
$('<div class="dropdown-backdrop"/>').insertBefore($(this)).on('click', clearMenus)
691+
}
688692
$parent.toggleClass('open')
689693
}
690694

@@ -737,6 +741,7 @@
737741
}
738742

739743
function clearMenus() {
744+
$('.dropdown-backdrop').remove()
740745
$(toggle).each(function () {
741746
getParent($(this)).removeClass('open')
742747
})
@@ -791,7 +796,6 @@
791796
$(document)
792797
.on('click.dropdown.data-api', clearMenus)
793798
.on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
794-
.on('click.dropdown-menu', function (e) { e.stopPropagation() })
795799
.on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
796800
.on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
797801

docs/assets/js/bootstrap.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/bootstrap-dropdown.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
clearMenus()
5353

5454
if (!isActive) {
55+
if ('ontouchstart' in document.documentElement) {
56+
// if mobile we we use a backdrop because click events don't delegate
57+
$('<div class="dropdown-backdrop"/>').insertBefore($(this)).on('click', clearMenus)
58+
}
5559
$parent.toggleClass('open')
5660
}
5761

@@ -104,6 +108,7 @@
104108
}
105109

106110
function clearMenus() {
111+
$('.dropdown-backdrop').remove()
107112
$(toggle).each(function () {
108113
getParent($(this)).removeClass('open')
109114
})
@@ -158,7 +163,6 @@
158163
$(document)
159164
.on('click.dropdown.data-api', clearMenus)
160165
.on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
161-
.on('click.dropdown-menu', function (e) { e.stopPropagation() })
162166
.on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
163167
.on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
164168

less/dropdowns.less

+11
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@
135135
}
136136
}
137137

138+
// Backdrop to catch body clicks on mobile, etc.
139+
// ---------------------------
140+
.dropdown-backdrop {
141+
position: fixed;
142+
left: 0;
143+
right: 0;
144+
bottom: 0;
145+
top: 0;
146+
z-index: @zindexDropdown - 10;
147+
}
148+
138149
// Right aligned dropdowns
139150
// ---------------------------
140151
.pull-right > .dropdown-menu {

0 commit comments

Comments
 (0)