Message: Allow system context menu for links (#1105)

This commit is contained in:
Alexander Zinchuk 2021-05-21 14:44:20 +03:00
parent 3520854116
commit 08cfbd9d25
2 changed files with 6 additions and 4 deletions

View File

@ -231,7 +231,7 @@ const Message: FC<OwnProps & StateProps & DispatchProps> = ({
isContextMenuOpen, contextMenuPosition, isContextMenuOpen, contextMenuPosition,
handleBeforeContextMenu, handleContextMenu, handleBeforeContextMenu, handleContextMenu,
handleContextMenuClose, handleContextMenuHide, handleContextMenuClose, handleContextMenuHide,
} = useContextMenuHandlers(ref); } = useContextMenuHandlers(ref, false, true);
const noAppearanceAnimation = appearanceOrder <= 0; const noAppearanceAnimation = appearanceOrder <= 0;
const [isShown, markShown] = useFlag(noAppearanceAnimation); const [isShown, markShown] = useFlag(noAppearanceAnimation);

View File

@ -17,6 +17,7 @@ function checkIsDisabledForMobile() {
export default ( export default (
elementRef: RefObject<HTMLElement>, elementRef: RefObject<HTMLElement>,
isMenuDisabled?: boolean, isMenuDisabled?: boolean,
shouldDisableOnLink?: boolean,
) => { ) => {
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false); const [isContextMenuOpen, setIsContextMenuOpen] = useState(false);
const [contextMenuPosition, setContextMenuPosition] = useState<IAnchorPosition | undefined>(undefined); const [contextMenuPosition, setContextMenuPosition] = useState<IAnchorPosition | undefined>(undefined);
@ -28,11 +29,12 @@ export default (
}, [isMenuDisabled]); }, [isMenuDisabled]);
const handleContextMenu = useCallback((e: React.MouseEvent) => { const handleContextMenu = useCallback((e: React.MouseEvent) => {
if (isMenuDisabled) { document.body.classList.remove('no-selection');
if (isMenuDisabled || (shouldDisableOnLink && (e.target as HTMLElement).matches('a.text-entity-link[href]'))) {
return; return;
} }
e.preventDefault(); e.preventDefault();
document.body.classList.remove('no-selection');
if (contextMenuPosition) { if (contextMenuPosition) {
return; return;
@ -45,7 +47,7 @@ export default (
setIsContextMenuOpen(true); setIsContextMenuOpen(true);
setContextMenuPosition({ x: e.clientX, y: e.clientY }); setContextMenuPosition({ x: e.clientX, y: e.clientY });
}, [isMenuDisabled, contextMenuPosition]); }, [isMenuDisabled, shouldDisableOnLink, contextMenuPosition]);
const handleContextMenuClose = useCallback(() => { const handleContextMenuClose = useCallback(() => {
setIsContextMenuOpen(false); setIsContextMenuOpen(false);