Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test that attributes added in custom elements aren't removed by the framework #2047

Open
tbroyer opened this issue Jan 26, 2023 · 0 comments

Comments

@tbroyer
Copy link

tbroyer commented Jan 26, 2023

It's been brought to my attention that Svelte removes attributes on elements when it "claims" them, so a custom element that adds itself some attributes will have them removed by Svelte at some point. This would be the case for example for ARIA attributes or custom attributes added to emulate custom states for styling, pending global support for ElementInternals and CustomStateSet (e.g. using https://github.com/calebdwilliams/element-internals-polyfill).

To reproduce, paste the following code in the Svelte REPL at https://svelte.dev/repl, then inspect the rendered DOM:

<script>
	let name = 'world';
	
	class FooBarElement extends HTMLElement {
		constructor() {
			super();
		}
		connectedCallback() {
			this.ariaLabel = "foo";
                        this.setAttribute("state--foo", "bar");
		}
	}
	customElements.define("foo-bar", FooBarElement)
</script>

<h1>Hello {name}!</h1>
<foo-bar></foo-bar>
@tbroyer tbroyer changed the title Add a test that attributes added in custom element constructor aren't removed by the framework Add a test that attributes added in custom elements aren't removed by the framework Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant