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

Doesn't update after parent display changes #49

Open
wnewbery opened this issue Aug 15, 2017 · 1 comment
Open

Doesn't update after parent display changes #49

wnewbery opened this issue Aug 15, 2017 · 1 comment

Comments

@wnewbery
Copy link

I found if used as a child element within an (emulated using display: none) <details> that it is never detected that the grid is displayed, seemingly because such attribute changes are not being observed.

From what I can tell this is because it inserted id's and CSS rules forcing a size of zero already, and so when displayed its still zero and no update :(

One possibility I found is to also check for offsetParent. In simple cases it will be null if not displayed, but its also null if the element itself is positioned: fixed at which point I am not sure.

css-grid/polyfill.js#L95

// TODO: watch resize events for relayout?
var lastWidth = element.offsetWidth;
var lastHeight = element.offsetHeight;
var lastParent = element.offsetParent; // Added
var updateOnResize = function() {
  if(!element.gridLayout) { return; }
  if(lastWidth != element.offsetWidth || lastHeight != element.offsetHeight || 
      lastParent !== element.offsetParent) {
    // update last known size
    lastWidth = element.offsetWidth;
    lastHeight = element.offsetHeight;
    lastParent = element.offsetParent;
    // relayout (and prevent double-dispatch)
    element.gridLayout.scheduleRelayout();
  }
  requestAnimationFrame(updateOnResize);
}
@FremyCompany
Copy link
Owner

Interesting approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants