Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #286 from deriv-com/nuzhy/active-nav-menu
Browse files Browse the repository at this point in the history
chore: active menu item
  • Loading branch information
prince-deriv authored Dec 26, 2023
2 parents 08b7672 + 9ae3d3b commit 517c59a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
22 changes: 16 additions & 6 deletions libs/blocks/src/lib/navigation/desktop/desktop.nav-item.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import React, { useEffect, useState } from 'react';
import { CustomLink } from '@deriv-com/components';
import { useLanguageSwitcher, useNavigation } from '@deriv-com/hooks';
import { NavItem } from '@deriv-com/providers';
import { Text } from '@deriv/quill-design';
import React from 'react';

export interface DesktopNavItemProps {
item: NavItem;
navItemName: string;
}

const removeTrailingSlash = (str: string) => {
return str.replace(/\/+$/, '');
};
export const DesktopNavItem: React.FC<DesktopNavItemProps> = ({
item,
navItemName,
}) => {
const { onListItemHover } = useNavigation();
const { setShowLangContent } = useLanguageSwitcher();

const [isActive, setIsActive] = useState(false);
useEffect(() => {
if (item.type === 'direct' && typeof window !== undefined) {
const { pathname } = window.location;
setIsActive(
removeTrailingSlash(pathname) === removeTrailingSlash(item.href),
);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
!item.isMobileNavOnly && (
<li
Expand All @@ -29,14 +39,15 @@ export const DesktopNavItem: React.FC<DesktopNavItemProps> = ({
>
{item.type === 'direct' ? (
<CustomLink
className="text-typography-default group-hover:text-typography-prominent"
className="text-typography-default group-hover:text-typography-prominent aria-[current=true]:text-typography-prominent"
href={item.href}
hasHoverDecoration={false}
onMouseEnter={() => {
setShowLangContent?.(false);
onListItemHover?.(navItemName);
}}
target={item.target}
aria-current={isActive}
>
{item.text}
</CustomLink>
Expand All @@ -52,5 +63,4 @@ export const DesktopNavItem: React.FC<DesktopNavItemProps> = ({
)
);
};

export default DesktopNavItem;
1 change: 1 addition & 0 deletions libs/blocks/src/lib/navigation/mobile/mobile.nav-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const MobileNavLink: React.FC<MobileNavLinkProps> = ({
href={item.href}
hasHoverDecoration={false}
className={qtMerge(
'text-typography-default',
'py-general-sm text-body-md font-bold leading-body-md',
'hover:text-typography-prominent',
className,
Expand Down
14 changes: 0 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 517c59a

Please sign in to comment.