Skip to content

fix: dropdown-menu #545

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion components/Navbar/navDrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ import links from '../../config/links.json';
import Link from 'next/link';
import Dropdown from '../illustration/dropdown';


const NavDrop = forwardRef((props, ref)=> {
const {setDrop}=props;
const [show, setShow] = useState(null);

const handleKeyDown = (event, linkTitle) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
show === linkTitle ? setShow(null) : setShow(linkTitle);
}
};

return (
<div ref ={ref} className='z-[99] absolute left-0 top-[74px] w-full h-screen bg-[#1B1130]/90 backdrop-filter backdrop-blur-md'>
<div className='flex flex-col p-5 pb-8 w-full'>
Expand All @@ -19,6 +26,8 @@ const NavDrop = forwardRef((props, ref)=> {
onClick={() =>
show === link.title ? setShow(null) : setShow(link.title)
}
tabIndex={0}
onKeyDown={(event) => handleKeyDown(event, link.title)}
>
{link.subMenu ? (
<div>
Expand All @@ -35,6 +44,7 @@ const NavDrop = forwardRef((props, ref)=> {
<div data-test={`nav-sub-${sub.title}`}
onClick={() => setDrop(false)}
className='h-[40px] flex navbg items-center p-6 hover:text-black text-white cursor-pointer'
tabIndex={0}
>
{sub.title}
</div>
Expand Down
11 changes: 10 additions & 1 deletion components/Navbar/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ function Navbar() {
setShow(null);
};

const handleKeyDown = (event, linkTitle) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
show === linkTitle ? setShow(null) : setShow(linkTitle);
}
};

return (
<div className="relative">
<div
Expand Down Expand Up @@ -114,8 +121,9 @@ function Navbar() {
onMouseLeave={handleMouseLeave}
className="ml-16 text-[14px] group cursor-pointer relative flex flex-col"
data-test={`nav-${link.title}`}
onKeyDown={(event) => handleKeyDown(event, link.title)}
>
<div>
<div tabIndex={0}>
{link.subMenu ? (
<div className="flex items-center">
{link.title}{" "}
Expand Down Expand Up @@ -150,6 +158,7 @@ function Navbar() {
<div
className={`flex items-center ${link.subMenu.length === 1 ? "justify-center" : "justify-start"} min-h-[32px] text-[16px] hover:scale-95 hover:translate-x-1 transition-all`}
data-test={`nav-sub-${subL.title}`}
tabIndex={0}
>
{subL.title}
</div>
Expand Down