+17
-0
lines changedFilter options
+17
-0
lines changed Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ describe('runtime-dom: props patching', () => {
9
9
// prop with string value should be set to empty string on null values
10
10
patchProp(el, 'id', null, null)
11
11
expect(el.id).toBe('')
12
+
expect(el.getAttribute('id')).toBe(null)
12
13
})
13
14
14
15
test('value', () => {
@@ -17,12 +18,25 @@ describe('runtime-dom: props patching', () => {
17
18
expect(el.value).toBe('foo')
18
19
patchProp(el, 'value', null, null)
19
20
expect(el.value).toBe('')
21
+
expect(el.getAttribute('value')).toBe(null)
20
22
const obj = {}
21
23
patchProp(el, 'value', null, obj)
22
24
expect(el.value).toBe(obj.toString())
23
25
expect((el as any)._value).toBe(obj)
24
26
})
25
27
28
+
// For <input type="text">, setting el.value won't create a `value` attribute
29
+
// so we need to add tests for other elements
30
+
test('value for non-text input', () => {
31
+
const el = document.createElement('option')
32
+
patchProp(el, 'value', null, 'foo')
33
+
expect(el.value).toBe('foo')
34
+
patchProp(el, 'value', null, null)
35
+
expect(el.value).toBe('')
36
+
// #3475
37
+
expect(el.getAttribute('value')).toBe(null)
38
+
})
39
+
26
40
test('boolean prop', () => {
27
41
const el = document.createElement('select')
28
42
patchProp(el, 'multiple', null, '')
Original file line number Diff line number Diff line change
@@ -33,6 +33,9 @@ export function patchDOMProp(
33
33
if (el.value !== newValue) {
34
34
el.value = newValue
35
35
}
36
+
if (value == null) {
37
+
el.removeAttribute('value')
38
+
}
36
39
return
37
40
}
38
41
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