Skip to content

Commit 54fcb5c

Browse files
committed
fix v-bind for enumerated attributes that expect true and false values (fix #2407)
1 parent aa23fdc commit 54fcb5c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/directives/public/bind.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const disallowedInterpAttrRE = /^v-|^:|^@|^(?:is|transition|transition-mode|debo
1212
// these attributes should also set their corresponding properties
1313
// because they only affect the initial state of the element
1414
const attrWithPropsRE = /^(?:value|checked|selected|muted)$/
15+
// these attributes expect enumrated values of "true" or "false"
16+
// but are not boolean attributes
17+
const enumeratedAttrRE = /^(?:draggable|contenteditable|spellcheck)$/
1518

1619
// these attributes should set a hidden property for
1720
// binding v-model to object values
@@ -126,7 +129,9 @@ export default {
126129
return
127130
}
128131
// update attribute
129-
if (value != null && value !== false) {
132+
if (enumeratedAttrRE.test(attr)) {
133+
el.setAttribute(attr, value ? 'true' : 'false')
134+
} else if (value != null && value !== false) {
130135
if (attr === 'class') {
131136
// handle edge case #1960:
132137
// class interpolation should not overwrite Vue transition class

test/unit/specs/directives/public/bind_spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,14 @@ describe('v-bind', function () {
8080
dir.update('0 0 1500 1000')
8181
expect(dir.el.getAttribute('viewBox')).toBe('0 0 1500 1000')
8282
})
83+
84+
it('enumrated non-boolean attributes', function () {
85+
['draggable', 'contenteditable', 'spellcheck'].forEach(function (attr) {
86+
dir.arg = attr
87+
dir.update(true)
88+
expect(el.getAttribute(attr)).toBe('true')
89+
dir.update(false)
90+
expect(el.getAttribute(attr)).toBe('false')
91+
})
92+
})
8393
})

0 commit comments

Comments
 (0)