Handle permalinks in room topic (#11115)
* Handle permalinks in room topic Fixes: vector-im/element-web#23395 * Add test for clicking non-link
This commit is contained in:
parent
767cd628f9
commit
9d9c55d92e
2 changed files with 94 additions and 2 deletions
|
@ -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<HTMLDivElement> {
|
||||
room: Room;
|
||||
|
@ -46,12 +47,22 @@ export default function RoomTopic({ room, ...props }: IProps): JSX.Element {
|
|||
const onClick = useCallback(
|
||||
(e: React.MouseEvent<HTMLDivElement>) => {
|
||||
props.onClick?.(e);
|
||||
|
||||
const target = e.target as HTMLElement;
|
||||
if (target.tagName.toUpperCase() === "A") {
|
||||
|
||||
if (target.tagName.toUpperCase() !== "A") {
|
||||
dis.fire(Action.ShowRoomTopic);
|
||||
return;
|
||||
}
|
||||
|
||||
dis.fire(Action.ShowRoomTopic);
|
||||
const anchor = e.target as HTMLLinkElement;
|
||||
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],
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue