SolidJSS
SolidJSโ€ข2y agoโ€ข
6 replies
sponge

Delegated custom events

Should delegated events work with custom events sent via HTMLElement dispatchEvent? The (new) docs mention:

For any other events, such as custom events or events you wish not to be delegated, the on: attribute will add an event listener as-is.

If you need to attach an event listener to an element that is not supported by Solid's event delegation, such as a custom event in a custom element, you can use the on:__ form.

I'm wanting to use delegated events so I can have a component that uses onMyEvent, and also allow users of that component to add their own onMyEvent on the same component.

Even though the docs imply I need to use the on: form to attach a native event, the delegated events seem to work correctly. TS does complain about the JSX, though (I have setup the event in JSX.CustomEvents/CustomCaptureEvents):

Property 'onMyEvent' does not exist on type 'HTMLAttributes<HTMLDivElement>'. Did you mean '"on:myevent"'?

Should I be able to use delegated events for this custom event, and if I can, how do I get TS to stop complaining about that property not existing?
Was this page helpful?