Skip to content

Commit c915cf4

Browse files
committed
support boolean props in the form of a="a"
1 parent c748bb3 commit c915cf4

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/compiler/compile-props.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,13 @@ function makePropsLinkFn (props) {
197197
initProp(vm, prop, value)
198198
} else {
199199
// string literal, but we need to cater for
200-
// Boolean props with no value
201-
value = options.type === Boolean && raw === ''
202-
? true
200+
// Boolean props with no value, or with same
201+
// literal value (e.g. disabled="disabled")
202+
// see https://github.com/vuejs/vue-loader/issues/182
203+
value = (
204+
options.type === Boolean &&
205+
(raw === '' || raw === hyphenate(prop.name))
206+
) ? true
203207
: raw
204208
initProp(vm, prop, value)
205209
}

test/unit/specs/directives/internal/prop_spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,18 +626,20 @@ describe('prop', function () {
626626
it('treat boolean props properly', function () {
627627
var vm = new Vue({
628628
el: el,
629-
template: '<comp v-ref:child prop-a></comp>',
629+
template: '<comp v-ref:child prop-a prop-b="prop-b"></comp>',
630630
components: {
631631
comp: {
632632
props: {
633633
propA: Boolean,
634-
propB: Boolean
634+
propB: Boolean,
635+
propC: Boolean
635636
}
636637
}
637638
}
638639
})
639640
expect(vm.$refs.child.propA).toBe(true)
640-
expect(vm.$refs.child.propB).toBe(false)
641+
expect(vm.$refs.child.propB).toBe(true)
642+
expect(vm.$refs.child.propC).toBe(false)
641643
})
642644

643645
it('detect possible camelCase prop usage', function () {

0 commit comments

Comments
 (0)