From c0f001af334e9e3190550419a293fbb917b79b85 Mon Sep 17 00:00:00 2001 From: Adrien KISSIE Date: Fri, 5 Jan 2024 17:50:39 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20finish=20lo?= =?UTF-8?q?ader=20on=20click=20to=20new=20tab=20(#123)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/top-loader.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/components/top-loader.tsx b/src/components/top-loader.tsx index db429044..669adf5b 100644 --- a/src/components/top-loader.tsx +++ b/src/components/top-loader.tsx @@ -20,5 +20,22 @@ function FinishingLoader() { React.useEffect(() => { NProgress.done(); }, [pathname, router, searchParams]); + React.useEffect(() => { + const linkClickListener = (ev: MouseEvent) => { + const element = ev.target as HTMLElement; + const closestlink = element.closest("a"); + const isOpenToNewTabClick = + ev.ctrlKey || + ev.shiftKey || + ev.metaKey || // apple + (ev.button && ev.button == 1); // middle click, >IE9 + everyone else + + if (closestlink && isOpenToNewTabClick) { + NProgress.done(); + } + }; + window.addEventListener("click", linkClickListener); + return () => window.removeEventListener("click", linkClickListener); + }, []); return null; }