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

feat(dw-dialog): TypeError unobserver trigger element is undefined #73

Merged
merged 2 commits into from
Jan 17, 2023
Merged
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
18 changes: 4 additions & 14 deletions dw-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,13 @@ export const DwModalDialogMixin = (baseElement) => class DwModalDialog extends b
this._onDialogScroll = this._onDialogScroll.bind(this);
}

get _dialogContentEl() {
return this.renderRoot.querySelector('.mdc-dialog__content');
}

connectedCallback() {
super.connectedCallback();
if (this.type === "modal") {
this.resizeObserver = new ResizeObserver(() => this._manageFullHeight());
}
}

firstUpdated() {
super.firstUpdated();
if (this.type == "modal") {
this.resizeObserver.observe(this._dialogContentEl);
}
}

disconnectedCallback() {
if (this.type === 'modal') {
this._unlistenEvents();
Expand All @@ -183,9 +172,6 @@ export const DwModalDialogMixin = (baseElement) => class DwModalDialog extends b
}
}
super.disconnectedCallback();
if (this.type === 'modal') {
this.resizeObserver.unobserve(this._dialogContentEl);
}
}

updated(changedProps) {
Expand All @@ -207,6 +193,9 @@ export const DwModalDialogMixin = (baseElement) => class DwModalDialog extends b
super.open(triggerEl)
return;
}
this._dialogContentEl = this.renderRoot.querySelector('.mdc-dialog__content');
this.resizeObserver.observe(this._dialogContentEl);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hitendreamworld for better logic, following updates are needed:

  1. Don't write custom getter of _dialogContentEl
  2. Instead, during observe set this instance variable, using the same logic written for the custom getter.
  3. Use the same instance variable during unobserve.


this.updateComplete.then(() => {
if (this._mdcDialogInstance) {
return;
Expand All @@ -230,6 +219,7 @@ export const DwModalDialogMixin = (baseElement) => class DwModalDialog extends b
super.close();
return;
}
this._dialogContentEl && this.resizeObserver.unobserve(this._dialogContentEl);
this._mdcDialogInstance && this._mdcDialogInstance.close();
}

Expand Down