Skip to content

Commit 8c5821c

Browse files
authored
getMouseArgsForPosition
1 parent 5983dca commit 8c5821c

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

Diff for: packages/core/API.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,16 @@ Details of each property can be found by clicking on it.
4545

4646
## Ref Methods
4747

48-
| Name | Description |
49-
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
50-
| [appendRow](#appendrow) | Append a row to the data grid. |
51-
| [emit](#emit) | Used to emit commands normally emitted by keyboard shortcuts. |
52-
| [focus](#focus) | Focuses the data grid. |
53-
| [getBounds](#getbounds) | Gets the current screen-space bounds of a desired cell. |
54-
| [remeasureColumns](#remeasureColumns) | Causes the columns in the selection to have their natural sizes recomputed and re-emitted as a resize event. |
55-
| [scrollTo](#scrollto) | Tells the data-grid to scroll to a particular location. |
56-
| [updateCells](#updatecells) | Invalidates the rendering of a list of passed cells. |
48+
| Name | Description |
49+
| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
50+
| [appendRow](#appendrow) | Append a row to the data grid. |
51+
| [emit](#emit) | Used to emit commands normally emitted by keyboard shortcuts. |
52+
| [focus](#focus) | Focuses the data grid. |
53+
| [getBounds](#getbounds) | Gets the current screen-space bounds of a desired cell. |
54+
| [remeasureColumns](#remeasureColumns) | Causes the columns in the selection to have their natural sizes recomputed and re-emitted as a resize event. |
55+
| [scrollTo](#scrollto) | Tells the data-grid to scroll to a particular location. |
56+
| [updateCells](#updatecells) | Invalidates the rendering of a list of passed cells. |
57+
| [getMouseArgsForPosition](#getMouseArgsForPosition) | Gets the mouse args from pointer event position. |
5758

5859
## Required Props
5960

Diff for: packages/core/src/data-editor/data-editor.tsx

+15
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ export interface DataEditorRef {
722722
* Causes the columns in the selection to have their natural size recomputed and re-emitted as a resize event.
723723
*/
724724
remeasureColumns: (cols: CompactSelection) => void;
725+
/**
726+
* Gets the mouse args from pointer event position.
727+
*/
728+
getMouseArgsForPosition: (posX: number, posY: number, ev?: MouseEvent | TouchEvent) => GridMouseEventArgs
725729
}
726730

727731
const loadingCell: GridCell = {
@@ -3912,6 +3916,17 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
39123916
void normalSizeColumn(col + rowMarkerOffset);
39133917
}
39143918
},
3919+
getMouseArgsForPosition: (posX: number, posY: number, ev?: MouseEvent | TouchEvent): GridMouseEventArgs => {
3920+
if (gridRef?.current === null) {
3921+
return undefined;
3922+
}
3923+
3924+
const args = gridRef.current.getMouseArgsForPosition(posX, posY, ev);
3925+
return {
3926+
...args, // FIXME: Mutate
3927+
location: [args.location[0] - rowMarkerOffset, args.location[1]] as any,
3928+
};
3929+
}
39153930
}),
39163931
[appendRow, normalSizeColumn, scrollRef, onCopy, onKeyDown, onPasteInternal, rowMarkerOffset, scrollTo]
39173932
);

Diff for: packages/core/src/internal/data-grid/data-grid.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,13 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
17081708
return getBoundsForItem(canvasRef.current, col ?? 0, row ?? -1);
17091709
},
17101710
damage,
1711+
getMouseArgsForPosition: (posX: number, posY: number, ev?: MouseEvent | TouchEvent) => {
1712+
if (canvasRef === undefined || canvasRef.current === null) {
1713+
return undefined;
1714+
}
1715+
1716+
return getMouseArgsForPosition(canvasRef.current, posX, posY, ev);
1717+
}
17111718
}),
17121719
[canvasRef, damage, getBoundsForItem]
17131720
);

0 commit comments

Comments
 (0)