From 6044911501f5bab58bcb70e4c139c9b4e0856b02 Mon Sep 17 00:00:00 2001 From: Nathan Sarang-Walters Date: Mon, 11 Mar 2024 17:04:20 -0700 Subject: [PATCH] Only make PrairieLearn link active on homepage --- src/components/Header.tsx | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 851c05d..120b0ac 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -14,10 +14,12 @@ import { RequestCourseModal } from "../components/RequestCourseModal"; import styles from "./Header.module.scss"; -function useIsActive(href: string | string[]): boolean { +function useIsActive(href: string | string[], exact: boolean): boolean { const { asPath } = useRouter(); const hrefs = Array.isArray(href) ? href : [href]; - return hrefs.some((href) => asPath.startsWith(href)); + return hrefs.some((href) => + exact ? asPath === href : asPath.startsWith(href) + ); } function useIsCurrent(href: string): boolean { @@ -27,11 +29,12 @@ function useIsCurrent(href: string): boolean { interface NavLinkProps { href: string; + activeMatchExactHref?: boolean; children: React.ReactNode; } const RouterNavLink: React.FC = ({ href, children }) => { - const active = useIsActive(href); + const active = useIsActive(href, false); const current = useIsCurrent(href); return ( = ({ href, children }) => { ); }; -const NavDropdownItem: React.FC = ({ href, children }) => { - const active = useIsActive(href); +const NavDropdownItem: React.FC = ({ + href, + children, + activeMatchExactHref = false, +}) => { + const active = useIsActive(href, activeMatchExactHref); const current = useIsCurrent(href); return ( { Product - PrairieLearn + + PrairieLearn + PrairieTest