Merge pull request #424 from ing-bank/fix/registrationPortalMove

fix(field): support moving of a portal node
This commit is contained in:
gerjanvangeest 2019-12-04 17:12:04 +01:00 committed by GitHub
commit 4c3a8afa33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View file

@ -21,6 +21,7 @@ export const FormRegistrarPortalMixin = dedupeMixin(
super();
this.formElements = [];
this.registrationTarget = undefined;
this.__hasBeenRendered = false;
this.__readyForRegistration = false;
this.registrationReady = new Promise(resolve => {
this.__resolveRegistrationReady = resolve;
@ -34,6 +35,9 @@ export const FormRegistrarPortalMixin = dedupeMixin(
this.__checkRegistrationTarget();
formRegistrarManager.add(this);
if (this.__hasBeenRendered) {
formRegistrarManager.becomesReady();
}
this.__redispatchEventForFormRegistrarPortalMixin = ev => {
ev.stopPropagation();
@ -67,6 +71,7 @@ export const FormRegistrarPortalMixin = dedupeMixin(
this.__resolveRegistrationReady();
this.__readyForRegistration = true;
formRegistrarManager.becomesReady(this);
this.__hasBeenRendered = true;
}
__checkRegistrationTarget() {

View file

@ -221,6 +221,30 @@ export const runRegistrationSuite = customConfig => {
expect(registerSpy.args[2][0].target.tagName).to.equal(childEl.tagName);
});
it('keeps working if moving the portal itself', async () => {
const el = await fixture(html`<${parentTag}></${parentTag}>`);
const portal = await fixture(html`
<${portalTag} .registrationTarget=${el}>
<${childTag}></${childTag}>
</${portalTag}>
`);
const otherPlace = await fixture(html`
<div></div>
`);
otherPlace.appendChild(portal);
const newField = await fixture(html`
<${childTag}></${childTag}>
`);
expect(el.formElements.length).to.equal(1);
portal.appendChild(newField);
expect(el.formElements.length).to.equal(2);
portal.removeChild(newField);
expect(el.formElements.length).to.equal(1);
});
it('works for portals that have a delayed render', async () => {
const delayedPortalString = defineCE(
class extends FormRegistrarPortalMixin(LitElement) {