Dominus
Dominus

Reputation: 93

How do I set my event listener to capture an event through the shadow DOM?

I have a custom element which has a number of other custom elements in its shadow DOM. I want those child elements to react to an event the parent dispatches, so I set the composed flag to true, like

const matchingEvent = new CustomEvent('match', {
      composed: true
    })
this.dispatchEvent(matchingEvent)

and in the child element I set capture to true, like

this.addEventListener('match', this.#onMatching, {
      capture: true
    })

The event isn't captured, though. Is composed the wrong flag for capturing events from outside the shadow DOM, or is there another problem with my code?

Upvotes: 1

Views: 533

Answers (0)

Related Questions