Skip to content

Commit

Permalink
Navlink merch store target fix (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscusagnew authored Jan 31, 2025
1 parent bba779a commit e21daba
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 22 deletions.
1 change: 1 addition & 0 deletions common/constants/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const getInvolved = {
const merchStore = {
name: 'Merch Store',
href: '/swag',
isExternal: true,
};

const jobs = {
Expand Down
17 changes: 14 additions & 3 deletions components/Nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Logo from 'public/static/images/logo.svg';
import { desktopNavItems, mobileNavItems } from 'common/constants/navigation';
import NavMobile from 'components/Nav/NavMobile/NavMobile';
import dynamic from 'next/dynamic';
import { twMerge } from 'tailwind-merge';
import UserLogo from '../../public/static/images/icons/FontAwesome/user.svg';
import styles from './Nav.module.css';

Expand Down Expand Up @@ -48,7 +49,10 @@ export const Nav = () => {
<nav data-testid="Desktop Nav">
<Link href="/" key="Home">
<a
className={classNames(styles.logoLink, styles.link)}
className={classNames(
styles.logoLink,
twMerge(styles.link, '[&>svg]:-bottom-2 [&>svg]:right-3'),
)}
onContextMenu={event => {
event.preventDefault();
Router.push('/branding');
Expand All @@ -58,7 +62,7 @@ export const Nav = () => {
</a>
</Link>

<ul className={styles.link}>
<ul className={twMerge(styles.link, '[&>svg]:-bottom-2 [&>svg]:right-3')}>
{desktopNavItems.map(navItem => (
<NavListItem
key={navItem.name}
Expand All @@ -74,7 +78,14 @@ export const Nav = () => {
{/* stylistic one-off */}
<li key="Donate">
<Link href="/donate">
<a className={classNames(styles.link, styles.donateLink)}>Donate</a>
<a
className={classNames(
twMerge(styles.link, '[&>svg]:-bottom-2 [&>svg]:right-3'),
styles.donateLink,
)}
>
Donate
</a>
</Link>
</li>
</ul>
Expand Down
47 changes: 32 additions & 15 deletions components/Nav/NavListItem/NavListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import classNames from 'classnames';
import Link from 'next/link';
import PlusIcon from 'static/images/icons/plus.svg';
import MinusIcon from 'static/images/icons/minus.svg';
import OutboundLink from 'components/OutboundLink/OutboundLink';
import { twMerge } from 'tailwind-merge';
import styles from './NavListItem.module.css';

type SublinkType = {
interface SublinkType {
name: string;
href: string;
};
isExternal?: boolean;
}

export type NavListItemPropsType = {
export interface NavListItemPropsType {
/**
* Text used for the label.
*/
Expand All @@ -27,7 +30,7 @@ export type NavListItemPropsType = {
* Includes an optional icon.
*/
icon?: React.ReactElement | null;
};
}

function NavListItem({ sublinks, href, name, icon = null }: NavListItemPropsType) {
const [areSublinksVisible, setSublinksVisible] = useState(false);
Expand Down Expand Up @@ -58,7 +61,10 @@ function NavListItem({ sublinks, href, name, icon = null }: NavListItemPropsType
<li className={styles.NavListItem}>
<Link href={href}>
<a
className={classNames(styles.link, styles.navItemLink)}
className={classNames(
twMerge(styles.link, '[&>svg]:-bottom-2 [&>svg]:right-3'),
styles.navItemLink,
)}
onMouseEnter={exposeSublinks}
onMouseLeave={hideSublinks}
role="link"
Expand Down Expand Up @@ -99,18 +105,29 @@ function NavListItem({ sublinks, href, name, icon = null }: NavListItemPropsType
{sublinks.map((sublink, index) => (
<li className={styles.sublinkListItem} key={sublink.name}>
{/* 😞 next/link fought being mocked, so `prefetch` has test-specific code */}
<Link href={sublink.href} prefetch={process.env.NODE_ENV === 'production'}>
<a
className={styles.link}
key={sublink.name}
role="link"
tabIndex={0}
{!sublink.isExternal ? (
<Link href={sublink.href} prefetch={process.env.NODE_ENV === 'production'}>
<a
className={twMerge(styles.link, '[&>svg]:-bottom-2 [&>svg]:right-3')}
role="link"
tabIndex={0}
data-testid={`Nav Item ${sublink.name}`}
onKeyDown={event => handleKeyDown(event, index)}
>
<span className={styles.linkContent}>{sublink.name}</span>
</a>
</Link>
) : (
<OutboundLink
analyticsEventLabel={`Clicked on ${sublink.name} -> ${sublink.href}`}
className={twMerge(styles.link, '[&>svg]:-bottom-2 [&>svg]:right-3')}
data-testid={`Nav Item ${sublink.name}`}
onKeyDown={event => handleKeyDown(event, index)}
href={sublink.href}
hasIcon
>
<span className={styles.linkContent}>{sublink.name}</span>
</a>
</Link>
<span className={twMerge(styles.link, '[&>svg]:-bottom-2 [&>svg]:right-3')}>{sublink.name}</span>
</OutboundLink>
)}
</li>
))}
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`NavListItem > should render with required props passed 1`] = `
href="/test"
>
<a
className="link navItemLink"
className="link [&>svg]:-bottom-2 [&>svg]:right-3 navItemLink"
data-testid="Nav Item Test"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
Expand Down
8 changes: 5 additions & 3 deletions components/Nav/__tests__/__snapshots__/Nav.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ exports[`Nav > should render with no props passed 1`] = `
},
{
"href": "/swag",
"isExternal": true,
"name": "Merch Store",
},
{
Expand Down Expand Up @@ -69,7 +70,7 @@ exports[`Nav > should render with no props passed 1`] = `
href="/"
>
<a
className="logoLink link"
className="logoLink link [&>svg]:-bottom-2 [&>svg]:right-3"
onContextMenu={[Function]}
>
<ForwardRef
Expand All @@ -85,7 +86,7 @@ exports[`Nav > should render with no props passed 1`] = `
</a>
</ForwardRef(LinkComponent)>
<ul
className="link"
className="link [&>svg]:-bottom-2 [&>svg]:right-3"
>
<ForwardRef(LoadableComponent)
href="/about"
Expand Down Expand Up @@ -153,6 +154,7 @@ exports[`Nav > should render with no props passed 1`] = `
},
{
"href": "/swag",
"isExternal": true,
"name": "Merch Store",
},
{
Expand All @@ -171,7 +173,7 @@ exports[`Nav > should render with no props passed 1`] = `
href="/donate"
>
<a
className="link donateLink"
className="link [&>svg]:-bottom-2 [&>svg]:right-3 donateLink"
>
Donate
</a>
Expand Down

0 comments on commit e21daba

Please sign in to comment.