Skip to content

Commit

Permalink
feat: dropdown on hover (#667)
Browse files Browse the repository at this point in the history
* feat: dropdown on hover

* fix: add timeout
  • Loading branch information
harshbutfairx authored Aug 22, 2024
1 parent 612cb22 commit 960d3a2
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions components/TopNav/TopNav.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client'

import { useEffect, useState } from 'react'
import { useEffect, useState, useRef } from 'react'
import { Button, Dialog, Popover } from '@headlessui/react'
import { Bars3Icon, XMarkIcon } from '@heroicons/react/24/outline'
import Image from 'next/image'
Expand Down Expand Up @@ -64,6 +64,22 @@ export default function TopNav() {
}
}, [pathname])

const [isOpen, setIsOpen] = useState(false);
const timeoutRef = useRef<NodeJS.Timeout | null>(null);

const handleMouseEnter = () => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
setIsOpen(true);
};

const handleMouseLeave = () => {
timeoutRef.current = setTimeout(() => {
setIsOpen(false);
}, 1);
};

return (
<div className="fixed left-0 right-0 z-30">

Expand Down Expand Up @@ -93,10 +109,21 @@ export default function TopNav() {
<span className="text-[17.111px] font-medium">SigNoz</span>
</Link>
<Popover.Group className="hidden items-center gap-x-6 lg:flex">
<Dropdown>
<div
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>

<Dropdown isOpen={isOpen}>
<DropdownTrigger>
<Button
className="truncate px-1.5 py-1 text-sm font-normal hover:text-signoz_robin-500"
onMouseEnter={() => {
setIsOpen(true);
}}
onMouseLeave={() => {
setIsOpen(false);
}}
>
<div className='flex items-center'>

Expand Down Expand Up @@ -192,6 +219,7 @@ export default function TopNav() {
</DropdownItem>
</DropdownMenu>
</Dropdown>
</div>

<Link
href="/docs"
Expand Down

0 comments on commit 960d3a2

Please sign in to comment.