improve sizeobserver logic for modern browsers

This commit is contained in:
Rene
2021-02-06 01:17:19 +01:00
parent 6f590b2cc4
commit c7f6be778d
2 changed files with 10 additions and 3 deletions
@@ -149,7 +149,13 @@ export const createSizeObserver = (
// appearCallback is always needed on scroll-observer strategy to reset it
if (appearCallback) {
addClass(sizeObserver, classNameSizeObserverAppear);
push(offListeners, on(sizeObserver, animationStartEventName, appearCallback));
push(
offListeners,
on(sizeObserver, animationStartEventName, appearCallback, {
// Fire only once for "CSS is ready" event
_once: !!ResizeObserverConstructor,
})
);
}
prependChildren(target, sizeObserver);
@@ -3,7 +3,7 @@ import './index.scss';
import should from 'should';
import { generateClassChangeSelectCallback, iterateSelect } from '@/testing-browser/Select';
import { setTestResult, waitForOrFailTest } from '@/testing-browser/TestResult';
import { hasDimensions, offsetSize, WH, style } from 'support';
import { hasDimensions, offsetSize, WH, style, ResizeObserverConstructor } from 'support';
import { createSizeObserver } from 'observers/sizeObserver';
@@ -65,7 +65,8 @@ const iterate = async (select: HTMLSelectElement | null, afterEach?: () => any)
const offsetSizeChanged = currOffsetSize.w !== newOffsetSize.w || currOffsetSize.h !== newOffsetSize.h;
const contentSizeChanged = currContentSize.w !== newContentSize.w || currContentSize.h !== newContentSize.h;
const dirChanged = currDir !== newDir;
const dimensions = hasDimensions(targetElm as HTMLElement);
// ResizeObserver Polyfill doesn't react on display: none, so make an exception there
const dimensions = ResizeObserverConstructor ? true : hasDimensions(targetElm as HTMLElement);
const observerElm = targetElm?.firstElementChild as HTMLElement;
// no overflow if not needed