Skip to content

Commit

Permalink
[fix] always use set_attributes for attribute of <svelte:element> (
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama authored and himanshiLt committed Jun 24, 2022
1 parent 509a7bd commit 38cb5b9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ export default class ElementWrapper extends Wrapper {
}
});

if (this.node.attributes.some(attr => attr.is_spread)) {
if (this.node.attributes.some(attr => attr.is_spread) || this.node.is_dynamic_element) {
this.add_spread_attributes(block);
return;
}
Expand Down
15 changes: 15 additions & 0 deletions test/runtime/samples/dynamic-element-attribute-boolean/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
props: {
disabled: false
},
html: '<button>Click me</button>',

test({ assert, component, target }) {
const button = target.querySelector('button');
assert.equal(button.disabled, false);

component.disabled = true;
assert.htmlEqual(target.innerHTML, '<button disabled>Click me</button>');
assert.equal(button.disabled, true);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let disabled = false;
</script>

<svelte:element {disabled} this="button">Click me</svelte:element>
23 changes: 23 additions & 0 deletions test/runtime/samples/dynamic-element-attribute-spread/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default {
props: {
props: {
disabled: true,
type: 'button',
'data-named': 'foo'
}
},
html: '<button disabled type="button" data-named="foo">Click me</button>',

test({ assert, component, target }) {
const button = target.querySelector('button');
assert.equal(button.disabled, true);
assert.equal(button.type, 'button');
assert.equal(button.dataset.named, 'foo');

component.props = { type: 'submit' };
assert.htmlEqual(target.innerHTML, '<button type="submit">Click me</button>');
assert.equal(button.disabled, false);
assert.equal(button.type, 'submit');
assert.equal(button.dataset.named, undefined);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
export let props = {
disabled: false,
type: 'button',
'data-named': 'foo'
};
</script>

<svelte:element this="button" {...props}>Click me</svelte:element>

0 comments on commit 38cb5b9

Please sign in to comment.