Skip to content

Commit d7d5683

Browse files
committed
Fix: Corrected progress bar issue for mail/tel links and ignored other targets (#25)
1 parent ed57498 commit d7d5683

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "next13-progressbar",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "A ProgressBar for next.js >=13 with app directory ",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/AppProgressBar.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ export const Next13ProgressBar = React.memo(
112112
const handleAnchorClick = (event: MouseEvent) => {
113113
const anchorElement = event.currentTarget as HTMLAnchorElement;
114114

115-
// Skip anchors with target="_blank"
116-
if (anchorElement.target === '_blank') return;
115+
// Skip anchors with target="_blank" | "_top" | "_parent" | "_self"
116+
if (anchorElement.target === '_blank' || anchorElement.target === '_top' || anchorElement.target === '_parent')
117+
return;
117118

118119
// Skip anchors with download attribute
119120
if (anchorElement.hasAttribute('download')) return;
@@ -138,8 +139,10 @@ export const Next13ProgressBar = React.memo(
138139

139140
const handleMutation: MutationCallback = () => {
140141
const anchorElements = document.querySelectorAll('a');
141-
// Skip anchors with target="_blank" and anchors without href
142-
const validAnchorELes = Array.from(anchorElements).filter((anchor) => anchor.href);
142+
const validAnchorELes = Array.from(anchorElements).filter((anchor) => {
143+
if (anchor.href.startsWith('tel:+') || anchor.href.startsWith('mailto:')) return false;
144+
return anchor.href && anchor.target !== '_blank';
145+
});
143146
validAnchorELes.forEach((anchor) => anchor.addEventListener('click', handleAnchorClick));
144147
};
145148

0 commit comments

Comments
 (0)