-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(runtime):
scoped: true
slot fallback with forwarded slot (#6171)
* fix(runtime): `scoped: true` slot fallback with forwarded slot * chore: --------- Co-authored-by: John Jenkins <[email protected]>
- Loading branch information
1 parent
30f2a09
commit 57e7e58
Showing
5 changed files
with
108 additions
and
9 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
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
24 changes: 24 additions & 0 deletions
24
test/wdio/slot-fallback-with-forwarded-slot/child-component.tsx
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,24 @@ | ||
import { Component, h, Host, Prop } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'slot-forward-child-fallback', | ||
scoped: true, | ||
styles: ` | ||
:host { | ||
display: block; | ||
} | ||
`, | ||
}) | ||
export class ChildComponent { | ||
@Prop() label: string; | ||
|
||
render() { | ||
return ( | ||
<Host> | ||
<div> | ||
<slot name="label">{this.label}</slot> | ||
</div> | ||
</Host> | ||
); | ||
} | ||
} |
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,51 @@ | ||
import { h } from '@stencil/core'; | ||
import { render } from '@wdio/browser-runner/stencil'; | ||
|
||
describe('slot-fallback-with-forwarded-slot', () => { | ||
it('renders fallback via prop', async () => { | ||
// @ts-expect-error - wdio complaining about missing prop | ||
const { $root, root } = render({ | ||
template: () => <slot-forward-root label="Slot fallback via property"></slot-forward-root>, | ||
}); | ||
await $root.$('slot-fb'); | ||
const fb: HTMLElement = document.querySelector('slot-fb'); | ||
|
||
expect(await $root.getText()).toBe(''); | ||
expect(fb.textContent).toBe('Slot fallback via property'); | ||
expect(fb.getAttribute('hidden')).toBe(null); | ||
expect(fb.hidden).toBe(false); | ||
|
||
const p = document.createElement('p'); | ||
p.textContent = 'Slot content via slot'; | ||
p.slot = 'label'; | ||
root.appendChild(p); | ||
|
||
expect(await $root.getText()).toBe('Slot content via slot'); | ||
expect(fb.getAttribute('hidden')).toBe(''); | ||
expect(fb.hidden).toBe(true); | ||
}); | ||
|
||
it('should hide slot-fb elements when slotted content exists', async () => { | ||
// @ts-expect-error - wdio complaining about missing prop | ||
const { $root, root } = render({ | ||
template: () => ( | ||
<slot-forward-root label="Slot fallback via property"> | ||
<div slot="label">Slot content via slot</div> | ||
</slot-forward-root> | ||
), | ||
}); | ||
await $root.$('slot-fb'); | ||
const fb: HTMLElement = document.querySelector('slot-fb'); | ||
|
||
expect(await $root.getText()).toBe('Slot content via slot'); | ||
expect(fb.textContent).toBe('Slot fallback via property'); | ||
expect(fb.getAttribute('hidden')).toBe(''); | ||
expect(fb.hidden).toBe(true); | ||
|
||
root.removeChild(root.childNodes[0]); | ||
|
||
expect(await $root.getText()).toBe(''); | ||
expect(fb.getAttribute('hidden')).toBe(null); | ||
expect(fb.hidden).toBe(false); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
test/wdio/slot-fallback-with-forwarded-slot/parent-component.tsx
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,24 @@ | ||
import { Component, h, Host, Prop } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'slot-forward-root', | ||
scoped: true, | ||
styles: ` | ||
:host { | ||
display: block; | ||
} | ||
`, | ||
}) | ||
export class MyComponent { | ||
@Prop() label: string; | ||
|
||
render() { | ||
return ( | ||
<Host> | ||
<slot-forward-child-fallback label={this.label}> | ||
<slot name="label" /> | ||
</slot-forward-child-fallback> | ||
</Host> | ||
); | ||
} | ||
} |