Replies: 3 comments
-
It is a bit unclear what you are trying to do here. If the web component dispatches a
For web components I would use regular events, that is the DOM-native way (Playground example). You can use callback functions, but the custom element has to define a property for it. E.g. <my-element close={data => alert(data)}></my-element> export class MyElement extends HTMLElement {
get close() {
return this._close;
}
set close(value) {
this._close = value;
}
// ..., in event listener:
this.close?.('hello from my-element');
} |
Beta Was this translation helpful? Give feedback.
-
Thanks for your reply. In fact, I was aiming to use a Svelte5 component from a vanilla HTML/JS setup and I do have control of both sides. Reading the remark with |
Beta Was this translation helpful? Give feedback.
-
I finally discovered the $host function. If it had been mentioned in the Here is how I support both customElement and Svelte component modes:
|
Beta Was this translation helpful? Give feedback.
-
I wonder if it is possible to pass callbacks to custom element created with Svelte5 and if it is how ?
Basically I would like the equivalent of:
But using the custom WebComponents syntax
<my-element language="fr" ?onClose?=?? ?onModify?=??></my-element>
.Beta Was this translation helpful? Give feedback.
All reactions