我无法使材料UI菜单
与反应表@v6
一起工作。
我希望能够右键单击表中的任何位置(行,td)并显示上下文菜单。这部分工作。
但我也希望能够连续右键单击表中的其他位置,并始终显示上下文菜单的光标位置。这不起作用。当前,您必须单击“离开”关闭菜单,然后再次右键单击以重新打开菜单。
在Material UI演示中,
https://material-ui.com/components/menus/#context-menu操作正常:
https://material-ui.com/components/menus/#context-menu
我采用了上面的例子来处理React表,但它并不像预期的那样工作。
我的示例采用:
https://codesandbox.io/s/aged-leaf-0NF6B?file=/src/index.js
有什么想法如何使它像示例中那样工作吗?
最后,我创建了一个popper上下文菜单,以复制菜单的所有material-ui行为。
import React from "react";
import Popper from "@material-ui/core/Popper";
import Typography from "@material-ui/core/Typography";
import MenuList from "@material-ui/core/MenuList";
import MenuItem from "@material-ui/core/MenuItem";
import Paper from "@material-ui/core/Paper";
import { makeStyles } from "@material-ui/core/styles";
import { ClickAwayListener, Fade } from "@material-ui/core";
/* copied from https://github.com/mui-org/material-ui/blob/v4.3.2/packages/material-ui/src/Menu/Menu.js#L21 */
const useMenuStyles = makeStyles({
/* Styles applied to the `Paper` component. */
paper: {
// specZ: The maximum height of a simple menu should be one or more rows less than the view
// height. This ensures a tapable area outside of the simple menu with which to dismiss
// the menu.
maxHeight: "calc(100% - 96px)",
// Add iOS momentum scrolling.
WebkitOverflowScrolling: "touch"
},
/* Styles applied to the `List` component via `MenuList`. */
list: {
// We disable the focus ring for mouse, touch and keyboard users.
outline: 0
}
});
export default function FakedReferencePopper() {
const [open, setOpen] = React.useState(false);
const [anchorEl, setAnchorEl] = React.useState<null | any>(null);
const handleClose = () => {
setOpen(false);
};
const handleContextMenu = (e) => {
e.preventDefault();
const { clientX, clientY } = e;
setOpen(true);
const virtualElement = {
getBoundingClientRect: () => ({
width: 0,
height: 0,
top: clientY,
right: clientX,
bottom: clientY,
left: clientX
})
};
setAnchorEl(virtualElement);
};
const id = open ? "faked-reference-popper" : undefined;
const menuClasses = useMenuStyles();
return (
<div>
<div onContextMenu={handleContextMenu}>
<Typography aria-describedby={id}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam ipsum
purus, bibendum sit amet vulputate eget, porta semper ligula. Donec
bibendum vulputate erat, ac fringilla mi finibus nec. Donec ac dolor
sed dolor porttitor blandit vel vel purus. Fusce vel malesuada ligula.
Nam quis vehicula ante, eu finibus est. Proin ullamcorper fermentum
orci, quis finibus massa. Nunc lobortis, massa ut rutrum ultrices,
metus metus finibus ex, sit amet facilisis neque enim sed neque.
Quisque accumsan metus vel maximus consequat. Suspendisse lacinia
tellus a libero volutpat maximus. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Nullam ipsum purus, bibendum sit amet
vulputate eget, porta semper ligula. Donec bibendum vulputate erat, ac
fringilla mi finibus nec. Donec ac dolor sed dolor porttitor blandit
vel vel purus. Fusce vel malesuada ligula. Nam quis vehicula ante, eu
finibus est. Proin ullamcorper fermentum orci, quis finibus massa.
Nunc lobortis, massa ut rutrum ultrices, metus metus finibus ex, sit
amet facilisis neque enim sed neque. Quisque accumsan metus vel
maximus consequat. Suspendisse lacinia tellus a libero volutpat
maximus. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nullam ipsum purus, bibendum sit amet vulputate eget, porta semper
ligula. Donec bibendum vulputate erat, ac fringilla mi finibus nec.
Donec ac dolor sed dolor porttitor blandit vel vel purus. Fusce vel
malesuada ligula. Nam quis vehicula ante, eu finibus est. Proin
ullamcorper fermentum orci, quis finibus massa. Nunc lobortis, massa
ut rutrum ultrices, metus metus finibus ex, sit amet facilisis neque
enim sed neque. Quisque accumsan metus vel maximus consequat.
Suspendisse lacinia tellus a libero volutpat maximus. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Nullam ipsum purus,
bibendum sit amet vulputate eget, porta semper ligula. Donec bibendum
vulputate erat, ac fringilla mi finibus nec. Donec ac dolor sed dolor
porttitor blandit vel vel purus. Fusce vel malesuada ligula. Nam quis
vehicula ante, eu finibus est. Proin ullamcorper fermentum orci, quis
finibus massa. Nunc lobortis, massa ut rutrum ultrices, metus metus
finibus ex, sit amet facilisis neque enim sed neque. Quisque accumsan
metus vel maximus consequat. Suspendisse lacinia tellus a libero
volutpat maximus. Lorem ipsum dolor sit amet, consectetur adipiscing
elit. Nullam ipsum purus, bibendum sit amet vulputate eget, porta
semper ligula. Donec bibendum vulputate erat, ac fringilla mi finibus
nec. Donec ac dolor sed dolor porttitor blandit vel vel purus. Fusce
vel malesuada ligula. Nam quis vehicula ante, eu finibus est. Proin
ullamcorper fermentum orci, quis finibus massa. Nunc lobortis, massa
ut rutrum ultrices, metus metus finibus ex, sit amet facilisis neque
enim sed neque. Quisque accumsan metus vel maximus consequat.
Suspendisse lacinia tellus a libero volutpat maximus. Lorem ipsum
dolor sit amet, consectetur adipiscing elit. Nullam ipsum purus,
bibendum sit amet vulputate eget, porta semper ligula. Donec bibendum
vulputate erat, ac fringilla mi finibus nec. Donec ac dolor sed dolor
porttitor blandit vel vel purus. Fusce vel malesuada ligula. Nam quis
vehicula ante, eu finibus est. Proin ullamcorper fermentum orci, quis
finibus massa. Nunc lobortis, massa ut rutrum ultrices, metus metus
finibus ex, sit amet facilisis neque enim sed neque. Quisque accumsan
metus vel maximus consequat. Suspendisse lacinia tellus a libero
volutpat maximus.
</Typography>
</div>
<Popper
id={id}
open={open}
anchorEl={anchorEl}
transition
placement="bottom-start"
>
{({ TransitionProps }) => (
<ClickAwayListener onClickAway={handleClose}>
<Fade {...TransitionProps}>
<Paper className={menuClasses.paper}>
<MenuList className={menuClasses.list} autoFocus>
<MenuItem onClick={handleClose}>Profile</MenuItem>
<MenuItem onClick={handleClose}>My account</MenuItem>
<MenuItem onClick={handleClose}>Logout</MenuItem>
</MenuList>
</Paper>
</Fade>
</ClickAwayListener>
)}
</Popper>
</div>
);
}
这里是codesandbox
https://codesandbox.io/s/popper-context-menu-t1u6r
这是因为您向Td添加了onContextMenu道具,而不是向table容器添加了onContextMenu道具。
将onContext菜单移动到container div,如下所示:
<div onContextMenu={(e) => {
e.preventDefault();
console.log("context menu");
this.setState({
mouseX: e.clientX - 2,
mouseY: e.clientY - 4
});
}}>
它应该会起作用的。
好好享受!
问题内容: 我在玩Material- ui。我使用路线实现了LeftNav,但找不到找到IconMenu或Menu来处理链接或路线的方法。任何人都可以为我指出一个好的资源/教程吗?该文档不足,并且两个组件似乎都不像LeftNav那样支持’menuItems’作为属性。 问题答案: 2016年12月编辑: 该道具已 弃用 ,您会收到警告: 因此,只需删除道具: 这是示例存储库,以及此处的实时演示。
我还在学习酶和材料的反应。 我有一个包含Material-ui的TextField的组件,我想对以下情况进行单元测试。 当用户在屏幕上的文本字段上输入字符串“123”时,文本字段应将“错误”设置为“true”,并显示消息“错误的名称格式”。 成分 单元测试 我得到以下错误。错误:期望(收到). toBe(期望)//Object.is相等 预期:true收到:false 我做错了什么吗?
我第一次学习材料界面。我想自定义材质UI的文本字段。当文本字段未被选中时,我可以更改其样式;当文本字段聚焦时,我无法更改其样式。我正在使用将样式注入组件。我试过这个密码 问题: 如何更改焦点文本字段的样式?我们将不胜感激
问题内容: 给定以下用例: 我使用D3js渲染由AngularJS管理的对象。我想向D3图表添加交互性。当单击svg元素时,我希望有一种弹出菜单允许修改对象属性。这些属性是AngularJS必需的,但不是D3呈现的。 D3-Angular集成源自使用闭包的http://bl.ocks.org/biovisualize/5372077。 当前实施: 从今天开始,我正在使用angular-ui引导程序
我在Visual Studio C#IDE中定义了一个ContextMenuStri上下文菜单,并对程序进行编码,以便当用户右键单击屏幕上的一个对象时,上下文菜单成功弹出。用户可以从上下文菜单中选择一个项目,代码成功确定用户选择了哪个上下文菜单项。到目前为止还不错。问题是上下文菜单接受右键单击作为选择上下文菜单项的机制。当我不小心双击右键单击屏幕上的一个对象时,我注意到了这一点...菜单在第一次单
无法使用SafariDriver Selenium在Safari浏览器中打开上下文菜单。获得以下异常: org . open QA . selenium . web Driver exception:未知命令:< br> {"id":"az1mvyq9x4ly "," name":"mouseMoveTo "," parameters ":< br > { " element ":":wdc:14