diff --git a/src/components/views/elements/RoomTopic.tsx b/src/components/views/elements/RoomTopic.tsx index 02a9bfe2d77c..9cbee3bdccad 100644 --- a/src/components/views/elements/RoomTopic.tsx +++ b/src/components/views/elements/RoomTopic.tsx @@ -31,6 +31,7 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext"; import AccessibleButton from "./AccessibleButton"; import TooltipTarget from "./TooltipTarget"; import { Linkify, topicToHtml } from "../../../HtmlUtils"; +import { tryTransformPermalinkToLocalHref } from "../../../utils/permalinks/Permalinks"; interface IProps extends React.HTMLProps { room: Room; @@ -46,12 +47,27 @@ export default function RoomTopic({ room, ...props }: IProps): JSX.Element { const onClick = useCallback( (e: React.MouseEvent) => { props.onClick?.(e); + const target = e.target as HTMLElement; - if (target.tagName.toUpperCase() === "A") { + + if (target.tagName.toUpperCase() !== "A") { + dis.fire(Action.ShowRoomTopic); + return; + } + + const anchor: HTMLLinkElement | null = e.target as HTMLLinkElement; + + if (!anchor) { return; } - dis.fire(Action.ShowRoomTopic); + const localHref = tryTransformPermalinkToLocalHref(anchor.href); + + if (localHref !== anchor.href) { + // it could be converted to a localHref -> therefore handle locally + e.preventDefault(); + window.location.hash = localHref; + } }, [props], );