Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify nav link underline to match design #54

Merged
merged 4 commits into from
Dec 10, 2024
Merged

Conversation

jakewheeler
Copy link
Collaborator

@jakewheeler jakewheeler commented Nov 20, 2024

This PR updates the currently selected NavLink's underline to be offset, which more closely resembles the Figma design.
image

I've also created the useIsActive hook, which is used to check whether we are currently on a parent page or a child page of one of the parent pages.

For example, navigating to/products or /products/ecr-viewer should cause the "Our products" NavLink to be underlined now, as the Figma designs show.

@jakewheeler jakewheeler marked this pull request as ready for review November 21, 2024 14:24
Comment on lines 49 to 52
const pathSegments = pathname.split('/').filter((segment) => segment !== '');
if (pathSegments.length > 0 && url.toString().includes(pathSegments[0])) {
return true;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely open to suggestions here if there is a better way to handle this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this

function useIsActive(url: NavigationLinkProps['href']) {
  const pathname = usePathname();
  const urlStr = url.toString();
  return (
    pathname === urlStr ||
    (pathname.startsWith(urlStr) && (urlStr !== '/' || pathname === '/'))
  );
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I like it.

Comment on lines 49 to 52
const pathSegments = pathname.split('/').filter((segment) => segment !== '');
if (pathSegments.length > 0 && url.toString().includes(pathSegments[0])) {
return true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this

function useIsActive(url: NavigationLinkProps['href']) {
  const pathname = usePathname();
  const urlStr = url.toString();
  return (
    pathname === urlStr ||
    (pathname.startsWith(urlStr) && (urlStr !== '/' || pathname === '/'))
  );
}

@nickbristow nickbristow merged commit a574e24 into next Dec 10, 2024
1 check passed
@nickbristow nickbristow deleted the jw/nav-underline branch December 10, 2024 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants