Skip to content

Commit becb6ce

Browse files
ysdsXhmikosR
authored andcommitted
Add dropdown responsive alignment (#26255)
1 parent 6bae9ef commit becb6ce

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

scss/_dropdown.scss

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,26 @@
3333
@include box-shadow($dropdown-box-shadow);
3434
}
3535

36-
.dropdown-menu-right {
37-
right: 0;
38-
left: auto;
36+
@each $breakpoint in map-keys($grid-breakpoints) {
37+
@include media-breakpoint-up($breakpoint) {
38+
$infix: breakpoint-infix($breakpoint, $grid-breakpoints);
39+
40+
.dropdown-menu#{$infix}-right {
41+
right: 0;
42+
left: auto;
43+
}
44+
}
45+
}
46+
47+
@each $breakpoint in map-keys($grid-breakpoints) {
48+
@include media-breakpoint-up($breakpoint) {
49+
$infix: breakpoint-infix($breakpoint, $grid-breakpoints);
50+
51+
.dropdown-menu#{$infix}-left {
52+
right: auto;
53+
left: 0;
54+
}
55+
}
3956
}
4057

4158
// Allow for dropdowns to go bottom up (aka, dropup-menu)

site/docs/4.1/components/dropdowns.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,44 @@ By default, a dropdown menu is automatically positioned 100% from the top and al
616616
{% endcapture %}
617617
{% include example.html content=example %}
618618

619+
### Responsive alignment
620+
621+
If you want to use responsive alignment, disable dynamic positioning by adding the `data-display="static"` attribute and use the responsive variation classes.
622+
623+
To align **right** the dropdown menu with the given breakpoint or larger, add `.dropdown-menu{-sm|-md|-lg|-xl}-right`.
624+
625+
{% capture example %}
626+
<div class="btn-group">
627+
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" data-display="static" aria-haspopup="true" aria-expanded="false">
628+
Left-aligned but right aligned when large screen
629+
</button>
630+
<div class="dropdown-menu dropdown-menu-lg-right">
631+
<button class="dropdown-item" type="button">Action</button>
632+
<button class="dropdown-item" type="button">Another action</button>
633+
<button class="dropdown-item" type="button">Something else here</button>
634+
</div>
635+
</div>
636+
{% endcapture %}
637+
{% include example.html content=example %}
638+
639+
To align **left** the dropdown menu with the given breakpoint or larger, add `.dropdown-menu-right` and `.dropdown-menu{-sm|-md|-lg|-xl}-left`.
640+
641+
{% capture example %}
642+
<div class="btn-group">
643+
<button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" data-display="static" aria-haspopup="true" aria-expanded="false">
644+
Right-aligned but left aligned when large screen
645+
</button>
646+
<div class="dropdown-menu dropdown-menu-right dropdown-menu-lg-left">
647+
<button class="dropdown-item" type="button">Action</button>
648+
<button class="dropdown-item" type="button">Another action</button>
649+
<button class="dropdown-item" type="button">Something else here</button>
650+
</div>
651+
</div>
652+
{% endcapture %}
653+
{% include example.html content=example %}
654+
655+
Note that you don't need to add a `data-display="static"` attribute to dropdown buttons in navbars, since Popper.js isn't used in navbars.
656+
619657
## Menu content
620658

621659
### Headers

0 commit comments

Comments
 (0)