File tree Expand file tree Collapse file tree 3 files changed +40
-5
lines changed Expand file tree Collapse file tree 3 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ export const BNavbarToggle = /*#__PURE__*/ Vue.extend({
23
23
target : {
24
24
type : String ,
25
25
required : true
26
+ } ,
27
+ disabled : {
28
+ type : Boolean ,
29
+ default : false
26
30
}
27
31
} ,
28
32
data ( ) {
@@ -36,8 +40,10 @@ export const BNavbarToggle = /*#__PURE__*/ Vue.extend({
36
40
} ,
37
41
methods : {
38
42
onClick ( evt ) {
39
- // Emit courtesy `click` event
40
- this . $emit ( 'click' , evt )
43
+ if ( ! this . disabled ) {
44
+ // Emit courtesy `click` event
45
+ this . $emit ( 'click' , evt )
46
+ }
41
47
} ,
42
48
handleStateEvt ( id , state ) {
43
49
// We listen for state events so that we can pass the
@@ -48,17 +54,23 @@ export const BNavbarToggle = /*#__PURE__*/ Vue.extend({
48
54
}
49
55
} ,
50
56
render ( h ) {
51
- const expanded = this . toggleState
57
+ const { disabled } = this
58
+
52
59
return h (
53
60
'button' ,
54
61
{
55
62
staticClass : CLASS_NAME ,
63
+ class : { disabled } ,
56
64
directives : [ { name : 'BToggle' , value : this . target } ] ,
57
- attrs : { type : 'button' , 'aria-label' : this . label } ,
65
+ attrs : {
66
+ type : 'button' ,
67
+ disabled,
68
+ 'aria-label' : this . label
69
+ } ,
58
70
on : { click : this . onClick }
59
71
} ,
60
72
[
61
- this . normalizeSlot ( 'default' , { expanded } ) ||
73
+ this . normalizeSlot ( 'default' , { expanded : this . toggleState } ) ||
62
74
h ( 'span' , { staticClass : `${ CLASS_NAME } -icon` } )
63
75
]
64
76
)
Original file line number Diff line number Diff line change @@ -159,4 +159,22 @@ describe('navbar-toggle', () => {
159
159
160
160
wrapper . destroy ( )
161
161
} )
162
+
163
+ it ( 'disabled prop works' , async ( ) => {
164
+ const wrapper = mount ( BNavbarToggle , {
165
+ propsData : {
166
+ target : 'target-9' ,
167
+ disabled : true
168
+ }
169
+ } )
170
+
171
+ expect ( wrapper . emitted ( 'click' ) ) . not . toBeDefined ( )
172
+ expect ( wrapper . element . hasAttribute ( 'disabled' ) ) . toBe ( true )
173
+ expect ( wrapper . classes ( ) ) . toContain ( 'disabled' )
174
+
175
+ await wrapper . trigger ( 'click' )
176
+ expect ( wrapper . emitted ( 'click' ) ) . not . toBeDefined ( )
177
+
178
+ wrapper . destroy ( )
179
+ } )
162
180
} )
Original file line number Diff line number Diff line change 78
78
"prop" : " label" ,
79
79
"settings" : true ,
80
80
"description" : " String to place in the toggle's 'aria-label' attribute"
81
+ },
82
+ {
83
+ "prop" : " disabled" ,
84
+ "version" : " 2.15.0" ,
85
+ "description" : " When `true`, disables the navbar toggle button, and adds class `disabled` to the button"
81
86
}
82
87
],
83
88
"events" : [
You can’t perform that action at this time.
0 commit comments