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

Commit

Permalink
Unbreak in-app permalink tooltips (#9087)
Browse files Browse the repository at this point in the history
* Unbreak in-app permalink tooltips

Fixes: element-hq/element-web#22874
Signed-off-by: Johannes Marbach <johannesm@element.io>

* Appease the linter

* Fix the tests
  • Loading branch information
Johennes committed Jul 26, 2022
1 parent 60696d7 commit e28fd86
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/utils/tooltipify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ export function tooltipifyLinks(rootNodes: ArrayLike<Element>, ignoredNodes: Ele
const href = node.getAttribute("href");

const tooltip = <LinkWithTooltip tooltip={new URL(href, window.location.href).toString()}>
<span dangerouslySetInnerHTML={{ __html: node.outerHTML }} />
{ node.innerHTML }
</LinkWithTooltip>;

ReactDOM.render(tooltip, container);
node.parentNode.replaceChild(container, node);
node.replaceChildren(container);
containers.push(container);
tooltipified = true;
}
Expand Down
5 changes: 3 additions & 2 deletions test/utils/tooltipify-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ describe('tooltipify', () => {
const containers: Element[] = [];
tooltipifyLinks([root], [], containers);
expect(containers).toHaveLength(1);
const anchor = root.querySelector(".mx_TextWithTooltip_target a");
const anchor = root.querySelector("a");
expect(anchor?.getAttribute("href")).toEqual("/foo");
expect(anchor?.innerHTML).toEqual("click");
const tooltip = anchor.querySelector(".mx_TextWithTooltip_target");
expect(tooltip).toBeDefined();
});

it('ignores node', () => {
Expand Down

0 comments on commit e28fd86

Please sign in to comment.