You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This should help everyone who has special needs and use cases around custom elements. Since Svelte components are wrapped and only run on connectedCallback, it makes sense to expose the custom element class for modification before that.
- fixes#8954 - use extend to attach the function manually and save possible values to a prop
- closes#8473 / closes#4168 - use extend to set the proper static attribute and then call attachInternals in the constructor
closes#8472 - use extend to attach anything custom you need
closes#3091 - pass `this` to a prop of your choice and use it inside your component
<svelte:optionscustomElement={{
tag: 'custom-element',
extend: (customElementConstructor) => {
// Extend the class so we can let it participate in HTML formsreturnclassextendscustomElementConstructor {
static formAssociated =true;
constructor() {
super();
this.attachedInternals=this.attachInternals();
}
};
}
}}
/>
<script>
exportlet attachedInternals;// ...functioncheck() {attachedInternals.checkValidity(); }
</script>
...
Describe the problem
Currently, there is no way to add a static tag to Svelte Web Components.
This poses a problem when you are trying to make custom elements with form interoperability using ElementInternals.
This could easily be fixed by adding logic in the constructor template to add the static value and internals setup logic.
https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals#examples
Describe the proposed solution
I propose adding a new setting to the
<svelte:options />
tag;elementInternals="true"
.We could then add the static field necessary and have a separate function for adding internals in the lifecycle hook.
Alternatives considered
I thought it would be possible to adjust the constructor of the element's class. This would not work as we cannot redefine custom elements.
Importance
i cannot use svelte without it
The text was updated successfully, but these errors were encountered: