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,
handleBeforeContextMenu, handleContextMenu,
handleContextMenuClose, handleContextMenuHide,
} = useContextMenuHandlers(ref);
} = useContextMenuHandlers(ref, false, true);
const noAppearanceAnimation = appearanceOrder <= 0;
const [isShown, markShown] = useFlag(noAppearanceAnimation);

View File

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