mirror of
https://github.com/sveltejs/svelte.git
synced 2024-11-30 00:46:29 +01:00
Remove an undefined attribute instead of setting it to "undefined" (string)
This commit is contained in:
parent
9eec6f8c72
commit
790f2b5313
@ -82,7 +82,8 @@ export function removeListener(node, event, handler) {
|
||||
}
|
||||
|
||||
export function setAttribute(node, attribute, value) {
|
||||
node.setAttribute(attribute, value);
|
||||
if (value === undefined) removeAttribute(node, attribute);
|
||||
else node.setAttribute(attribute, value);
|
||||
}
|
||||
|
||||
export function setAttributes(node, attributes) {
|
||||
@ -90,8 +91,7 @@ export function setAttributes(node, attributes) {
|
||||
if (key in node) {
|
||||
node[key] = attributes[key];
|
||||
} else {
|
||||
if (attributes[key] === undefined) removeAttribute(node, key);
|
||||
else setAttribute(node, key, attributes[key]);
|
||||
setAttribute(node, key, attributes[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -238,4 +238,4 @@ export function addResizeListener(element, fn) {
|
||||
element.removeChild(object);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
5
test/runtime/samples/set-undefined-attr/_config.js
Normal file
5
test/runtime/samples/set-undefined-attr/_config.js
Normal file
@ -0,0 +1,5 @@
|
||||
export default {
|
||||
'skip-ssr': true,
|
||||
|
||||
html: '<div></div>'
|
||||
};
|
14
test/runtime/samples/set-undefined-attr/main.html
Normal file
14
test/runtime/samples/set-undefined-attr/main.html
Normal file
@ -0,0 +1,14 @@
|
||||
<div {foo} {bar}></div>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data: () => ({
|
||||
foo: 1,
|
||||
bar: undefined
|
||||
}),
|
||||
|
||||
oncreate () {
|
||||
this.set({ foo: undefined });
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user