Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tame-tomatoes-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: take custom attribute name into account when reflecting property
2 changes: 1 addition & 1 deletion packages/svelte/src/runtime/internal/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ if (typeof HTMLElement === 'function') {
'toAttribute'
);
if (attribute_value == null) {
this.removeAttribute(key);
this.removeAttribute(this.$$p_d[key].attribute || key);
} else {
this.setAttribute(this.$$p_d[key].attribute || key, attribute_value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<svelte:options
customElement={{
tag: 'custom-element',
props: {
expanded: { reflect: true, type: 'Boolean', attribute: 'aria-expanded' }
}
}}
/>

<script>
export let expanded = false;
</script>

<div>
<button on:click={() => (expanded = !expanded)}>Toggle</button>
<div class:hidden={!expanded}>Hidden Text</div>
</div>

<style>
.hidden {
display: none;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as assert from 'assert.js';
import { tick } from 'svelte';
import './main.svelte';

export default async function (target) {
const element = document.createElement('custom-element');
target.appendChild(element);
await tick();

const el = target.querySelector('custom-element');
el.shadowRoot.querySelector('button').click();
await tick();

assert.equal(el.getAttribute('aria-expanded'), '');
el.shadowRoot.querySelector('button').click();
await tick();

assert.equal(el.getAttribute('aria-expanded'), null);
}