Skip to content

Commit ad8a4ae

Browse files
committed
Interval menu position
1 parent a27af59 commit ad8a4ae

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

site/src/pages/TemplatePage/TemplateInsightsPage/IntervalMenu.tsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Box from "@mui/material/Box";
44
import Button from "@mui/material/Button";
55
import Menu from "@mui/material/Menu";
66
import MenuItem from "@mui/material/MenuItem";
7-
import { useState, MouseEvent } from "react";
7+
import { useState, useRef } from "react";
88

99
export const insightsIntervals = {
1010
day: {
@@ -24,35 +24,42 @@ export const IntervalMenu = ({
2424
value: InsightsInterval;
2525
onChange: (value: InsightsInterval) => void;
2626
}) => {
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+
3230
const handleClose = () => {
33-
setAnchorEl(null);
31+
setOpen(false);
3432
};
3533

3634
return (
3735
<div>
3836
<Button
37+
ref={anchorRef}
3938
id="interval-button"
4039
aria-controls={open ? "interval-menu" : undefined}
4140
aria-haspopup="true"
4241
aria-expanded={open ? "true" : undefined}
43-
onClick={handleClick}
42+
onClick={() => setOpen(true)}
4443
endIcon={<ExpandMoreOutlined />}
4544
>
4645
{insightsIntervals[value].label}
4746
</Button>
4847
<Menu
4948
id="interval-menu"
50-
anchorEl={anchorEl}
49+
anchorEl={anchorRef.current}
5150
open={open}
5251
onClose={handleClose}
5352
MenuListProps={{
5453
"aria-labelledby": "interval-button",
5554
}}
55+
anchorOrigin={{
56+
vertical: "bottom",
57+
horizontal: "left",
58+
}}
59+
transformOrigin={{
60+
vertical: "top",
61+
horizontal: "left",
62+
}}
5663
>
5764
{Object.keys(insightsIntervals).map((interval) => {
5865
const { label } = insightsIntervals[interval as InsightsInterval];

0 commit comments

Comments
 (0)