Prevent native mobile context menu

This commit is contained in:
schroda
2025-06-10 22:09:02 +02:00
parent 3b0d91e4a6
commit 781d89a75a
4 changed files with 37 additions and 4 deletions

View File

@@ -7,7 +7,7 @@
*/
import useMediaQuery from '@mui/material/useMediaQuery';
import { Breakpoint } from '@mui/material/styles';
import { Breakpoint, SxProps, Theme } from '@mui/material/styles';
import { useCallback, useState } from 'react';
import { getCurrentTheme } from '@/modules/theme/services/ThemeCreator.ts';
import { ThemeMode } from '@/modules/theme/contexts/AppThemeContext.tsx';
@@ -112,4 +112,24 @@ export class MediaQuery {
return () => matchSystemThemeMode.removeEventListener('change', handleSystemThemeModeChange);
}
static usePreventMobileContextMenu() {
const isTouchDevice = MediaQuery.useIsTouchDevice();
return useCallback(
(e: React.MouseEvent<any, MouseEvent>) => {
if (isTouchDevice) {
e.preventDefault();
}
},
[isTouchDevice],
);
}
static preventMobileContextMenuSx(): SxProps<Theme> {
return {
userSelect: 'none',
'-webkit-touch-callout': 'none',
};
}
}