react-movable icon indicating copy to clipboard operation
react-movable copied to clipboard

Collapse draggable item

Open raunofreiberg opened this issue 5 years ago • 5 comments

Hey,

Thanks for the great library! I have a use case that doesn't seem to be possible.

On drag, I would like to collapse the item along with it's hidden clone. This is quite useful for long lists where items can be pretty large in height. Collapsing them helps navigate through this list.

I tried doing something like:

height: isDragged ? "50px" : "100px",

on the component in renderItem but only the ghost item seems to change height, but not the hidden one?

Here's an example: https://codesandbox.io/s/sad-einstein-u7feh?file=/src/App.js:1160-1212

Thanks!

raunofreiberg avatar Oct 07 '20 08:10 raunofreiberg

I can collapse the draggable item by doing:

height: isDragged || props.style.visibility === 'hidden' ? "50px" : "100px",

But this still requires me to drag over the initial height of it:

Kapture 2020-10-07 at 12 00 14

raunofreiberg avatar Oct 07 '20 09:10 raunofreiberg

@tajo any ideas here?

raunofreiberg avatar Oct 12 '20 10:10 raunofreiberg

Utilizing beforeDrag could get you closer: https://codesandbox.io/s/romantic-cookies-7odri?file=/src/App.js

However, onChange is not called when the item position is not changed so the height doesn't reset. Maybe we could add afterDrag or having some better API for this use-case (explicit draggedHeight prop?). Although, it seems too rare of a use-case to just add a new API for this, so maybe more general afterDrag to fix my workaround would be the best.

tajo avatar Oct 12 '20 17:10 tajo

afterDrag would work for me! With some direction, I could open a PR, if you'd like?

raunofreiberg avatar Oct 19 '20 10:10 raunofreiberg

@raunofreiberg Yea, go for it.

tajo avatar Oct 19 '20 18:10 tajo