-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lightning-element): expose hostElement property (#4259)
Co-authored-by: Nolan Lawson <[email protected]>
- Loading branch information
1 parent
228a4a7
commit 8b3f436
Showing
12 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
packages/@lwc/engine-server/src/__tests__/fixtures/this-dot-host-element/error.txt
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 @@ | ||
this.hostElement is not supported in this environment |
3 changes: 3 additions & 0 deletions
3
packages/@lwc/engine-server/src/__tests__/fixtures/this-dot-host-element/index.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,3 @@ | ||
export const tagName = 'x-this-dot-host-element'; | ||
export { default } from 'x/this-dot-host-element'; | ||
export * from 'x/this-dot-host-element'; |
3 changes: 3 additions & 0 deletions
3
...fixtures/this-dot-host-element/modules/x/this-dot-host-element/this-dot-host-element.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> | ||
<span>{test}</span> | ||
</template> |
11 changes: 11 additions & 0 deletions
11
..._/fixtures/this-dot-host-element/modules/x/this-dot-host-element/this-dot-host-element.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,11 @@ | ||
import { LightningElement } from 'lwc'; | ||
|
||
export default class ThisDotHostElement extends LightningElement { | ||
constructor() { | ||
super(); | ||
} | ||
|
||
get test() { | ||
return this.hostElement.tagName; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/@lwc/integration-karma/test/component/LightningElement.hostElement/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,39 @@ | ||
import { createElement } from 'lwc'; | ||
|
||
import Wrapper from 'x/wrapper'; | ||
|
||
function createWrapper() { | ||
const elm = createElement('x-wrapper', { is: Wrapper }); | ||
document.body.appendChild(elm); | ||
return elm; | ||
} | ||
|
||
it('should provide the root element for light rendering', () => { | ||
const elm = createWrapper(); | ||
|
||
const divElement = elm.getDivElement(); | ||
const lightElement = elm.getLightElement(); | ||
const hostElement = lightElement.getHostElement(); | ||
|
||
expect(hostElement).toBeTruthy(); | ||
expect(hostElement.tagName).toEqual('X-LIGHT'); | ||
expect(hostElement.dataset.name).toEqual('lightElement'); | ||
|
||
expect(hostElement).toEqual(lightElement); | ||
expect(hostElement.parentElement).toEqual(divElement); | ||
}); | ||
|
||
it('should provide the root element for shadow rendering', () => { | ||
const elm = createWrapper(); | ||
|
||
const divElement = elm.getDivElement(); | ||
const shadowElement = elm.getShadowElement(); | ||
const hostElement = shadowElement.getHostElement(); | ||
|
||
expect(hostElement).toBeTruthy(); | ||
expect(hostElement.tagName).toEqual('X-SHADOW'); | ||
expect(hostElement.dataset.name).toEqual('shadowElement'); | ||
|
||
expect(hostElement).toEqual(shadowElement); | ||
expect(hostElement.parentElement).toEqual(divElement); | ||
}); |
1 change: 1 addition & 0 deletions
1
...ges/@lwc/integration-karma/test/component/LightningElement.hostElement/x/light/light.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 @@ | ||
<template lwc:render-mode="light"></template> |
10 changes: 10 additions & 0 deletions
10
packages/@lwc/integration-karma/test/component/LightningElement.hostElement/x/light/light.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,10 @@ | ||
import { LightningElement, api } from 'lwc'; | ||
|
||
export default class Light extends LightningElement { | ||
static renderMode = 'light'; | ||
|
||
@api | ||
getHostElement() { | ||
return this.hostElement; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ges/@lwc/integration-karma/test/component/LightningElement.hostElement/x/shadow/shadow.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,8 @@ | ||
import { LightningElement, api } from 'lwc'; | ||
|
||
export default class Shadow extends LightningElement { | ||
@api | ||
getHostElement() { | ||
return this.hostElement; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...@lwc/integration-karma/test/component/LightningElement.hostElement/x/wrapper/wrapper.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,6 @@ | ||
<template> | ||
<div data-name="divElement" lwc:ref="div"> | ||
<x-light data-name="lightElement" lwc:ref="light"></x-light> | ||
<x-shadow data-name="shadowElement" lwc:ref="shadow"></x-shadow> | ||
</div> | ||
</template> |
18 changes: 18 additions & 0 deletions
18
...s/@lwc/integration-karma/test/component/LightningElement.hostElement/x/wrapper/wrapper.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 @@ | ||
import { LightningElement, api } from 'lwc'; | ||
|
||
export default class Wrapper extends LightningElement { | ||
@api | ||
getDivElement() { | ||
return this.refs.div; | ||
} | ||
|
||
@api | ||
getLightElement() { | ||
return this.refs.light; | ||
} | ||
|
||
@api | ||
getShadowElement() { | ||
return this.refs.shadow; | ||
} | ||
} |
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