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

<tr> cannot appear as a child of <body> #58

Closed alxvallejo closed 3 years ago

alxvallejo commented 3 years ago

This is an error I see coming up with trying to reorder table rows. Pretty standard implementation:

<List
    values={questions}
    onChange={({ oldIndex, newIndex }) => {
        const newList = arrayMove(questions, oldIndex, newIndex);
        const newOrder = newList.map((q, i) => { return {id: q.id, order: i} });
        setQuestions(newList)
        orderQuestions(newOrder)
    }}
    renderList={({ children, props }) => <Table size="sm" responsive striped ><tbody {...props}>{children}</tbody></Table>}
    renderItem={({ value, props }) => {
        const p = value;
        const field_type = p.field_type.charAt(0).toUpperCase() + p.field_type.slice(1)
        return (
            <tr {...props}>
                <td>{p.title}</td>
                <td>{field_type}</td>
            </tr>
        )
    }}
/>
tajo commented 3 years ago

Check the table example. The trick is to wrap renderItem with a table element when isDragged is true.