Skip to content

Commit 53ee455

Browse files
committed
Handle dropup for Dropdown
1 parent 69de651 commit 53ee455

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

js/src/dropdown.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ const Dropdown = (($) => {
6464
VISIBLE_ITEMS : '.dropdown-menu .dropdown-item:not(.disabled)'
6565
}
6666

67+
const AttachmentMap = {
68+
TOP : 'top',
69+
BOTTOM : 'bottom'
70+
}
71+
6772
const Default = {
68-
placement : 'bottom',
73+
placement : AttachmentMap.BOTTOM,
6974
offset : 0
7075
}
7176

@@ -141,8 +146,10 @@ const Dropdown = (($) => {
141146
return false
142147
}
143148

149+
// Handle dropup
150+
const dropdownPlacement = $(this).parent().hasClass('dropup') ? AttachmentMap.TOP : context._config.placement
144151
this._popper = new Popper(this, context._menu, {
145-
placement : context._config.placement,
152+
placement : dropdownPlacement,
146153
modifiers : {
147154
offset : {
148155
offset : context._config.offset

js/tests/unit/tooltip.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ $(function () {
456456
assert.expect(1)
457457
var done = assert.async()
458458

459-
var containerHTML = '<div>'
459+
var containerHTML = '<div id="test">'
460460
+ '<p style="margin-top: 200px">'
461461
+ '<a href="#" title="very very very very very very very long tooltip">Hover me</a>'
462462
+ '</p>'
@@ -482,7 +482,12 @@ $(function () {
482482
})
483483
.on('shown.bs.tooltip', function () {
484484
var $tooltip = $($(this).data('bs.tooltip').tip)
485-
assert.ok(Math.round($tooltip.offset().top + $tooltip.outerHeight()) >= Math.round($(this).offset().top))
485+
if (/iPhone|iPad|iPod/.test(navigator.userAgent)) {
486+
assert.ok(Math.round($tooltip.offset().top + $tooltip.outerHeight()) <= Math.round($(this).offset().top))
487+
}
488+
else {
489+
assert.ok(Math.round($tooltip.offset().top + $tooltip.outerHeight()) >= Math.round($(this).offset().top))
490+
}
486491
done()
487492
})
488493
.bootstrapTooltip('show')

js/tests/visual/dropdown.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ <h1>Dropdown <small>Bootstrap Visual Test</small></h1>
5858
</div>
5959
</li>
6060
</ul>
61+
62+
<!-- Default dropup button -->
63+
<div class="btn-group dropup" style="margin-top: 60px;">
64+
<button type="button" class="btn btn-secondary">Dropup</button>
65+
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
66+
<span class="sr-only">Toggle Dropdown</span>
67+
</button>
68+
<div class="dropdown-menu">
69+
<a class="dropdown-item" href="#">Action</a>
70+
<a class="dropdown-item" href="#">Another action</a>
71+
<a class="dropdown-item" href="#">Something else here</a>
72+
</div>
73+
</div>
6174
</div>
6275

6376
<script src="../../../docs/assets/js/vendor/jquery-slim.min.js"></script>

scss/_dropdown.scss

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
}
2424
}
2525

26+
// Allow for dropdowns to go bottom up (aka, dropup-menu)
27+
// Just add .dropup after the standard .dropdown class and you're set.
2628
.dropup {
2729
.dropdown-toggle {
2830
&::after {
@@ -133,9 +135,3 @@
133135
color: $dropdown-header-color;
134136
white-space: nowrap; // as with > li > a
135137
}
136-
137-
// Allow for dropdowns to go bottom up (aka, dropup-menu)
138-
//
139-
// Just add .dropup after the standard .dropdown class and you're set.
140-
141-
//.dropup {}

0 commit comments

Comments
 (0)