File tree 3 files changed +49
-1
lines changed
site/content/docs/5.1/components
3 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ const CLASS_NAME_SHOW = 'show'
48
48
const CLASS_NAME_DROPUP = 'dropup'
49
49
const CLASS_NAME_DROPEND = 'dropend'
50
50
const CLASS_NAME_DROPSTART = 'dropstart'
51
+ const CLASS_NAME_DROPUP_CENTER = 'dropup-center'
52
+ const CLASS_NAME_DROPDOWN_CENTER = 'dropdown-center'
51
53
52
54
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="dropdown"]:not(.disabled):not(:disabled)'
53
55
const SELECTOR_DATA_TOGGLE_SHOWN = `${ SELECTOR_DATA_TOGGLE } .${ CLASS_NAME_SHOW } `
@@ -62,6 +64,8 @@ const PLACEMENT_BOTTOM = isRTL() ? 'bottom-end' : 'bottom-start'
62
64
const PLACEMENT_BOTTOMEND = isRTL ( ) ? 'bottom-start' : 'bottom-end'
63
65
const PLACEMENT_RIGHT = isRTL ( ) ? 'left-start' : 'right-start'
64
66
const PLACEMENT_LEFT = isRTL ( ) ? 'right-start' : 'left-start'
67
+ const PLACEMENT_TOPCENTER = 'top'
68
+ const PLACEMENT_BOTTOMCENTER = 'bottom'
65
69
66
70
const Default = {
67
71
offset : [ 0 , 2 ] ,
@@ -248,6 +252,14 @@ class Dropdown extends BaseComponent {
248
252
return PLACEMENT_LEFT
249
253
}
250
254
255
+ if ( parentDropdown . classList . contains ( CLASS_NAME_DROPUP_CENTER ) ) {
256
+ return PLACEMENT_TOPCENTER
257
+ }
258
+
259
+ if ( parentDropdown . classList . contains ( CLASS_NAME_DROPDOWN_CENTER ) ) {
260
+ return PLACEMENT_BOTTOMCENTER
261
+ }
262
+
251
263
// We need to trim the value because custom properties can also include spaces
252
264
const isEnd = getComputedStyle ( this . _menu ) . getPropertyValue ( '--bs-position' ) . trim ( ) === 'end'
253
265
Original file line number Diff line number Diff line change 2
2
.dropup ,
3
3
.dropend ,
4
4
.dropdown ,
5
- .dropstart {
5
+ .dropstart ,
6
+ .dropup-center ,
7
+ .dropdown-center {
6
8
position : relative ;
7
9
}
8
10
Original file line number Diff line number Diff line change @@ -400,6 +400,23 @@ And putting it to use in a navbar:
400
400
Directions are mirrored when using Bootstrap in RTL, meaning ` .dropstart ` will appear on the right side.
401
401
{{< /callout >}}
402
402
403
+ ### Centered
404
+
405
+ Make the dropdown menu centered below the toggle with ` .dropdown-center ` on the parent element.
406
+
407
+ {{< example >}}
408
+ <div class =" dropdown-center " >
409
+ <button class =" btn btn-secondary dropdown-toggle " type =" button " id =" dropdownCenterBtn " data-bs-toggle =" dropdown " aria-expanded =" false " >
410
+ Centered dropdown
411
+ </button >
412
+ <ul class =" dropdown-menu " aria-labelledby =" dropdownCenterBtn " >
413
+ <li><a class="dropdown-item" href="#">Action</a></li>
414
+ <li><a class="dropdown-item" href="#">Action two</a></li>
415
+ <li><a class="dropdown-item" href="#">Action three</a></li>
416
+ </ul >
417
+ </div >
418
+ {{< /example >}}
419
+
403
420
### Dropup
404
421
405
422
Trigger dropdown menus above elements by adding ` .dropup ` to the parent element.
@@ -459,6 +476,23 @@ Trigger dropdown menus above elements by adding `.dropup` to the parent element.
459
476
</div >
460
477
```
461
478
479
+ ### Dropup centered
480
+
481
+ Make the dropup menu centered above the toggle with ` .dropup-center ` on the parent element.
482
+
483
+ {{< example >}}
484
+ <div class =" dropup-center " >
485
+ <button class =" btn btn-secondary dropdown-toggle " type =" button " id =" dropupCenterBtn " data-bs-toggle =" dropdown " aria-expanded =" false " >
486
+ Centered dropup
487
+ </button >
488
+ <ul class =" dropdown-menu " aria-labelledby =" dropupCenterBtn " >
489
+ <li><a class="dropdown-item" href="#">Action</a></li>
490
+ <li><a class="dropdown-item" href="#">Action two</a></li>
491
+ <li><a class="dropdown-item" href="#">Action three</a></li>
492
+ </ul >
493
+ </div >
494
+ {{< /example >}}
495
+
462
496
### Dropend
463
497
464
498
Trigger dropdown menus at the right of the elements by adding ` .dropend ` to the parent element.
You can’t perform that action at this time.
0 commit comments