tajo / react-movable

🔀 Drag and drop for your React lists and tables. Accessible. Tiny.
https://react-movable.pages.dev
MIT License
1.53k stars 51 forks source link

Make one or more item inside the list fixed/locked #97

Open ahmaadaziz opened 1 year ago

ahmaadaziz commented 1 year ago

I am looking for a way to make a specific item inside a list to be not draggable which is implemented using the disabled property. But the items that are not disabled can still be dragged above it and that would change the order of the list; the feature I am looking for would FIX that item's index so its order cannot be changed.

For example I have a list that contains 5 items and I want the first item to always remain on top, so I will FIX that item and make it disabled, so now all other items below it can be dragged and moved around but that FIXED item will always remain at index 1/0. Same could be done for the last item as well.

IanVS commented 9 months ago

Just a thought, but could you add the first/last items as part of the renderList prop, instead of adding them to renderItem?

ahmaadaziz commented 9 months ago

@IanVS consider I want to fix the 4th item in my list then then it won't work. I only provided an example for better understanding but it doesn't necessary always have to be the first and last items

IanVS commented 9 months ago

In that case, it seems like you could have two lists, one above the fixed item, and one below.

ahmaadaziz commented 9 months ago

@IanVS Yes you are right, I can do that and in case of dynamically selecting the fixed item i can maintain two lists and filter out the fixed item, but in case there is more than one fixed item the amount of preprocessing that I have to do can be a bit much.

Imagine a case where the 2nd, 5th, 9th and 17th (these are random by the way) items need to stay fixed and I only get to know those indexes right before render from a some fetched data. Splitting and maintaining multiple lists and rendering them above and below those fixed items is definitely not the best solution (Hopefully this gets my point across 🤞)

My problem has already been solved due to architectural changes (the issue can be closed 👍), however I feel like this is something the library should handle by itself.

Consider it a feature request now 🚀

IanVS commented 9 months ago

Yeah I understand it's not an ideal workaround, but I wonder what kind of use case would involve so many "locked" cells requiring sorting only above or below them. I'd be curious to hear what kind of UI you're building where this might be needed. (note: I'm not a maintainer, just trying to help out)

ahmaadaziz commented 9 months ago

haha @IanVS your curiosity is understandable for such a situation (which by the way I am not in any more 😉). My UI consisted of a list where the end user can add as many items as they want from an available list type of items and in those items, some had to be fixed, so this was merely an edge case for me. Thanks for taking the time and interest, your help is appreciated