diff --git a/packages/core/src/data-editor/data-editor.tsx b/packages/core/src/data-editor/data-editor.tsx index 7a3c89d86..9d0ccdab6 100644 --- a/packages/core/src/data-editor/data-editor.tsx +++ b/packages/core/src/data-editor/data-editor.tsx @@ -845,6 +845,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction { + args.setData("text", "testing"); + }} + dragImageAnchor={'click'} + getCellContent={getData} + columns={columns} + rows={1000} + /> + ); +} + export function DynamicAddRemoveColumns({ columnCount }: { columnCount: number }) { // trying to be 500x500 const cols: GridColumn[] = [ diff --git a/packages/core/src/internal/data-grid-dnd/data-grid-dnd.tsx b/packages/core/src/internal/data-grid-dnd/data-grid-dnd.tsx index f91c16da6..a54d61842 100644 --- a/packages/core/src/internal/data-grid-dnd/data-grid-dnd.tsx +++ b/packages/core/src/internal/data-grid-dnd/data-grid-dnd.tsx @@ -398,6 +398,7 @@ const DataGridDnd: React.FunctionComponent = p => { imageWindowLoader={p.imageWindowLoader} resizeColumn={resizeCol} isDraggable={p.isDraggable} + dragImageAnchor={p.dragImageAnchor} isFilling={p.isFilling} isFocused={p.isFocused} onCanvasBlur={p.onCanvasBlur} diff --git a/packages/core/src/internal/data-grid-search/data-grid-search.tsx b/packages/core/src/internal/data-grid-search/data-grid-search.tsx index d507d6a43..974ba2232 100644 --- a/packages/core/src/internal/data-grid-search/data-grid-search.tsx +++ b/packages/core/src/internal/data-grid-search/data-grid-search.tsx @@ -524,6 +524,7 @@ const DataGridSearch: React.FunctionComponent = p => { gridRef={p.gridRef} headerIcons={p.headerIcons} isDraggable={p.isDraggable} + dragImageAnchor={p.dragImageAnchor} onCanvasBlur={p.onCanvasBlur} onCanvasFocused={p.onCanvasFocused} onCellFocused={p.onCellFocused} diff --git a/packages/core/src/internal/data-grid/data-grid.tsx b/packages/core/src/internal/data-grid/data-grid.tsx index 52338a786..9c949d711 100644 --- a/packages/core/src/internal/data-grid/data-grid.tsx +++ b/packages/core/src/internal/data-grid/data-grid.tsx @@ -189,6 +189,13 @@ export interface DataGridProps { * @group Drag and Drop */ readonly isDraggable: boolean | "cell" | "header" | undefined; + + /** + * Determines, when dragging, where the cursor is anchored to the drag image. + * @defaultValue 'center' + * @group Drag and Drop + */ + readonly dragImageAnchor: 'center' | 'click' | 'click-x' | 'click-y' | undefined; /** * If `isDraggable` is set, the grid becomes HTML draggable, and `onDragStart` will be called when dragging starts. * You can use this to build a UI where the user can drag the Grid around. @@ -390,6 +397,7 @@ const DataGrid: React.ForwardRefRenderFunction = (p, experimental, getCellRenderer, resizeIndicator = "full", + dragImageAnchor = "center" } = p; const translateX = p.translateX ?? 0; const translateY = p.translateY ?? 0; @@ -1566,10 +1574,13 @@ const DataGrid: React.ForwardRefRenderFunction = (p, document.body.append(offscreen); + const dragAnchorX = ['click', 'click-x'].includes(dragImageAnchor) ? event.clientX - boundsForDragTarget.x : boundsForDragTarget.width / 2 + const dragAnchorY = ['click', 'click-y'].includes(dragImageAnchor) ? event.clientY - boundsForDragTarget.y : boundsForDragTarget.height / 2 + event.dataTransfer.setDragImage( offscreen, - boundsForDragTarget.width / 2, - boundsForDragTarget.height / 2 + dragAnchorX, + dragAnchorY ); window.setTimeout(() => { diff --git a/packages/core/src/internal/scrolling-data-grid/scrolling-data-grid.tsx b/packages/core/src/internal/scrolling-data-grid/scrolling-data-grid.tsx index 1013c7ea9..e39bac877 100644 --- a/packages/core/src/internal/scrolling-data-grid/scrolling-data-grid.tsx +++ b/packages/core/src/internal/scrolling-data-grid/scrolling-data-grid.tsx @@ -312,6 +312,7 @@ const GridScroller: React.FunctionComponent = p => { gridRef={p.gridRef} headerIcons={p.headerIcons} isDraggable={p.isDraggable} + dragImageAnchor={p.dragImageAnchor} onCanvasBlur={p.onCanvasBlur} onCanvasFocused={p.onCanvasFocused} onCellFocused={p.onCellFocused}