From 981395e4d68a1c0cfccbdb8924bc11ac912d1e05 Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Sun, 7 Jul 2024 18:14:15 +0200 Subject: [PATCH] Remove the `title` attribute when hovering a card anchor (#30948) --- .../mastodon/components/hover_card_controller.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/javascript/mastodon/components/hover_card_controller.tsx b/app/javascript/mastodon/components/hover_card_controller.tsx index 5ca55ebde..057ef1aae 100644 --- a/app/javascript/mastodon/components/hover_card_controller.tsx +++ b/app/javascript/mastodon/components/hover_card_controller.tsx @@ -43,6 +43,7 @@ export const HoverCardController: React.FC = () => { useEffect(() => { let isScrolling = false; let currentAnchor: HTMLElement | null = null; + let currentTitle: string | null = null; const open = (target: HTMLElement) => { target.setAttribute('aria-describedby', 'hover-card'); @@ -75,6 +76,9 @@ export const HoverCardController: React.FC = () => { currentAnchor?.removeAttribute('aria-describedby'); currentAnchor = target; + currentTitle = target.getAttribute('title'); + target.removeAttribute('title'); + setEnterTimeout(() => { open(target); }, enterDelay); @@ -90,11 +94,20 @@ export const HoverCardController: React.FC = () => { }; const handleMouseLeave = (e: MouseEvent) => { + const { target } = e; + if (!currentAnchor) { return; } - if (e.target === currentAnchor || e.target === cardRef.current) { + if ( + currentTitle && + target instanceof HTMLElement && + target === currentAnchor + ) + target.setAttribute('title', currentTitle); + + if (target === currentAnchor || target === cardRef.current) { cancelEnterTimeout(); setLeaveTimeout(() => {