hootsuite / grid

Drag and drop library for two-dimensional, resizable and responsive lists
http://hootsuite.github.io/grid/
Apache License 2.0
3.57k stars 279 forks source link

Autoheight gets applied to the wrong items #67

Closed andrei-picus-hs closed 9 years ago

andrei-picus-hs commented 9 years ago

autoheight-bug

Solution

The problem is due to the cloneItems method. When the properties are copied from the source to the destination we don't take into account any properties existing only on the destination.

So what happens is this:

  1. Grid initializes, auto size attribute is applied to items.
  2. Snapshot.
  3. Drag and drop. At this point the order of the items might have changed.
  4. Snapshot is copied back. Now the auto size attribute may be copied to the wrong items.
  5. Multiple items end up with the auto size attribute.
  6. Resize -> items end up being stretched.

A solution is to clear the extra properties on the destination. We can do this by doing two iterations over the properties:

The second time will set any extra properties to undefined since they won't be on the source object.

Another solution is to ignore the auto size attribute when copying the properties since it's the only extra property that we add onto the items.

andrei-picus-hs commented 9 years ago

@skidding which solution do you prefer?