Skip to content

Commit bd64f07

Browse files
authored
fix: take custom attribute name into account when reflecting property (#9140)
fixes #9134
1 parent 3c9e661 commit bd64f07

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

.changeset/tame-tomatoes-warn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: take custom attribute name into account when reflecting property

packages/svelte/src/runtime/internal/Component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ if (typeof HTMLElement === 'function') {
283283
'toAttribute'
284284
);
285285
if (attribute_value == null) {
286-
this.removeAttribute(key);
286+
this.removeAttribute(this.$$p_d[key].attribute || key);
287287
} else {
288288
this.setAttribute(this.$$p_d[key].attribute || key, attribute_value);
289289
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<svelte:options
2+
customElement={{
3+
tag: 'custom-element',
4+
props: {
5+
expanded: { reflect: true, type: 'Boolean', attribute: 'aria-expanded' }
6+
}
7+
}}
8+
/>
9+
10+
<script>
11+
export let expanded = false;
12+
</script>
13+
14+
<div>
15+
<button on:click={() => (expanded = !expanded)}>Toggle</button>
16+
<div class:hidden={!expanded}>Hidden Text</div>
17+
</div>
18+
19+
<style>
20+
.hidden {
21+
display: none;
22+
}
23+
</style>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as assert from 'assert.js';
2+
import { tick } from 'svelte';
3+
import './main.svelte';
4+
5+
export default async function (target) {
6+
const element = document.createElement('custom-element');
7+
target.appendChild(element);
8+
await tick();
9+
10+
const el = target.querySelector('custom-element');
11+
el.shadowRoot.querySelector('button').click();
12+
await tick();
13+
14+
assert.equal(el.getAttribute('aria-expanded'), '');
15+
el.shadowRoot.querySelector('button').click();
16+
await tick();
17+
18+
assert.equal(el.getAttribute('aria-expanded'), null);
19+
}

0 commit comments

Comments
 (0)