Skip to content

Commit ef3b2dd

Browse files
committed
Dropdown fixed
1 parent 93f2758 commit ef3b2dd

File tree

4 files changed

+38
-76
lines changed

4 files changed

+38
-76
lines changed

templerobotics.github.io/app/globals.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
--foreground: #171717;
2626
--foreground-hover: #4e4e4e;
2727
--primary: #9D2235;
28+
--primary-hover: #8D2235;
2829
}
2930

3031
/* Dark theme colors */
Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
1-
.menuItem {
2-
height: 25%;
3-
color: black;
4-
text-align: center;
5-
text-decoration: none;
1+
.dropdown {
2+
position: relative;
3+
display: inline-block;
4+
}
5+
6+
.dropdownMenu {
7+
display: none;
8+
position: absolute;
9+
z-index: 1;
10+
height: unset;
11+
}
12+
13+
.dropdown:hover .dropdownMenu {
614
display: block;
7-
border-bottom: 1px solid black;
815
}
916

1017
.dropdownLink {
11-
cursor: pointer;
1218
gap: 0;
1319
}
1420

15-
.title:hover {
21+
.menuItem {
22+
background-color: var(--primary);
1623
cursor: pointer;
24+
display: block;
25+
height: 3rem;
26+
display: flex;
27+
align-items: center;
28+
padding: 0 1rem;
1729
}
1830

19-
.popOverRoot {
20-
pointer-events: none;
21-
}
31+
.menuItem:hover {
32+
background-color: var(--primary-hover);
33+
}
34+
35+
.menuItem:last-child {
36+
border-bottom-left-radius: 8;
37+
border-bottom-right-radius: 8;
38+
}

templerobotics.github.io/components/navigation/DropDownMenu.tsx

Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import styles from './DropdownMenu.module.css'
33

44
import { useRouter } from 'next/navigation'
5-
import React, { useState } from 'react'
5+
import React from 'react'
66

7-
import { Link, Menu, MenuItem } from '@mui/material'
7+
import { Link } from '@mui/material'
88
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'
99

1010
type DropDownMenuProps = {
@@ -13,77 +13,21 @@ type DropDownMenuProps = {
1313
}
1414

1515
export default function DropdownMenu ({ title, items }: DropDownMenuProps): React.ReactElement {
16-
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
17-
let currentlyHovering = false;
1816
const router = useRouter()
1917

20-
const handleMouseOver = (event: React.MouseEvent<HTMLElement>) => {
21-
handleHover();
22-
if (anchorEl !== event.currentTarget) {
23-
setAnchorEl(event.currentTarget);
24-
}
25-
};
26-
27-
const handleClose = () => {
28-
setAnchorEl(null);
29-
};
30-
31-
const handleHover = () => {
32-
currentlyHovering = true;
33-
}
34-
35-
const handleCloseHover = () => {
36-
currentlyHovering = false;
37-
setTimeout(() => {
38-
if (!currentlyHovering) {
39-
handleClose();
40-
}
41-
}, 50);
42-
}
43-
4418
const handleClick = (path: string) => {
45-
handleClose();
4619
router.push(path);
4720
}
4821

4922
return (
50-
<div>
51-
<Link
52-
className={`flex-horizontal ${styles.dropdownLink}`}
53-
onClick={() => handleClick(title.path)}
54-
onMouseOver={handleMouseOver}
55-
onMouseLeave={handleCloseHover}>
56-
{title.text}
57-
<KeyboardArrowDownIcon fontSize='small' />
23+
<div className={styles.dropdown}>
24+
<Link className={`flex-horizontal ${styles.dropdownLink}`}>
25+
{title.text} <KeyboardArrowDownIcon fontSize='small'/>
5826
</Link>
5927

60-
<Menu
61-
id="simple-menu"
62-
anchorEl={anchorEl}
63-
open={Boolean(anchorEl)}
64-
onClose={handleClose}
65-
autoFocus={false}
66-
slotProps={{
67-
paper: {
68-
style: {
69-
borderTopLeftRadius: 0,
70-
borderTopRightRadius: 0
71-
}
72-
},
73-
list: {
74-
onMouseLeave: handleCloseHover,
75-
onMouseEnter: handleHover,
76-
style: {
77-
pointerEvents: 'auto',
78-
backgroundColor: 'var(--primary)'
79-
}
80-
}
81-
}}
82-
PopoverClasses={{
83-
root: styles.popOverRoot
84-
}}>
85-
{items.map((item, i) => <MenuItem key={i} className={styles.menuItem} onClick={() => handleClick(item.path)}>{item.text}</MenuItem>)}
86-
</Menu>
28+
<div className={styles.dropdownMenu}>
29+
{items.map((item, i) => <div key={i} className={styles.menuItem} onClick={() => handleClick(item.path)}>{item.text}</div>)}
30+
</div>
8731
</div>
8832
)
8933
}

templerobotics.github.io/components/navigation/NavBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import DropDownMenu from './DropdownMenu'
1010

1111
const dropDownItems = [
1212
{ text: 'Events', path: PATHS.EVENTS },
13-
{ text: 'Sponsors', path: PATHS.SPONSORS }
13+
{ text: 'ewfwfwfwewefwefwefew', path: PATHS.SPONSORS }
1414
]
1515

1616
export default function NavBar (): React.ReactElement {

0 commit comments

Comments
 (0)