Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» finish loader on click to new tab (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredkiss3 authored Jan 5, 2024
1 parent 42fe696 commit c0f001a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/top-loader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit c0f001a

Please sign in to comment.