css-element-queries icon indicating copy to clipboard operation
css-element-queries copied to clipboard

Stops working after drop event using dragula

Open quiringk opened this issue 8 years ago • 4 comments
trafficstars

I am using css-element-queries successfully in my Angular 2+ project. I have a page with a bunch of different components that have element-queries inside of them. I am also using dragula to allow dragging and dropping of these components for reordering. Everything is working fine until I drop a component after or before another component. Once that happens, the element queries stop working for the component that was dragged and dropped, but continue working for the other components.

I tried firing ElementQueries.init() &/or ElementQueries.update() in the dragula drop event without any success.

I am initializing ElementQueries in each component by calling ElementQueries.update() after the data has loaded but if I called ElementQueries.init() that works fine as well.

Any idea why a dragula drop event would stop the element queries in that dropped component to stop working? Is there a way to "refresh" the element queries to start working again?

quiringk avatar Aug 09 '17 00:08 quiringk

Same issue as in https://github.com/marcj/css-element-queries/issues/171 I guess.

marcj avatar Aug 09 '17 17:08 marcj

So I figured out a way to capture the drag and drop event, and then I can remove the DOM and re-add it using angulars *ngIf, and then call ElementQueries.update(). However, this seems to make the performance of the page get worse the more I do that. Should I be calling something else at that moment?

quiringk avatar Aug 09 '17 17:08 quiringk

Well, we need to add the reset method in our API as described in the linked issue, so you can call it on those elements that have been moved in the DOM. If you could send us a pull-request with that change, we could merge it and you have immediately a real fix.

marcj avatar Aug 09 '17 19:08 marcj

so, the reset api is added to the ResizeSensor. However, there's no easy way to reset all these elements using ElementQueries. I can submit a PR fixing this. Once that is available, we could easily subscribe to drop events in dragula and call ElementQueries.reset()

DmitryEfimenko avatar Jan 09 '19 00:01 DmitryEfimenko