Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 944598d

Browse files
committed
Handle permalinks in room topic
Fixes: element-hq/element-web#23395
1 parent a491795 commit 944598d

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/components/views/elements/RoomTopic.tsx

+18-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import MatrixClientContext from "../../../contexts/MatrixClientContext";
3131
import AccessibleButton from "./AccessibleButton";
3232
import TooltipTarget from "./TooltipTarget";
3333
import { Linkify, topicToHtml } from "../../../HtmlUtils";
34+
import { tryTransformPermalinkToLocalHref } from "../../../utils/permalinks/Permalinks";
3435

3536
interface IProps extends React.HTMLProps<HTMLDivElement> {
3637
room: Room;
@@ -46,12 +47,27 @@ export default function RoomTopic({ room, ...props }: IProps): JSX.Element {
4647
const onClick = useCallback(
4748
(e: React.MouseEvent<HTMLDivElement>) => {
4849
props.onClick?.(e);
50+
4951
const target = e.target as HTMLElement;
50-
if (target.tagName.toUpperCase() === "A") {
52+
53+
if (target.tagName.toUpperCase() !== "A") {
54+
dis.fire(Action.ShowRoomTopic);
55+
return;
56+
}
57+
58+
const anchor: HTMLLinkElement | null = e.target as HTMLLinkElement;
59+
60+
if (!anchor) {
5161
return;
5262
}
5363

54-
dis.fire(Action.ShowRoomTopic);
64+
const localHref = tryTransformPermalinkToLocalHref(anchor.href);
65+
66+
if (localHref !== anchor.href) {
67+
// it could be converted to a localHref -> therefore handle locally
68+
e.preventDefault();
69+
window.location.hash = localHref;
70+
}
5571
},
5672
[props],
5773
);

0 commit comments

Comments
 (0)