【发布时间】:2019-07-09 08:33:23
【问题描述】:
这里是material-uihttps://material-ui.com/utils/popover/#mouse-over-interaction的例子
对于示例 material-ui https://material-ui.com/utils/popover/#mouse-over-interaction,请按照以下步骤操作
在上面的例子中,将鼠标保持在文本
Hover with a Popover.--- 你看到popover试着把你的鼠标移到
popover附近——popover消失了对吧? 但即使我将鼠标悬停在popover 上,我也想显示弹出框
只有当用户没有悬停在popover 或Hover with a Popover.(基本上是anchorEl)上时才会使弹出框消失
我正在从他们的演示中复制代码
import React from 'react';
import PropTypes from 'prop-types';
import Popover from '@material-ui/core/Popover';
import Typography from '@material-ui/core/Typography';
import { withStyles } from '@material-ui/core/styles';
const styles = theme => ({
popover: {
pointerEvents: 'none',
},
paper: {
padding: theme.spacing.unit,
},
});
class MouseOverPopover extends React.Component {
state = {
anchorEl: null,
};
handlePopoverOpen = event => {
this.setState({ anchorEl: event.currentTarget });
};
handlePopoverClose = () => {
this.setState({ anchorEl: null });
};
render() {
const { classes } = this.props;
const { anchorEl } = this.state;
const open = Boolean(anchorEl);
return (
<div>
<Typography
aria-owns={open ? 'mouse-over-popover' : undefined}
aria-haspopup="true"
onMouseEnter={this.handlePopoverOpen}
onMouseLeave={this.handlePopoverClose}
>
Hover with a Popover.
</Typography>
<Popover
id="mouse-over-popover"
className={classes.popover}
classes={{
paper: classes.paper,
}}
open={open}
anchorEl={anchorEl}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'left',
}}
transformOrigin={{
vertical: 'top',
horizontal: 'left',
}}
onClose={this.handlePopoverClose}
disableRestoreFocus
>
<Typography>I use Popover.</Typography>
</Popover>
</div>
);
}
}
MouseOverPopover.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(MouseOverPopover);
我需要在此处进行哪些代码更改? 你可以试试https://codesandbox.io/s/6l3wk6kv3
【问题讨论】:
-
我不清楚你想要什么??你能解释一下你到底想要什么吗?
-
已更新。你现在可以检查吗?
-
我相信这个问题没有引起关注。如果你使用
onClick作为触发器,你会发现你实际上根本无法点击弹出框。
标签: javascript reactjs material-ui dom-events