-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Fix view menu going off screen in some cases (#3731)"
This reverts commit f3e2223.
- Loading branch information
Showing
5 changed files
with
80 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,53 @@ | ||
import React from 'react' | ||
import React, { useState } from 'react' | ||
import { | ||
IconButton, | ||
IconButtonProps as IconButtonPropsType, | ||
SvgIconProps, | ||
} from '@mui/material' | ||
import CascadingMenuButton from '@jbrowse/core/ui/CascadingMenuButton' | ||
import MenuIcon from '@mui/icons-material/Menu' | ||
import { observer } from 'mobx-react' | ||
import { IBaseViewModel } from '@jbrowse/core/pluggableElementTypes/models/BaseViewModel' | ||
|
||
// icons | ||
import MenuIcon from '@mui/icons-material/Menu' | ||
import { Menu } from '@jbrowse/core/ui' | ||
|
||
const ViewMenu = observer(function ({ | ||
model, | ||
IconButtonProps, | ||
IconProps, | ||
}: { | ||
model: IBaseViewModel | ||
IconButtonProps: IconButtonPropsType | ||
IconProps: SvgIconProps | ||
}) { | ||
const items = model.menuItems() | ||
return items.length ? ( | ||
<CascadingMenuButton menuItems={items} data-testid="view_menu_icon"> | ||
<MenuIcon {...IconProps} /> | ||
</CascadingMenuButton> | ||
) : null | ||
const [anchorEl, setAnchorEl] = useState<HTMLElement>() | ||
|
||
if (!model.menuItems()?.length) { | ||
return null | ||
} | ||
|
||
return ( | ||
<> | ||
<IconButton | ||
{...IconButtonProps} | ||
aria-label="more" | ||
aria-controls="view-menu" | ||
aria-haspopup="true" | ||
onClick={event => setAnchorEl(event.currentTarget)} | ||
data-testid="view_menu_icon" | ||
> | ||
<MenuIcon {...IconProps} /> | ||
</IconButton> | ||
<Menu | ||
anchorEl={anchorEl} | ||
open={Boolean(anchorEl)} | ||
onMenuItemClick={(_, callback) => { | ||
callback() | ||
setAnchorEl(undefined) | ||
}} | ||
onClose={() => setAnchorEl(undefined)} | ||
menuItems={model.menuItems()} | ||
/> | ||
</> | ||
) | ||
}) | ||
|
||
export default ViewMenu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters