+25
-12
lines changedFilter options
+25
-12
lines changed Original file line number Diff line number Diff line change
@@ -14,7 +14,8 @@ import {
14
14
getXlinkProp,
15
15
isBooleanAttr,
16
16
isEnumeratedAttr,
17
-
isFalsyAttrValue
17
+
isFalsyAttrValue,
18
+
convertEnumeratedValue
18
19
} from 'web/util/index'
19
20
20
21
function updateAttrs (oldVnode: VNodeWithData, vnode: VNodeWithData) {
@@ -75,7 +76,7 @@ function setAttr (el: Element, key: string, value: any) {
75
76
el.setAttribute(key, value)
76
77
}
77
78
} else if (isEnumeratedAttr(key)) {
78
-
el.setAttribute(key, isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true')
79
+
el.setAttribute(key, convertEnumeratedValue(key, value))
79
80
} else if (isXlink(key)) {
80
81
if (isFalsyAttrValue(value)) {
81
82
el.removeAttributeNS(xlinkNS, getXlinkProp(key))
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@ import {
11
11
import {
12
12
isBooleanAttr,
13
13
isEnumeratedAttr,
14
-
isFalsyAttrValue
14
+
isFalsyAttrValue,
15
+
convertEnumeratedValue
15
16
} from 'web/util/attrs'
16
17
17
18
import { isSSRUnsafeAttr } from 'web/server/util'
@@ -54,7 +55,7 @@ export function renderAttr (key: string, value: string): string {
54
55
return ` ${key}="${key}"`
55
56
}
56
57
} else if (isEnumeratedAttr(key)) {
57
-
return ` ${key}="${isFalsyAttrValue(value) || value === 'false' ? 'false' : 'true'}"`
58
+
return ` ${key}="${escape(convertEnumeratedValue(key, value))}"`
58
59
} else if (!isFalsyAttrValue(value)) {
59
60
return ` ${key}="${escape(String(value))}"`
60
61
}
Original file line number Diff line number Diff line change
@@ -19,6 +19,17 @@ export const mustUseProp = (tag: string, type: ?string, attr: string): boolean =
19
19
20
20
export const isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck')
21
21
22
+
const isValidContentEditableValue = makeMap('events,caret,typing,plaintext-only')
23
+
24
+
export const convertEnumeratedValue = (key: string, value: any) => {
25
+
return isFalsyAttrValue(value) || value === 'false'
26
+
? 'false'
27
+
// allow arbitrary string value for contenteditable
28
+
: key === 'contenteditable' && isValidContentEditableValue(value)
29
+
? value
30
+
: 'true'
31
+
}
32
+
22
33
export const isBooleanAttr = makeMap(
23
34
'allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,' +
24
35
'default,defaultchecked,defaultmuted,defaultselected,defer,disabled,' +
Original file line number Diff line number Diff line change
@@ -69,25 +69,25 @@ describe('Directive v-bind', () => {
69
69
70
70
it('enumerated attr', done => {
71
71
const vm = new Vue({
72
-
template: '<div><span :draggable="foo">hello</span></div>',
72
+
template: '<div><span :contenteditable="foo">hello</span></div>',
73
73
data: { foo: true }
74
74
}).$mount()
75
-
expect(vm.$el.firstChild.getAttribute('draggable')).toBe('true')
76
-
vm.foo = 'again'
75
+
expect(vm.$el.firstChild.getAttribute('contenteditable')).toBe('true')
76
+
vm.foo = 'plaintext-only' // allow special values
77
77
waitForUpdate(() => {
78
-
expect(vm.$el.firstChild.getAttribute('draggable')).toBe('true')
78
+
expect(vm.$el.firstChild.getAttribute('contenteditable')).toBe('plaintext-only')
79
79
vm.foo = null
80
80
}).then(() => {
81
-
expect(vm.$el.firstChild.getAttribute('draggable')).toBe('false')
81
+
expect(vm.$el.firstChild.getAttribute('contenteditable')).toBe('false')
82
82
vm.foo = ''
83
83
}).then(() => {
84
-
expect(vm.$el.firstChild.getAttribute('draggable')).toBe('true')
84
+
expect(vm.$el.firstChild.getAttribute('contenteditable')).toBe('true')
85
85
vm.foo = false
86
86
}).then(() => {
87
-
expect(vm.$el.firstChild.getAttribute('draggable')).toBe('false')
87
+
expect(vm.$el.firstChild.getAttribute('contenteditable')).toBe('false')
88
88
vm.foo = 'false'
89
89
}).then(() => {
90
-
expect(vm.$el.firstChild.getAttribute('draggable')).toBe('false')
90
+
expect(vm.$el.firstChild.getAttribute('contenteditable')).toBe('false')
91
91
}).then(done)
92
92
})
93
93
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4