clauderic / dnd-kit

The modern, lightweight, performant, accessible and extensible drag & drop toolkit for React.
http://dndkit.com
MIT License
12.79k stars 638 forks source link

Draggable item is disabled with MUI Grid container #1317

Open MOhhh-ok opened 9 months ago

MOhhh-ok commented 9 months ago

Hi.

Draggable element doesn't work with MUI Grid container. I made sample code. Could you please check it?

import React from 'react';
import { DndContext, useDraggable } from '@dnd-kit/core';
import { Grid } from '@mui/material';

const DND_ID = "dndTest";

function Draggable(props: { children: React.ReactNode }) {
    const { attributes, listeners, setNodeRef, transform } = useDraggable({
        id: DND_ID,
    });
    const style = transform ? {
        transform: `translate3d(${transform.x}px, ${transform.y}px, 0)`,
    } : undefined;

    return (
        <button ref={setNodeRef} style={style} {...listeners} {...attributes}>
            {props.children}
        </button>
    );
}

export function DraggableTest() {
    return <>
        <h1>Drag test</h1>
        <DndContext>
            <Draggable>Can drag</Draggable>
        </DndContext>
        <br />

        <DndContext>
            <Draggable>Can not drag</Draggable>
        </DndContext>
        <br />

        <Grid container spacing={2}>
            <Grid item xs={12}>This grid may the cause</Grid>
        </Grid>

        <DndContext>
            <Draggable>Can drag</Draggable>
        </DndContext>
        <br/><br/>
        <Grid container spacing={2}>
            <Grid item xs={12}>This grid is safe under two line breaks.</Grid>
        </Grid>

    </>
}

Thanks.

MOhhh-ok commented 9 months ago

Version is "@dnd-kit/core": "^6.1.0",