Skip to content

Commit

Permalink
[feat]: handling target _black link -> not considered
Browse files Browse the repository at this point in the history
  • Loading branch information
ndungtse committed Jul 8, 2023
1 parent 5cd20f8 commit 656edac
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import Providers from './providers';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body className={inter.className}>
<body>
<Providers>{children}</Providers>
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"eslint": "8.43.0",
"eslint-config-next": "13.4.7",
"next": "13.4.7",
"next13-progressbar": "^0.1.2",
"next13-progressbar": "../",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.1.5"
Expand Down
4 changes: 1 addition & 3 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1506,10 +1506,8 @@ natural-compare@^1.4.0:
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==

next13-progressbar@^0.1.2:
next13-progressbar@../:
version "0.1.2"
resolved "https://registry.yarnpkg.com/next13-progressbar/-/next13-progressbar-0.1.2.tgz#4b7c846908c548dcb6948bb33120d81ef65c589c"
integrity sha512-6r3J/GFeTcVLkkBd615sutRUR1oLP341VLbXv+54S+7qzoB5q66pBMNq2VI5cT8hXjSKvVvHeSadUCpomFG4pw==
dependencies:
"@types/nprogress" "^0.2.0"
nprogress "^0.2.0"
Expand Down
5 changes: 4 additions & 1 deletion src/CLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export interface PLinkProps extends LinkProps {
export const CLink = (props: PLinkProps) => {
const pathname = usePathname();
const { setShowProgressBar } = useNProgress();
const newProps = { ...props };
delete newProps.children;
delete newProps.onClick;

const handleShowProgressBar = () => {
if (pathname !== props.href) {
Expand All @@ -23,7 +26,7 @@ export const CLink = (props: PLinkProps) => {
};

return (
<Link onClick={handleShowProgressBar} {...props}>
<Link onClick={handleShowProgressBar} {...newProps}>
{props.children}
</Link>
);
Expand Down
7 changes: 6 additions & 1 deletion src/NProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ export const NProvider = (props: NProviderProps) => {
useEffect(() => {
const anchors = document.querySelectorAll('a');
anchors.forEach((anchor) => {
anchor.addEventListener('click', () => {
anchor.addEventListener('click', (e) => {
if(anchor.target === '_blank') return;
// add prev onclick
if (anchor.onclick) {
anchor.onclick(e);
}
if (pathname !== anchor.href) {
setShowProgressBar(true);
}
Expand Down

0 comments on commit 656edac

Please sign in to comment.