marcj / css-element-queries

CSS Element-Queries aka Container Queries. High-speed element dimension/media queries in valid css.
http://marcj.github.io/css-element-queries/
MIT License
4.27k stars 487 forks source link

Wrong query detecting after reinitialisation in Angular App #202

Closed marvinhuebner closed 6 years ago

marvinhuebner commented 6 years ago

I'm trying to implement css element queries in one of our Angular Apps.

Some element are not initially rendered, so i reinit ElementQueries after a <slide-in> component or <modal> is rendered.

This works in some way but not correct. At the first time the element queries are working correct, but if i close the slide in element and reopen it, there are only two element queries detected and not the fully list.

First:

vollbild_07_12_17__08_11

Second:

vollbild_07_12_17__08_21

Here is a short video example: https://streamable.com/z518j

My angular code looks like this:

I initialise ElementQueries after the app is loaded. And then I listen to simple changes, for example the slide-in opening, and reinit element queries to pass the new rendered html markup.

import {Component, OnChanges, Input, ElementRef, AfterViewInit, SimpleChanges} from '@angular/core';
import {ResizeSensor, ElementQueries} from 'css-element-queries';

@Component({
    selector: 'designer-element-queries',
    template: ''
})

export class ElementQueriesComponent implements OnChanges, AfterViewInit {
    @Input('active')active:boolean;

    constructor(
        private element:ElementRef
    ) {
    }

    ngAfterViewInit() {
        ElementQueries.init();
    }

    ngOnChanges(changes: SimpleChanges) {
        ElementQueries.init();
    }
}

Maybe someone can give me a hint why this is causing?

marcj commented 6 years ago

Is this just hidden (using visibility or display css property) or is the DOM detached and re-attached of the watched element when you toggle the visibility?

marvinhuebner commented 6 years ago

The DOM is detached and attached.

marcj commented 6 years ago

Should be fixed, will be part of the next version 1.0.0 in the next hours.