Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Losing style of tr element when being dragged with react-sortable-hoc

My issue is that the style of the selected element is lost while dragging. I am using the react-sortable-hoc library, which doesn't give information on that. Their examples do not have this issue. The style always stays the same as the original item.

<tbody>
    {items.map((value, index) => (
    <SortableItem key={`item-${value.code}`} index={index} sortIndex={index} value={value} />
    ))}
</tbody>

const SortableItem = SortableElement(({value, sortIndex}) => (
        <tr>
            <DragHandle sortIndex={sortIndex}/>
            <td>{value.label}</td>
            <td>{value.beta.toString()}</td>
            <td>{value.prod.toString()}</td>
            <td>{value.hidden.toString()}</td>
        </tr>
    ));

        const DragHandle = SortableHandle(({sortIndex}) => <td>{sortIndex}</td>);

Here is my list before I select and drag an element.

And here is my list when I select and start dragging the first element. enter image description here

like image 917
Alexandre Avatar asked Nov 29 '25 16:11

Alexandre


1 Answers

For me, the problem was in CSS hierarchy and specificity, I was defining the styles of the item in relation to the parent. like so:

.list .item{
...
}

but while dragging the item, the element was no longer a child to the [previous] parent but was a separate element outside the parent. hence it lost all its styling! therefore to solve this problem we could just define the item and parent styles globally like so:

.list{
...
}

.item{
...
}
like image 190
Dev Sebastian Avatar answered Dec 02 '25 05:12

Dev Sebastian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!