From d7d56831bffc1f46564d2ee649c8a8d7ba321725 Mon Sep 17 00:00:00 2001 From: ndungtse Date: Thu, 22 Feb 2024 20:28:04 +0200 Subject: [PATCH] Fix: Corrected progress bar issue for mail/tel links and ignored other targets (#25) --- package.json | 2 +- src/AppProgressBar.tsx | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6be1d94..fdb8649 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next13-progressbar", - "version": "1.2.0", + "version": "1.2.1", "description": "A ProgressBar for next.js >=13 with app directory ", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/AppProgressBar.tsx b/src/AppProgressBar.tsx index a3d7835..fdf51f0 100644 --- a/src/AppProgressBar.tsx +++ b/src/AppProgressBar.tsx @@ -112,8 +112,9 @@ export const Next13ProgressBar = React.memo( const handleAnchorClick = (event: MouseEvent) => { const anchorElement = event.currentTarget as HTMLAnchorElement; - // Skip anchors with target="_blank" - if (anchorElement.target === '_blank') return; + // Skip anchors with target="_blank" | "_top" | "_parent" | "_self" + if (anchorElement.target === '_blank' || anchorElement.target === '_top' || anchorElement.target === '_parent') + return; // Skip anchors with download attribute if (anchorElement.hasAttribute('download')) return; @@ -138,8 +139,10 @@ export const Next13ProgressBar = React.memo( const handleMutation: MutationCallback = () => { const anchorElements = document.querySelectorAll('a'); - // Skip anchors with target="_blank" and anchors without href - const validAnchorELes = Array.from(anchorElements).filter((anchor) => anchor.href); + const validAnchorELes = Array.from(anchorElements).filter((anchor) => { + if (anchor.href.startsWith('tel:+') || anchor.href.startsWith('mailto:')) return false; + return anchor.href && anchor.target !== '_blank'; + }); validAnchorELes.forEach((anchor) => anchor.addEventListener('click', handleAnchorClick)); };