@@ -2,6 +2,7 @@ import Vue from '../../utils/vue'
2
2
import { arrayIncludes } from '../../utils/array'
3
3
import { getComponentConfig } from '../../utils/config'
4
4
import { htmlOrText } from '../../utils/html'
5
+ import { toString } from '../../utils/string'
5
6
import dropdownMixin from '../../mixins/dropdown'
6
7
import idMixin from '../../mixins/id'
7
8
import normalizeSlotMixin from '../../mixins/normalize-slot'
@@ -15,14 +16,12 @@ const NAME = 'BDropdown'
15
16
16
17
export const props = {
17
18
text : {
18
- // Button label
19
- type : String ,
20
- default : ''
19
+ type : String
20
+ // default: null
21
21
} ,
22
22
html : {
23
- // Button label
24
23
type : String
25
- // default: undefined
24
+ // default: null
26
25
} ,
27
26
variant : {
28
27
type : String ,
@@ -141,11 +140,12 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
141
140
}
142
141
} ,
143
142
render ( h ) {
144
- const { variant, size, block, disabled, split, role } = this
143
+ const { visible , variant, size, block, disabled, split, role, hide , toggle } = this
145
144
const commonProps = { variant, size, block, disabled }
146
145
147
- const $buttonContent = this . normalizeSlot ( 'button-content' )
148
- const buttonContentProps = this . hasNormalizedSlot ( 'button-content' )
146
+ const buttonContentSlotName = 'button-content'
147
+ let $buttonChildren = this . normalizeSlot ( buttonContentSlotName )
148
+ let buttonContentDomProps = this . hasNormalizedSlot ( buttonContentSlotName )
149
149
? { }
150
150
: htmlOrText ( this . html , this . text )
151
151
@@ -154,8 +154,9 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
154
154
const { splitTo, splitHref, splitButtonType } = this
155
155
const btnProps = {
156
156
...commonProps ,
157
- variant : this . splitVariant || this . variant
157
+ variant : this . splitVariant || variant
158
158
}
159
+
159
160
// We add these as needed due to <router-link> issues with
160
161
// defined property with `undefined`/`null` values
161
162
if ( splitTo ) {
@@ -165,18 +166,23 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
165
166
} else if ( splitButtonType ) {
166
167
btnProps . type = splitButtonType
167
168
}
169
+
168
170
$split = h (
169
171
BButton ,
170
172
{
171
173
class : this . splitClass ,
172
174
attrs : { id : this . safeId ( '_BV_button_' ) } ,
173
175
props : btnProps ,
174
- domProps : buttonContentProps ,
176
+ domProps : buttonContentDomProps ,
175
177
on : { click : this . onSplitClick } ,
176
178
ref : 'button'
177
179
} ,
178
- [ $buttonContent ]
180
+ $buttonChildren
179
181
)
182
+
183
+ // Overwrite button content for the toggle when in `split` mode
184
+ $buttonChildren = [ h ( 'span' , { class : [ 'sr-only' ] } , [ this . toggleText ] ) ]
185
+ buttonContentDomProps = { }
180
186
}
181
187
182
188
const $toggle = h (
@@ -187,22 +193,22 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
187
193
attrs : {
188
194
id : this . safeId ( '_BV_toggle_' ) ,
189
195
'aria-haspopup' : 'true' ,
190
- 'aria-expanded' : this . visible ? 'true' : 'false'
196
+ 'aria-expanded' : toString ( visible )
191
197
} ,
192
198
props : {
193
199
...commonProps ,
194
200
tag : this . toggleTag ,
195
201
block : block && ! split
196
202
} ,
197
- domProps : split ? { } : buttonContentProps ,
203
+ domProps : buttonContentDomProps ,
198
204
on : {
199
205
mousedown : this . onMousedown ,
200
- click : this . toggle ,
201
- keydown : this . toggle // Handle ENTER, SPACE and DOWN
206
+ click : toggle ,
207
+ keydown : toggle // Handle ENTER, SPACE and DOWN
202
208
} ,
203
209
ref : 'toggle'
204
210
} ,
205
- [ split ? h ( 'span' , { class : [ 'sr-only' ] } , [ this . toggleText ] ) : $buttonContent ]
211
+ $buttonChildren
206
212
)
207
213
208
214
const $menu = h (
@@ -220,7 +226,7 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
220
226
} ,
221
227
ref : 'menu'
222
228
} ,
223
- ! this . lazy || this . visible ? this . normalizeSlot ( 'default' , { hide : this . hide } ) : [ h ( ) ]
229
+ [ ! this . lazy || visible ? this . normalizeSlot ( 'default' , { hide } ) : h ( ) ]
224
230
)
225
231
226
232
return h (
0 commit comments