@@ -2,6 +2,7 @@ import Vue from '../../utils/vue'
22import { arrayIncludes } from '../../utils/array'
33import { getComponentConfig } from '../../utils/config'
44import { htmlOrText } from '../../utils/html'
5+ import { toString } from '../../utils/string'
56import dropdownMixin from '../../mixins/dropdown'
67import idMixin from '../../mixins/id'
78import normalizeSlotMixin from '../../mixins/normalize-slot'
@@ -15,14 +16,12 @@ const NAME = 'BDropdown'
1516
1617export const props = {
1718 text : {
18- // Button label
19- type : String ,
20- default : ''
19+ type : String
20+ // default: null
2121 } ,
2222 html : {
23- // Button label
2423 type : String
25- // default: undefined
24+ // default: null
2625 } ,
2726 variant : {
2827 type : String ,
@@ -141,11 +140,12 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
141140 }
142141 } ,
143142 render ( h ) {
144- const { variant, size, block, disabled, split, role } = this
143+ const { visible , variant, size, block, disabled, split, role, hide , toggle } = this
145144 const commonProps = { variant, size, block, disabled }
146145
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 )
149149 ? { }
150150 : htmlOrText ( this . html , this . text )
151151
@@ -154,8 +154,9 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
154154 const { splitTo, splitHref, splitButtonType } = this
155155 const btnProps = {
156156 ...commonProps ,
157- variant : this . splitVariant || this . variant
157+ variant : this . splitVariant || variant
158158 }
159+
159160 // We add these as needed due to <router-link> issues with
160161 // defined property with `undefined`/`null` values
161162 if ( splitTo ) {
@@ -165,18 +166,23 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
165166 } else if ( splitButtonType ) {
166167 btnProps . type = splitButtonType
167168 }
169+
168170 $split = h (
169171 BButton ,
170172 {
171173 class : this . splitClass ,
172174 attrs : { id : this . safeId ( '_BV_button_' ) } ,
173175 props : btnProps ,
174- domProps : buttonContentProps ,
176+ domProps : buttonContentDomProps ,
175177 on : { click : this . onSplitClick } ,
176178 ref : 'button'
177179 } ,
178- [ $buttonContent ]
180+ $buttonChildren
179181 )
182+
183+ // Overwrite button content for the toggle when in `split` mode
184+ $buttonChildren = [ h ( 'span' , { class : [ 'sr-only' ] } , [ this . toggleText ] ) ]
185+ buttonContentDomProps = { }
180186 }
181187
182188 const $toggle = h (
@@ -187,22 +193,22 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
187193 attrs : {
188194 id : this . safeId ( '_BV_toggle_' ) ,
189195 'aria-haspopup' : 'true' ,
190- 'aria-expanded' : this . visible ? 'true' : 'false'
196+ 'aria-expanded' : toString ( visible )
191197 } ,
192198 props : {
193199 ...commonProps ,
194200 tag : this . toggleTag ,
195201 block : block && ! split
196202 } ,
197- domProps : split ? { } : buttonContentProps ,
203+ domProps : buttonContentDomProps ,
198204 on : {
199205 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
202208 } ,
203209 ref : 'toggle'
204210 } ,
205- [ split ? h ( 'span' , { class : [ 'sr-only' ] } , [ this . toggleText ] ) : $buttonContent ]
211+ $buttonChildren
206212 )
207213
208214 const $menu = h (
@@ -220,7 +226,7 @@ export const BDropdown = /*#__PURE__*/ Vue.extend({
220226 } ,
221227 ref : 'menu'
222228 } ,
223- ! this . lazy || this . visible ? this . normalizeSlot ( 'default' , { hide : this . hide } ) : [ h ( ) ]
229+ [ ! this . lazy || visible ? this . normalizeSlot ( 'default' , { hide } ) : h ( ) ]
224230 )
225231
226232 return h (
0 commit comments