Skip to content

Commit e186639

Browse files
jacobmllr95tmorehouse
authored andcommitted
feat(dropfoen): Add dropright and dropleft direction support (#2117)
This commit adds support for the dropright` and `dropleft` directions for the dropdown component. Closes #2108.
1 parent e39a855 commit e186639

File tree

4 files changed

+86
-14
lines changed

4 files changed

+86
-14
lines changed

src/components/dropdown/README.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Turn your dropdown menu into a drop-up menu by setting the `dropup` prop.
136136

137137
```html
138138
<div>
139-
<b-dropdown id="ddown-dropup" dropup text="Drop-Up" variant="info" class="m-2">
139+
<b-dropdown id="ddown-dropup" dropup text="Drop-Up" variant="primary" class="m-2">
140140
<b-dropdown-item href="#">Action</b-dropdown-item>
141141
<b-dropdown-item href="#">Another action</b-dropdown-item>
142142
<b-dropdown-item href="#">Something else here</b-dropdown-item>
@@ -146,6 +146,36 @@ Turn your dropdown menu into a drop-up menu by setting the `dropup` prop.
146146
<!-- dropdown-dropup.vue -->
147147
```
148148

149+
### Dropright
150+
Turn your dropdown menu into a drop-right menu by setting the `dropright` prop.
151+
152+
```html
153+
<div>
154+
<b-dropdown id="ddown-dropright" dropright text="Drop-Right" variant="primary" class="m-2">
155+
<b-dropdown-item href="#">Action</b-dropdown-item>
156+
<b-dropdown-item href="#">Another action</b-dropdown-item>
157+
<b-dropdown-item href="#">Something else here</b-dropdown-item>
158+
</b-dropdown>
159+
</div>
160+
161+
<!-- dropdown-dropright.vue -->
162+
```
163+
164+
### Dropleft
165+
Turn your dropdown menu into a drop-right menu by setting the `dropleft` prop.
166+
167+
```html
168+
<div>
169+
<b-dropdown id="ddown-dropleft" dropleft text="Drop-Left" variant="primary" class="m-2">
170+
<b-dropdown-item href="#">Action</b-dropdown-item>
171+
<b-dropdown-item href="#">Another action</b-dropdown-item>
172+
<b-dropdown-item href="#">Something else here</b-dropdown-item>
173+
</b-dropdown>
174+
</div>
175+
176+
<!-- dropdown-dropleft.vue -->
177+
```
178+
149179
### Auto "flipping"
150180
By default, dropdowns may flip to the top, or to the bottom, based on
151181
their current position in the viewport. To disable this auto-flip feature, set

src/components/dropdown/dropdown.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,29 @@ export default {
124124
},
125125
computed: {
126126
dropdownClasses () {
127-
let position = ''
128127
// Position `static` is needed to allow menu to "breakout" of the scrollParent boundaries
129128
// when boundary is anything other than `scrollParent`
130129
// See https://github.com/twbs/bootstrap/issues/24251#issuecomment-341413786
131-
if (this.boundary !== 'scrollParent' || !this.boundary) {
132-
position = 'position-static'
130+
const positionStatic = this.boundary !== 'scrollParent' || !this.boundary
131+
132+
let direction = ''
133+
if (this.dropup) {
134+
direction = 'dropup'
135+
} else if (this.dropright) {
136+
direction = 'dropright'
137+
} else if (this.dropleft) {
138+
direction = 'dropleft'
133139
}
140+
134141
return [
135142
'btn-group',
136143
'b-dropdown',
137144
'dropdown',
138-
this.dropup ? 'dropup' : '',
139-
this.visible ? 'show' : '',
140-
position
145+
direction,
146+
{
147+
show: this.visible,
148+
'position-static': positionStatic
149+
}
141150
]
142151
},
143152
menuClasses () {

src/components/dropdown/fixtures/dropdown.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,28 @@
9797
<b-dropdown-item href="#">Action</b-dropdown-item>
9898
<b-dropdown-item href="#">Another action</b-dropdown-item>
9999
</b-dropdown>
100+
101+
<br><br>
102+
103+
<b-dropdown ref="dd_11"
104+
text="Drop-Right"
105+
dropright
106+
variant="primary"
107+
class="m-md-2">
108+
<b-dropdown-item href="#">Action</b-dropdown-item>
109+
<b-dropdown-item href="#">Another action</b-dropdown-item>
110+
<b-dropdown-item href="#">Something else here</b-dropdown-item>
111+
</b-dropdown>
112+
113+
<br><br>
114+
115+
<b-dropdown ref="dd_12"
116+
text="Drop-Left"
117+
dropleft
118+
variant="primary"
119+
class="m-md-2">
120+
<b-dropdown-item href="#">Action</b-dropdown-item>
121+
<b-dropdown-item href="#">Another action</b-dropdown-item>
122+
<b-dropdown-item href="#">Something else here</b-dropdown-item>
123+
</b-dropdown>
100124
</div>

src/mixins/dropdown.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ export default {
4646
type: Boolean,
4747
default: false
4848
},
49+
dropright: {
50+
// place right if possible
51+
type: Boolean,
52+
default: false
53+
},
54+
dropleft: {
55+
// place left if possible
56+
type: Boolean,
57+
default: false
58+
},
4959
right: {
5060
// Right align menu (default is left align)
5161
type: Boolean,
@@ -198,14 +208,13 @@ export default {
198208
},
199209
getPopperConfig /* istanbul ignore next: can't test popper in JSDOM */ () {
200210
let placement = AttachmentMap.BOTTOM
201-
if (this.dropup && this.right) {
202-
// dropup + right
203-
placement = AttachmentMap.TOPEND
204-
} else if (this.dropup) {
205-
// dropup + left
206-
placement = AttachmentMap.TOP
211+
if (this.dropup) {
212+
placement = this.right ? AttachmentMap.TOPEND : AttachmentMap.TOP
213+
} else if (this.dropright) {
214+
placement = AttachmentMap.RIGHT
215+
} else if (this.dropleft) {
216+
placement = AttachmentMap.LEFT
207217
} else if (this.right) {
208-
// dropdown + right
209218
placement = AttachmentMap.BOTTOMEND
210219
}
211220
const popperConfig = {

0 commit comments

Comments
 (0)