Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore overlay opened state when moving within the DOM #3648

Merged
merged 4 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/dialog/src/vaadin-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,20 @@ class Dialog extends ThemePropertyMixin(ElementMixin(DialogDraggableMixin(Dialog
this.$.overlay.setProperties({ owner: this, renderer, headerRenderer, footerRenderer });
}

/** @protected */
connectedCallback() {
super.connectedCallback();
// Restore opened state if overlay was opened when disconnecting
if (this.__restoreOpened) {
this.opened = true;
}
}

/** @protected */
disconnectedCallback() {
super.disconnectedCallback();
// Close overlay and memorize opened state
this.__restoreOpened = this.opened;
this.opened = false;
}

Expand Down
8 changes: 8 additions & 0 deletions packages/dialog/test/dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ describe('vaadin-dialog', () => {
dialog.parentNode.removeChild(dialog);
expect(dialog.opened).to.be.false;
});

it('should not close the overlay when moved within the DOM', () => {
const newParent = document.createElement('div');
document.body.appendChild(newParent);

newParent.appendChild(dialog);
expect(dialog.opened).to.be.true;
});
});

describe('modeless', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/login/src/vaadin-login-overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class LoginOverlay extends LoginMixin(ElementMixin(ThemableMixin(PolymerElement)

this.$.vaadinLoginOverlayWrapper.addEventListener('vaadin-overlay-outside-click', this._preventClosingLogin);
this.$.vaadinLoginOverlayWrapper.addEventListener('vaadin-overlay-escape-press', this._preventClosingLogin);

// Restore opened state if overlay was open when disconnecting
if (this.__restoreOpened) {
this.$.vaadinLoginOverlayWrapper.opened = true;
}
}

/** @protected */
Expand All @@ -135,6 +140,9 @@ class LoginOverlay extends LoginMixin(ElementMixin(ThemableMixin(PolymerElement)

this.$.vaadinLoginOverlayWrapper.removeEventListener('vaadin-overlay-outside-click', this._preventClosingLogin);
this.$.vaadinLoginOverlayWrapper.removeEventListener('vaadin-overlay-escape-press', this._preventClosingLogin);

// Close overlay and memorize opened state
this.__restoreOpened = this.$.vaadinLoginOverlayWrapper.opened;
this.$.vaadinLoginOverlayWrapper.opened = false;
}

Expand Down
12 changes: 10 additions & 2 deletions packages/login/test/login-overlay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ describe('opened overlay', () => {

it('should set opened using attribute', () => {
expect(overlay.opened).to.be.true;
expect(document.querySelector('vaadin-login-form-wrapper')).to.be.ok;
expect(document.querySelector('vaadin-login-form-wrapper')).to.exist;
});

it('should remove form wrapper when closed', () => {
overlay.opened = false;
expect(document.querySelector('vaadin-login-form-wrapper')).to.be.not.ok;
expect(document.querySelector('vaadin-login-form-wrapper')).not.to.exist;
});

it('should not remove form wrapper when moved within DOM', () => {
const newParent = document.createElement('div');
document.body.appendChild(newParent);
newParent.appendChild(overlay);

expect(document.querySelector('vaadin-login-form-wrapper')).to.exist;
});

it('should propagate theme to a wrapper', () => {
Expand Down