Skip to content

Commit

Permalink
refactor: use _onResize instead of IntersectionObserver (#8620) (#8628)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Feb 4, 2025
1 parent f9e801a commit 7450e3e
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions packages/form-layout/src/vaadin-form-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ class FormLayout extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))
_labelsOnTop: {
type: Boolean,
},

/** @private */
__isVisible: {
type: Boolean,
},
};
}

Expand All @@ -269,27 +264,6 @@ class FormLayout extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))
this.addEventListener('animationend', this.__onAnimationEnd);
}

constructor() {
super();

this.__intersectionObserver = new IntersectionObserver((entries) => {
// If the browser is busy (e.g. due to slow rendering), multiple entries can
// be queued and then passed to the callback invocation at once. Make sure we
// use the most recent entry to detect whether the layout is visible or not.
// See https://github.com/vaadin/web-components/issues/8564
const entry = [...entries].pop();
if (!entry.isIntersecting) {
// Prevent possible jump when layout becomes visible
this.$.layout.style.opacity = 0;
}
if (!this.__isVisible && entry.isIntersecting) {
this._updateLayout();
this.$.layout.style.opacity = '';
}
this.__isVisible = entry.isIntersecting;
});
}

/** @protected */
connectedCallback() {
super.connectedCallback();
Expand All @@ -298,7 +272,6 @@ class FormLayout extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))
requestAnimationFrame(() => this._updateLayout());

this._observeChildrenColspanChange();
this.__intersectionObserver.observe(this.$.layout);
}

/** @protected */
Expand All @@ -307,7 +280,6 @@ class FormLayout extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))

this.__mutationObserver.disconnect();
this.__childObserver.disconnect();
this.__intersectionObserver.disconnect();
}

/** @private */
Expand Down Expand Up @@ -580,8 +552,16 @@ class FormLayout extends ResizeMixin(ElementMixin(ThemableMixin(PolymerElement))
* @protected
* @override
*/
_onResize() {
_onResize(contentRect) {
if (contentRect.width === 0 && contentRect.height === 0) {
this.$.layout.style.opacity = '0';
return;
}

this._selectResponsiveStep();
this._updateLayout();

this.$.layout.style.opacity = '';
}
}

Expand Down

0 comments on commit 7450e3e

Please sign in to comment.