@@ -507,7 +507,12 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
507507 ) ;
508508
509509 const getMouseArgsForPosition = React . useCallback (
510- ( canvas : HTMLCanvasElement , posX : number , posY : number , ev ?: MouseEvent | TouchEvent ) : GridMouseEventArgs => {
510+ (
511+ canvas : HTMLCanvasElement ,
512+ posX : number ,
513+ posY : number ,
514+ ev ?: PointerEvent | MouseEvent | TouchEvent
515+ ) : GridMouseEventArgs => {
511516 const rect = canvas . getBoundingClientRect ( ) ;
512517 const scale = rect . width / width ;
513518 const x = ( posX - rect . left ) / scale ;
@@ -518,7 +523,16 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
518523
519524 let button = 0 ;
520525 let buttons = 0 ;
521- if ( ev instanceof MouseEvent ) {
526+
527+ const isMouse =
528+ ( typeof PointerEvent !== "undefined" && ev instanceof PointerEvent && ev . pointerType === "mouse" ) ||
529+ ( typeof MouseEvent !== "undefined" && ev instanceof MouseEvent ) ;
530+
531+ const isTouch =
532+ ( typeof PointerEvent !== "undefined" && ev instanceof PointerEvent && ev . pointerType === "touch" ) ||
533+ ( typeof TouchEvent !== "undefined" && ev instanceof TouchEvent ) ;
534+
535+ if ( isMouse ) {
522536 button = ev . button ;
523537 buttons = ev . buttons ;
524538 }
@@ -544,7 +558,6 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
544558 const shiftKey = ev ?. shiftKey === true ;
545559 const ctrlKey = ev ?. ctrlKey === true ;
546560 const metaKey = ev ?. metaKey === true ;
547- const isTouch = ( ev !== undefined && ! ( ev instanceof MouseEvent ) ) || ( ev as any ) ?. pointerType === "touch" ;
548561
549562 const scrollEdge : GridMouseEventArgs [ "scrollEdge" ] = [
550563 x < 0 ? - 1 : width < x ? 1 : 0 ,
@@ -1037,22 +1050,16 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
10371050 const downTime = React . useRef ( 0 ) ;
10381051 const downPosition = React . useRef < Item > ( ) ;
10391052 const mouseDown = React . useRef ( false ) ;
1040- const onMouseDownImpl = React . useCallback (
1041- ( ev : MouseEvent | TouchEvent ) => {
1053+ const onPointerDown = React . useCallback (
1054+ ( ev : PointerEvent ) => {
10421055 const canvas = ref . current ;
10431056 const eventTarget = eventTargetRef ?. current ;
10441057 if ( canvas === null || ( ev . target !== canvas && ev . target !== eventTarget ) ) return ;
10451058 mouseDown . current = true ;
10461059
1047- let clientX : number ;
1048- let clientY : number ;
1049- if ( ev instanceof MouseEvent ) {
1050- clientX = ev . clientX ;
1051- clientY = ev . clientY ;
1052- } else {
1053- clientX = ev . touches [ 0 ] . clientX ;
1054- clientY = ev . touches [ 0 ] . clientY ;
1055- }
1060+ const clientX = ev . clientX ;
1061+ const clientY = ev . clientY ;
1062+
10561063 if ( ev . target === eventTarget && eventTarget !== null ) {
10571064 const bounds = eventTarget . getBoundingClientRect ( ) ;
10581065 if ( clientX > bounds . right || clientY > bounds . bottom ) return ;
@@ -1101,13 +1108,12 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
11011108 onMouseDown ,
11021109 ]
11031110 ) ;
1104- useEventListener ( "touchstart" , onMouseDownImpl , windowEventTarget , false ) ;
1105- useEventListener ( "mousedown" , onMouseDownImpl , windowEventTarget , false ) ;
1111+ useEventListener ( "pointerdown" , onPointerDown , windowEventTarget , false ) ;
11061112
11071113 const lastUpTime = React . useRef ( 0 ) ;
11081114
1109- const onMouseUpImpl = React . useCallback (
1110- ( ev : MouseEvent | TouchEvent ) => {
1115+ const onPointerUp = React . useCallback (
1116+ ( ev : PointerEvent ) => {
11111117 const lastUpTimeValue = lastUpTime . current ;
11121118 lastUpTime . current = Date . now ( ) ;
11131119 const canvas = ref . current ;
@@ -1116,21 +1122,9 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
11161122 const eventTarget = eventTargetRef ?. current ;
11171123
11181124 const isOutside = ev . target !== canvas && ev . target !== eventTarget ;
1119-
1120- let clientX : number ;
1121- let clientY : number ;
1122- let canCancel = true ;
1123- if ( ev instanceof MouseEvent ) {
1124- clientX = ev . clientX ;
1125- clientY = ev . clientY ;
1126- canCancel = ev . button < 3 ;
1127- if ( ( ev as any ) . pointerType === "touch" ) {
1128- return ;
1129- }
1130- } else {
1131- clientX = ev . changedTouches [ 0 ] . clientX ;
1132- clientY = ev . changedTouches [ 0 ] . clientY ;
1133- }
1125+ const clientX = ev . clientX ;
1126+ const clientY = ev . clientY ;
1127+ const canCancel = ev . pointerType === "mouse" ? ev . button < 3 : true ;
11341128
11351129 let args = getMouseArgsForPosition ( canvas , clientX , clientY , ev ) ;
11361130
@@ -1178,8 +1172,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
11781172 } ,
11791173 [ onMouseUp , eventTargetRef , getMouseArgsForPosition , isOverHeaderElement , groupHeaderActionForEvent ]
11801174 ) ;
1181- useEventListener ( "mouseup" , onMouseUpImpl , windowEventTarget , false ) ;
1182- useEventListener ( "touchend" , onMouseUpImpl , windowEventTarget , false ) ;
1175+ useEventListener ( "pointerup" , onPointerUp , windowEventTarget , false ) ;
11831176
11841177 const onClickImpl = React . useCallback (
11851178 ( ev : MouseEvent | TouchEvent ) => {
@@ -1284,7 +1277,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
12841277 } , [ getCellContent , getCellRenderer , hoveredItem ] ) ;
12851278
12861279 const hoveredRef = React . useRef < GridMouseEventArgs > ( ) ;
1287- const onMouseMoveImpl = React . useCallback (
1280+ const onPointerMove = React . useCallback (
12881281 ( ev : MouseEvent ) => {
12891282 const canvas = ref . current ;
12901283 if ( canvas === null ) return ;
@@ -1367,7 +1360,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
13671360 damageInternal ,
13681361 ]
13691362 ) ;
1370- useEventListener ( "mousemove " , onMouseMoveImpl , windowEventTarget , true ) ;
1363+ useEventListener ( "pointermove " , onPointerMove , windowEventTarget , true ) ;
13711364
13721365 const onKeyDownImpl = React . useCallback (
13731366 ( event : React . KeyboardEvent < HTMLCanvasElement > ) => {
0 commit comments