-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: event listener not being invoked for native web components (#4012)
* fix: event listener not being invoked for native web components * chore: simplify test * chore: test tweaks * chore: also avoid wrapping listeners for non-Node EventTargets * chore: account for light dom nodes * chore: account for window --------- Co-authored-by: Eugene Kashida <[email protected]>
- Loading branch information
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/@lwc/integration-karma/test/mixed-shadow-mode/composed-path/index.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createElement } from 'lwc'; | ||
import Test from 'x/test'; | ||
|
||
describe('event.composedPath() of event dispatched from closed shadow root', () => { | ||
it('should have shadowed elements when invoked inside the shadow root', () => { | ||
const elm = createElement('x-test', { is: Test }); | ||
document.body.appendChild(elm); | ||
|
||
return Promise.resolve().then(() => { | ||
elm.clickShadowedButton(); | ||
|
||
expect(elm.getShadowedComposedPath()).toEqual([ | ||
jasmine.any(HTMLElement), // button | ||
jasmine.any(Object), // #shadow-root(closed) | ||
elm.child, | ||
elm.shadowRoot, | ||
elm, | ||
document.body, | ||
document.documentElement, | ||
document, | ||
window, | ||
]); | ||
}); | ||
}); | ||
|
||
it('should not have shadowed elements when invoked outside the shadow root', () => { | ||
const elm = createElement('x-test', { is: Test }); | ||
document.body.appendChild(elm); | ||
|
||
return Promise.resolve().then(() => { | ||
elm.clickShadowedButton(); | ||
|
||
expect(elm.getComposedPath()).toEqual([ | ||
elm.child, | ||
elm.shadowRoot, | ||
elm, | ||
document.body, | ||
document.documentElement, | ||
document, | ||
window, | ||
]); | ||
}); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/@lwc/integration-karma/test/mixed-shadow-mode/composed-path/x/test/component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
customElements.define( | ||
'x-mixed-shadow-mode-composed-path', | ||
class extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this._shadowRoot = this.attachShadow({ mode: 'closed' }); | ||
this._button = document.createElement('button'); | ||
this._button.addEventListener('click', (event) => { | ||
this.composedPath = event.composedPath(); | ||
}); | ||
this._shadowRoot.appendChild(this._button); | ||
} | ||
|
||
click() { | ||
this._button.click(); | ||
} | ||
} | ||
); |
3 changes: 3 additions & 0 deletions
3
packages/@lwc/integration-karma/test/mixed-shadow-mode/composed-path/x/test/test.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<template> | ||
<x-mixed-shadow-mode-composed-path lwc:external lwc:ref="child" onclick={handleClick}></x-mixed-shadow-mode-composed-path> | ||
</template> |
30 changes: 30 additions & 0 deletions
30
packages/@lwc/integration-karma/test/mixed-shadow-mode/composed-path/x/test/test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { LightningElement, api } from 'lwc'; | ||
import './component.js'; | ||
|
||
export default class Parent extends LightningElement { | ||
composedPath; | ||
|
||
@api | ||
get child() { | ||
return this.refs.child; | ||
} | ||
|
||
@api | ||
getShadowedComposedPath() { | ||
return this.child.composedPath; | ||
} | ||
|
||
@api | ||
getComposedPath() { | ||
return this.composedPath; | ||
} | ||
|
||
@api | ||
clickShadowedButton() { | ||
this.child.click(); | ||
} | ||
|
||
handleClick(event) { | ||
this.composedPath = event.composedPath(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters