fix: take custom attribute name into account when reflecting property (#9140)

fixes #9134
pull/9144/head
Teo 1 year ago committed by GitHub
parent 3c9e661f4a
commit bd64f07e98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: take custom attribute name into account when reflecting property

@ -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);
}

@ -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>

@ -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);
}
Loading…
Cancel
Save