0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

fix: style directive not reactive in {#each} loop (#7140)

This commit is contained in:
Tan Li Hau 2022-01-15 01:16:34 +08:00 committed by GitHub
parent 815bc7ef6e
commit dc06ea916e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 7 deletions

View File

@ -199,7 +199,7 @@ export default class ElementWrapper extends Wrapper {
}
// add directive and handler dependencies
[node.animation, node.outro, ...node.actions, ...node.classes].forEach(directive => {
[node.animation, node.outro, ...node.actions, ...node.classes, ...node.styles].forEach(directive => {
if (directive && directive.expression) {
block.add_dependencies(directive.expression.dependencies);
}

View File

@ -1,18 +1,25 @@
export default {
html: `
<p style="color: red;"></p>
<p style="color: red;"></p>
`,
test({ assert, component, target, window }) {
const p = target.querySelector('p');
const [p1, p2] = target.querySelectorAll('p');
let styles = window.getComputedStyle(p);
assert.equal(styles.color, 'red');
assert.equal(window.getComputedStyle(p1).color, 'red');
assert.equal(window.getComputedStyle(p2).color, 'red');
component.color = 'blue';
assert.htmlEqual(target.innerHTML, '<p style="color: blue;"></p>');
assert.htmlEqual(
target.innerHTML,
`
<p style="color: blue;"></p>
<p style="color: blue;"></p>
`
);
styles = window.getComputedStyle(p);
assert.equal(styles.color, 'blue');
assert.equal(window.getComputedStyle(p1).color, 'blue');
assert.equal(window.getComputedStyle(p2).color, 'blue');
}
};

View File

@ -3,3 +3,7 @@
</script>
<p style:color />
{#each [1] as _}
<p style:color />
{/each}