lit / lit-element

LEGACY REPO. This repository is for maintenance of the legacy LitElement library. The LitElement base class is now part of the Lit library, which is developed in the lit monorepo.
https://lit-element.polymer-project.org
BSD 3-Clause "New" or "Revised" License
4.49k stars 318 forks source link

CustomEvent blocked/lost? #1157

Closed tamis-laan closed 3 years ago

tamis-laan commented 3 years ago

First custom component:

render() {
    return html`
      <div @click=${_=>{
            this.dispatchEvent(new CustomEvent('my-event',{bubbles:true}))
        }}>
           <slot></slot>
      </div>
    `
}

Second custom component:

render() {
    return html`
        <first-element @my-event=${_=>console.log('event triggered on second component')}>
                HELLO WORLD
        </first-element>
    `
}

Third custom component:

render() {
    return html`
        <second-element @my-event=${_=>console.log('event triggered on third component')}>      
        </second-element>
    `
}

When I click HELLO WORLD the second element my-event listener is triggered and prints to the console. The third custom component event listener is not triggered.

I would imagine the event would keep bubbling up to the third component?

BTW the click event is propagated all the way to the third component.

tamis-laan commented 3 years ago

Ah not a bug, apparently you need to set the composed property to true new CustomEvent('my-event',{bubbles:true,composed:true})