Skip to content

Commit 0ac9112

Browse files
author
annaha
committed
fix: add keyboard support for context menu
1 parent ab70423 commit 0ac9112

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

packages/core/src/internal/data-grid/data-grid.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,25 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
12631263
);
12641264
useEventListener("contextmenu", onContextMenuImpl, eventTargetRef?.current ?? null, false);
12651265

1266+
const onContextMenuWithKeyboardImpl = React.useCallback(
1267+
(ev: MouseEvent) => {
1268+
const canvas = ref.current;
1269+
const currentSelectedCell = selectionRef.current.current?.cell
1270+
if (canvas === null || onContextMenu === undefined || currentSelectedCell === undefined)
1271+
return;
1272+
const bounds = getBoundsForItem(canvas, ...currentSelectedCell);
1273+
if (bounds) {
1274+
const args = getMouseArgsForPosition(canvas, bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, ev);
1275+
onContextMenu(args, () => {
1276+
if (ev.cancelable) ev.preventDefault();
1277+
});
1278+
}
1279+
},
1280+
[getMouseArgsForPosition, onContextMenu, getBoundsForItem]
1281+
);
1282+
1283+
useEventListener("contextmenu", onContextMenuWithKeyboardImpl, ref?.current ?? null, false);
1284+
12661285
const onAnimationFrame = React.useCallback<StepCallback>(values => {
12671286
damageRegion.current = new CellSet(values.map(x => x.item));
12681287
hoverValues.current = values;

0 commit comments

Comments
 (0)