mirror of
https://github.com/danog/telegram-tt.git
synced 2024-12-02 17:48:34 +01:00
Message: Allow system context menu for links (#1105)
This commit is contained in:
parent
3520854116
commit
08cfbd9d25
@ -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);
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user