Skip to content

Commit

Permalink
fix: rework raq hack to fix instantiation not happening if element hi…
Browse files Browse the repository at this point in the history
…dden (fix #406)
  • Loading branch information
Grsmto committed Nov 13, 2019
1 parent 1b55116 commit c73be96
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/simplebar/src/simplebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,17 +293,20 @@ export default class SimpleBar {
window.addEventListener('resize', this.onWindowResize);

// Hack for https://github.com/WICG/ResizeObserver/issues/38
let ignoredCallbacks = 0;
let resizeObserverStarted = false;

this.resizeObserver = new ResizeObserver(() => {
ignoredCallbacks++;
if (ignoredCallbacks === 1) return;
if (!resizeObserverStarted) return;
this.recalculate();
});

this.resizeObserver.observe(this.el);
this.resizeObserver.observe(this.contentEl);

window.requestAnimationFrame(() => {
resizeObserverStarted = true;
});

// This is required to detect horizontal scroll. Vertical scroll only needs the resizeObserver.
this.mutationObserver = new MutationObserver(this.recalculate);

Expand Down

0 comments on commit c73be96

Please sign in to comment.