Skip to content

Commit 69fc8f7

Browse files
authored
Merge branch 'dev' into tmorehouse/table-multi-sort
2 parents f9133a9 + 30029e3 commit 69fc8f7

File tree

4 files changed

+101
-8
lines changed

4 files changed

+101
-8
lines changed

src/components/dropdown/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,58 @@ split button its own variant via the `split-variant` prop.
308308
<!-- b-dropdown-split-variant.vue -->
309309
```
310310

311+
### Block level dropdowns
312+
313+
By default dropdowns act like buttons and are displayed inline. To create block level dropdowns
314+
(that span to the full width of a parent) set the `block` prop. Both, regular and split button
315+
dropdowns are supported.
316+
317+
```html
318+
<div>
319+
<b-dropdown text="Block Level Dropdown" block variant="primary" class="m-2">
320+
<b-dropdown-item href="#">Action</b-dropdown-item>
321+
<b-dropdown-item href="#">Another action</b-dropdown-item>
322+
<b-dropdown-item href="#">Something else here</b-dropdown-item>
323+
</b-dropdown>
324+
325+
<b-dropdown
326+
text="Block Level Split Dropdown"
327+
block
328+
split
329+
split-variant="outline-primary"
330+
variant="primary"
331+
class="m-2"
332+
>
333+
<b-dropdown-item href="#">Action</b-dropdown-item>
334+
<b-dropdown-item href="#">Another action</b-dropdown-item>
335+
<b-dropdown-item href="#">Something else here...</b-dropdown-item>
336+
</b-dropdown>
337+
</div>
338+
339+
<!-- b-dropdown-block.vue -->
340+
```
341+
342+
If you want the dropdown menu to span to the full width of the parent container too, add the `w-100`
343+
utility class to the `menu-class` prop.
344+
345+
```html
346+
<div>
347+
<b-dropdown
348+
text="Block Level Dropdown Menu"
349+
block
350+
variant="primary"
351+
class="m-2"
352+
menu-class="w-100"
353+
>
354+
<b-dropdown-item href="#">Action</b-dropdown-item>
355+
<b-dropdown-item href="#">Another action</b-dropdown-item>
356+
<b-dropdown-item href="#">Something else here</b-dropdown-item>
357+
</b-dropdown>
358+
</div>
359+
360+
<!-- b-dropdown-block-menu.vue -->
361+
```
362+
311363
### Dropdown sub-component color variants
312364

313365
Many of the supported dropdown [sub-components](#dropdown-supported-sub-components) provide a

src/components/dropdown/dropdown.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export const props = {
2424
type: String,
2525
default: () => getComponentConfig(NAME, 'variant')
2626
},
27+
block: {
28+
type: Boolean,
29+
default: false
30+
},
2731
menuClass: {
2832
type: [String, Array],
2933
default: null
@@ -84,9 +88,16 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
8488
this.directionClass,
8589
{
8690
show: this.visible,
87-
// Position `static` is needed to allow menu to "breakout" of the scrollParent boundaries
88-
// when boundary is anything other than `scrollParent`
89-
// See https://github.com/twbs/bootstrap/issues/24251#issuecomment-341413786
91+
// The 'btn-group' class is required in `split` mode for button alignment
92+
// It needs also to be applied when `block` is disabled to allow multiple
93+
// dropdowns to be aligned one line
94+
'btn-group': this.split || !this.block,
95+
// When `block` is enabled and we are in `split` mode the 'd-flex' class
96+
// needs to be applied to allow the buttons to stretch to full width
97+
'd-flex': this.block && this.split,
98+
// Position `static` is needed to allow menu to "breakout" of the `scrollParent`
99+
// boundaries when boundary is anything other than `scrollParent`
100+
// See: https://github.com/twbs/bootstrap/issues/24251#issuecomment-341413786
90101
'position-static': this.boundary !== 'scrollParent' || !this.boundary
91102
}
92103
]
@@ -115,9 +126,10 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
115126
const buttonContent = this.normalizeSlot('button-content') || this.html || stripTags(this.text)
116127
if (this.split) {
117128
const btnProps = {
118-
disabled: this.disabled,
119129
variant: this.splitVariant || this.variant,
120-
size: this.size
130+
size: this.size,
131+
block: this.block,
132+
disabled: this.disabled
121133
}
122134
// We add these as needed due to router-link issues with defined property with undefined/null values
123135
if (this.splitTo) {
@@ -149,10 +161,11 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
149161
staticClass: 'dropdown-toggle',
150162
class: this.toggleClasses,
151163
props: {
164+
tag: this.toggleTag,
152165
variant: this.variant,
153166
size: this.size,
154-
disabled: this.disabled,
155-
tag: this.toggleTag
167+
block: this.block && !this.split,
168+
disabled: this.disabled
156169
},
157170
attrs: {
158171
id: this.safeId('_BV_toggle_'),
@@ -186,7 +199,7 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
186199
return h(
187200
'div',
188201
{
189-
staticClass: 'dropdown btn-group b-dropdown',
202+
staticClass: 'dropdown b-dropdown',
190203
class: this.dropdownClasses,
191204
attrs: { id: this.safeId() }
192205
},

src/components/dropdown/dropdown.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,30 @@ describe('dropdown', () => {
247247
wrapper.destroy()
248248
})
249249

250+
it('should not have "btn-group" class when block is true', async () => {
251+
const wrapper = mount(BDropdown, {
252+
attachToDocument: true,
253+
propsData: {
254+
block: true
255+
}
256+
})
257+
expect(wrapper.classes()).not.toContain('btn-group')
258+
wrapper.destroy()
259+
})
260+
261+
it('should have "btn-group" and "d-flex" classes when block and split are true', async () => {
262+
const wrapper = mount(BDropdown, {
263+
attachToDocument: true,
264+
propsData: {
265+
block: true,
266+
split: true
267+
}
268+
})
269+
expect(wrapper.classes()).toContain('btn-group')
270+
expect(wrapper.classes()).toContain('d-flex')
271+
wrapper.destroy()
272+
})
273+
250274
it('should have "dropdown-toggle-no-caret" class when no-caret is true', async () => {
251275
const wrapper = mount(BDropdown, {
252276
attachToDocument: true,

src/components/dropdown/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
"prop": "toggleClass",
6868
"description": "CSS class (or classes) to add to the toggle button"
6969
},
70+
{
71+
"prop": "block",
72+
"description": "Renders a 100% width toggle button (expands to the width of it's parent container)"
73+
},
7074
{
7175
"prop": "noCaret",
7276
"description": "Hide the caret indicator on the toggle button"

0 commit comments

Comments
 (0)