@@ -31,7 +31,7 @@ import {
31
31
BooleanIndeterminate ,
32
32
type FillHandleDirection ,
33
33
type EditListItem ,
34
- type CellActiviationBehavior ,
34
+ type CellActivationBehavior ,
35
35
} from "../internal/data-grid/data-grid-types.js" ;
36
36
import DataGridSearch , { type DataGridSearchProps } from "../internal/data-grid-search/data-grid-search.js" ;
37
37
import { browserIsOSX } from "../common/browser-detect.js" ;
@@ -78,6 +78,7 @@ import {
78
78
type GridDragEventArgs ,
79
79
mouseEventArgsAreEqual ,
80
80
type GridKeyEventArgs ,
81
+ type CellActivatedEventArgs ,
81
82
} from "../internal/data-grid/event-args.js" ;
82
83
import { type Keybinds , useKeybindingsWithDefaults } from "./data-editor-keybindings.js" ;
83
84
import type { Highlight } from "../internal/data-grid/render/data-grid-render.cells.js" ;
@@ -241,7 +242,7 @@ export interface DataEditorProps extends Props, Pick<DataGridSearchProps, "image
241
242
/** Emitted when a cell is activated, by pressing Enter, Space or double clicking it.
242
243
* @group Events
243
244
*/
244
- readonly onCellActivated ?: ( cell : Item ) => void ;
245
+ readonly onCellActivated ?: ( cell : Item , event : CellActivatedEventArgs ) => void ;
245
246
246
247
/**
247
248
* Emitted whenever the user initiats a pattern fill using the fill handle. This event provides both
@@ -663,7 +664,7 @@ export interface DataEditorProps extends Props, Pick<DataGridSearchProps, "image
663
664
* Determines when a cell is considered activated and will emit the `onCellActivated` event. Generally an activated
664
665
* cell will open to edit mode.
665
666
*/
666
- readonly cellActivationBehavior ?: CellActiviationBehavior ;
667
+ readonly cellActivationBehavior ?: CellActivationBehavior ;
667
668
668
669
/**
669
670
* Controls if focus will trap inside the data grid when doing tab and caret navigation.
@@ -771,6 +772,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
771
772
cell : Item ;
772
773
highlight : boolean ;
773
774
forceEditMode : boolean ;
775
+ activation : CellActivatedEventArgs ;
774
776
} > ( ) ;
775
777
const searchInputRef = React . useRef < HTMLInputElement | null > ( null ) ;
776
778
const canvasRef = React . useRef < HTMLCanvasElement | null > ( null ) ;
@@ -1431,7 +1433,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
1431
1433
) ;
1432
1434
1433
1435
const reselect = React . useCallback (
1434
- ( bounds : Rectangle , fromKeyboard : boolean , initialValue ?: string ) => {
1436
+ ( bounds : Rectangle , activation : CellActivatedEventArgs , initialValue ?: string ) => {
1435
1437
if ( gridSelection . current === undefined ) return ;
1436
1438
1437
1439
const [ col , row ] = gridSelection . current . cell ;
@@ -1466,8 +1468,9 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
1466
1468
cell : [ col , row ] ,
1467
1469
highlight : initialValue === undefined ,
1468
1470
forceEditMode : initialValue !== undefined ,
1471
+ activation,
1469
1472
} ) ;
1470
- } else if ( c . kind === GridCellKind . Boolean && fromKeyboard && c . readonly !== true ) {
1473
+ } else if ( c . kind === GridCellKind . Boolean && activation . inputType === "keyboard" && c . readonly !== true ) {
1471
1474
mangledOnCellsEdited ( [
1472
1475
{
1473
1476
location : gridSelection . current . cell ,
@@ -1502,6 +1505,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
1502
1505
highlight : true ,
1503
1506
cell : [ col , row ] ,
1504
1507
forceEditMode : true ,
1508
+ activation : { inputType : "keyboard" , key : "Enter" } ,
1505
1509
} ) ;
1506
1510
} ,
1507
1511
[ getMangledCellContent , scrollRef , setOverlaySimple ]
@@ -2058,6 +2062,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
2058
2062
mapper ,
2059
2063
lastRowSticky ,
2060
2064
setCurrent ,
2065
+ headerRowMarkerDisabled ,
2061
2066
setSelectedColumns ,
2062
2067
setGridSelection ,
2063
2068
onSelectionCleared ,
@@ -2387,8 +2392,16 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
2387
2392
}
2388
2393
}
2389
2394
if ( shouldActivate ) {
2390
- onCellActivated ?.( [ col - rowMarkerOffset , row ] ) ;
2391
- reselect ( a . bounds , false ) ;
2395
+ const act = a . isDoubleClick === true
2396
+ ? "double-click"
2397
+ : ( c . activationBehaviorOverride ?? cellActivationBehavior ) ;
2398
+ const activationEvent : CellActivatedEventArgs = {
2399
+ inputType : "pointer" ,
2400
+ pointerActivation : act ,
2401
+ pointerType : a . isTouch ? "touch" : "mouse" ,
2402
+ } ;
2403
+ onCellActivated ?.( [ col - rowMarkerOffset , row ] , activationEvent ) ;
2404
+ reselect ( a . bounds , activationEvent ) ;
2392
2405
return true ;
2393
2406
}
2394
2407
}
@@ -3265,8 +3278,12 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
3265
3278
void appendRow ( customTargetColumn ?? col ) ;
3266
3279
} , 0 ) ;
3267
3280
} else {
3268
- onCellActivated ?.( [ col - rowMarkerOffset , row ] ) ;
3269
- reselect ( bounds , true ) ;
3281
+ const activationEvent : CellActivatedEventArgs = {
3282
+ inputType : "keyboard" ,
3283
+ key : event . key ,
3284
+ } ;
3285
+ onCellActivated ?.( [ col - rowMarkerOffset , row ] , activationEvent ) ;
3286
+ reselect ( bounds , activationEvent ) ;
3270
3287
}
3271
3288
} else if ( gridSelection . current . range . height > 1 && isHotkey ( keys . downFill , event , details ) ) {
3272
3289
fillDown ( ) ;
@@ -3477,8 +3494,12 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
3477
3494
) {
3478
3495
return ;
3479
3496
}
3480
- onCellActivated ?.( [ col - rowMarkerOffset , row ] ) ;
3481
- reselect ( event . bounds , true , event . key ) ;
3497
+ const activationEvent : CellActivatedEventArgs = {
3498
+ inputType : "keyboard" ,
3499
+ key : event . key ,
3500
+ } ;
3501
+ onCellActivated ?.( [ col - rowMarkerOffset , row ] , activationEvent ) ;
3502
+ reselect ( event . bounds , activationEvent , event . key ) ;
3482
3503
event . stopPropagation ( ) ;
3483
3504
event . preventDefault ( ) ;
3484
3505
}
@@ -3543,7 +3564,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
3543
3564
formatted ?: string | string [ ]
3544
3565
) : EditListItem | undefined {
3545
3566
const stringifiedRawValue =
3546
- typeof rawValue === "object" ? rawValue ?. join ( "\n" ) ?? "" : rawValue ?. toString ( ) ?? "" ;
3567
+ typeof rawValue === "object" ? ( rawValue ?. join ( "\n" ) ?? "" ) : ( rawValue ?. toString ( ) ?? "" ) ;
3547
3568
3548
3569
if ( ! isInnerOnlyCell ( inner ) && isReadWriteCell ( inner ) && inner . readonly !== true ) {
3549
3570
const coerced = coercePasteValue ?.( stringifiedRawValue , inner ) ;
0 commit comments