Skip to content

Commit ddc0103

Browse files
authored
feat(b-dropdown): pass optional scope to default slot
Allows the default slot to be optionally scoped, receiving the `hide()` method in the scope.
1 parent acda2e2 commit ddc0103

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/components/dropdown/dropdown.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Vue from '../../utils/vue'
22
import { stripTags } from '../../utils/html'
33
import { getComponentConfig } from '../../utils/config'
4+
import { HTMLElement } from '../../utils/safe-types'
45
import idMixin from '../../mixins/id'
56
import dropdownMixin from '../../mixins/dropdown'
67
import normalizeSlotMixin from '../../mixins/normalize-slot'
@@ -60,8 +61,8 @@ export const props = {
6061
},
6162
boundary: {
6263
// String: `scrollParent`, `window` or `viewport`
63-
// Object: HTML Element reference
64-
type: [String, Object],
64+
// HTMLElement: HTML Element reference
65+
type: [String, HTMLElement],
6566
default: 'scrollParent'
6667
}
6768
}
@@ -73,40 +74,33 @@ export default Vue.extend({
7374
props,
7475
computed: {
7576
dropdownClasses() {
76-
// Position `static` is needed to allow menu to "breakout" of the scrollParent boundaries
77-
// when boundary is anything other than `scrollParent`
78-
// See https://github.com/twbs/bootstrap/issues/24251#issuecomment-341413786
79-
const positionStatic = this.boundary !== 'scrollParent' || !this.boundary
80-
8177
return [
82-
'btn-group',
83-
'b-dropdown',
84-
'dropdown',
8578
this.directionClass,
8679
{
8780
show: this.visible,
88-
'position-static': positionStatic
81+
// Position `static` is needed to allow menu to "breakout" of the scrollParent boundaries
82+
// when boundary is anything other than `scrollParent`
83+
// See https://github.com/twbs/bootstrap/issues/24251#issuecomment-341413786
84+
'position-static': this.boundary !== 'scrollParent' || !this.boundary
8985
}
9086
]
9187
},
9288
menuClasses() {
9389
return [
94-
'dropdown-menu',
90+
this.menuClass,
9591
{
9692
'dropdown-menu-right': this.right,
9793
show: this.visible
98-
},
99-
this.menuClass
94+
}
10095
]
10196
},
10297
toggleClasses() {
10398
return [
104-
'dropdown-toggle',
99+
this.toggleClass,
105100
{
106101
'dropdown-toggle-split': this.split,
107102
'dropdown-toggle-no-caret': this.noCaret && !this.split
108-
},
109-
this.toggleClass
103+
}
110104
]
111105
}
112106
},
@@ -149,6 +143,7 @@ export default Vue.extend({
149143
BButton,
150144
{
151145
ref: 'toggle',
146+
staticClass: 'dropdown-toggle',
152147
class: this.toggleClasses,
153148
props: {
154149
variant: this.variant,
@@ -172,6 +167,7 @@ export default Vue.extend({
172167
'ul',
173168
{
174169
ref: 'menu',
170+
staticClass: 'dropdown-menu',
175171
class: this.menuClasses,
176172
attrs: {
177173
role: this.role,
@@ -183,12 +179,16 @@ export default Vue.extend({
183179
keydown: this.onKeydown // tab, up, down, esc
184180
}
185181
},
186-
this.normalizeSlot('default')
182+
this.normalizeSlot('default', { hide: this.hide })
183+
)
184+
return h(
185+
'div',
186+
{
187+
staticClass: 'dropdown btn-group b-dropdown',
188+
class: this.dropdownClasses,
189+
attrs: { id: this.safeId() }
190+
},
191+
[split, toggle, menu]
187192
)
188-
return h('div', { attrs: { id: this.safeId() }, class: this.dropdownClasses }, [
189-
split,
190-
toggle,
191-
menu
192-
])
193193
}
194194
})

0 commit comments

Comments
 (0)