Skip to content

Commit 8184a95

Browse files
committed
respect boolean prop default value (fix #1079)
1 parent 696ce26 commit 8184a95

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/compiler/compile-props.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,12 @@ function makePropsLinkFn (props) {
155155
*/
156156

157157
function getDefault (options) {
158-
// absent boolean value
159-
if (options.type === Boolean) {
160-
return false
161-
}
162158
// no default, return undefined
163159
if (!options.hasOwnProperty('default')) {
164-
return
160+
// absent boolean value defaults to false
161+
return options.type === Boolean
162+
? false
163+
: undefined
165164
}
166165
var def = options.default
167166
// warn against non-factory defaults for Object & Array

test/unit/specs/directives/prop_spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,25 @@ if (_.inBrowser) {
447447
}))
448448
})
449449

450+
it('should respect default value of a Boolean prop', function () {
451+
var vm = new Vue({
452+
el: el,
453+
template: '<test></test>',
454+
components: {
455+
test: {
456+
props: {
457+
prop: {
458+
type: Boolean,
459+
default: true
460+
}
461+
},
462+
template: '{{prop}}'
463+
}
464+
}
465+
})
466+
expect(vm.$el.textContent).toBe('true')
467+
})
468+
450469
it('should initialize with default value when not provided & has default data', function (done) {
451470
var vm = new Vue({
452471
el: el,

0 commit comments

Comments
 (0)