-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(renderer): fix missing slot ref callback handling (#5337)
* fix(renderer): fix missing slot ref callback handling fixes one of the issues raised in #5335 adds a new internal variable which is stored during vnode rendering to reuse it within the relocatedNodes logic * test(slot): add missing e2e tests for slot ref handling * test(slot): add slotted element ref correctness to test case * style(slot): fix linter issue for the e2e test case
- Loading branch information
Showing
7 changed files
with
74 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Component, Element, h, Host } from '@stencil/core'; | ||
|
||
@Component({ | ||
tag: 'slot-ref', | ||
shadow: false, | ||
scoped: true, | ||
}) | ||
export class SlotRef { | ||
@Element() hostElement: HTMLElement; | ||
|
||
render() { | ||
return ( | ||
<Host> | ||
<slot | ||
name="title" | ||
ref={(el) => { | ||
this.hostElement.setAttribute('data-ref-id', el.id); | ||
this.hostElement.setAttribute('data-ref-tagname', el.tagName); | ||
}} | ||
/> | ||
</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,6 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf8"> | ||
<script src="./build/testapp.esm.js" type="module"></script> | ||
<script src="./build/testapp.js" nomodule></script> | ||
|
||
<slot-ref><span slot="title" id="slotted-element-id">Hello World!</span></slot-ref> |
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,19 @@ | ||
import { setupDomTests, waitForChanges } from '../util'; | ||
|
||
describe('slot-ref', function () { | ||
const { setupDom, tearDownDom } = setupDomTests(document); | ||
let app: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
app = await setupDom('/slot-ref/index.html'); | ||
}); | ||
afterEach(tearDownDom); | ||
|
||
it('ref callback of slot is called', async () => { | ||
await waitForChanges(); | ||
|
||
const host = app.querySelector('slot-ref'); | ||
expect(host.getAttribute('data-ref-id')).toBe('slotted-element-id'); | ||
expect(host.getAttribute('data-ref-tagname')).toBe('SPAN'); | ||
}); | ||
}); |