@@ -4,7 +4,7 @@ import Box from "@mui/material/Box";
4
4
import Button from "@mui/material/Button" ;
5
5
import Menu from "@mui/material/Menu" ;
6
6
import MenuItem from "@mui/material/MenuItem" ;
7
- import { useState , MouseEvent } from "react" ;
7
+ import { useState , useRef } from "react" ;
8
8
9
9
export const insightsIntervals = {
10
10
day : {
@@ -24,35 +24,42 @@ export const IntervalMenu = ({
24
24
value : InsightsInterval ;
25
25
onChange : ( value : InsightsInterval ) => void ;
26
26
} ) => {
27
- const [ anchorEl , setAnchorEl ] = useState < null | HTMLElement > ( null ) ;
28
- const open = Boolean ( anchorEl ) ;
29
- const handleClick = ( event : MouseEvent < HTMLButtonElement > ) => {
30
- setAnchorEl ( event . currentTarget ) ;
31
- } ;
27
+ const anchorRef = useRef < HTMLButtonElement > ( null ) ;
28
+ const [ open , setOpen ] = useState ( false ) ;
29
+
32
30
const handleClose = ( ) => {
33
- setAnchorEl ( null ) ;
31
+ setOpen ( false ) ;
34
32
} ;
35
33
36
34
return (
37
35
< div >
38
36
< Button
37
+ ref = { anchorRef }
39
38
id = "interval-button"
40
39
aria-controls = { open ? "interval-menu" : undefined }
41
40
aria-haspopup = "true"
42
41
aria-expanded = { open ? "true" : undefined }
43
- onClick = { handleClick }
42
+ onClick = { ( ) => setOpen ( true ) }
44
43
endIcon = { < ExpandMoreOutlined /> }
45
44
>
46
45
{ insightsIntervals [ value ] . label }
47
46
</ Button >
48
47
< Menu
49
48
id = "interval-menu"
50
- anchorEl = { anchorEl }
49
+ anchorEl = { anchorRef . current }
51
50
open = { open }
52
51
onClose = { handleClose }
53
52
MenuListProps = { {
54
53
"aria-labelledby" : "interval-button" ,
55
54
} }
55
+ anchorOrigin = { {
56
+ vertical : "bottom" ,
57
+ horizontal : "left" ,
58
+ } }
59
+ transformOrigin = { {
60
+ vertical : "top" ,
61
+ horizontal : "left" ,
62
+ } }
56
63
>
57
64
{ Object . keys ( insightsIntervals ) . map ( ( interval ) => {
58
65
const { label } = insightsIntervals [ interval as InsightsInterval ] ;
0 commit comments