Skip to content

Commit

Permalink
Prevent selection on right-button click or with Ctrl pressed on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw committed Dec 1, 2022
1 parent 6ca04ac commit c3d45b0
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ export const useGridCellSelection = (
useGridApiMethod(apiRef, cellSelectionApi, 'public');

const handleCellMouseDown = React.useCallback<GridEventListener<'cellMouseDown'>>(
(params) => {
(params, event) => {
// Skip if the click comes from the right-button or, only on macOS, Ctrl is pressed
// Fix for https://github.com/mui/mui-x/pull/6567#issuecomment-1329155578
const isMacOs = window.navigator.platform.toUpperCase().indexOf('MAC') >= 0;
if (event.button !== 0 || (event.ctrlKey && isMacOs)) {
return;
}

lastMouseDownCell.current = { id: params.id, field: params.field };
apiRef.current.rootElementRef?.current?.classList.add(
gridClasses['root--disableUserSelection'],
Expand All @@ -171,7 +178,7 @@ export const useGridCellSelection = (
[apiRef],
);

const handleCellMouseUp = React.useCallback<GridEventListener<'cellMouseDown'>>(() => {
const handleCellMouseUp = React.useCallback<GridEventListener<'cellMouseUp'>>(() => {
lastMouseDownCell.current = null;
apiRef.current.rootElementRef?.current?.classList.remove(
gridClasses['root--disableUserSelection'],
Expand Down

0 comments on commit c3d45b0

Please sign in to comment.