I am working on creating separate components for every utilities provided by Material UI using Redux framework.
I got stuck in creating Popover component.
The problem is that when I call the Popover Container, It flies from top-left corner of the screen. However when creating that same popover using plain react framework. Everything is working fine.
Snippet of code: Popover.js
class PopoverTip extends Component {
constructor(props) {
super(props);
}
handleRequestClose = () => {
this.props.togglePopover();
};
render() {
const { isOpen, anchorEl } = this.props;
return (
< div>
{isOpen && < Popover
open={isOpen}
anchorEl={anchorEl}
anchorOrigin={{horizontal: 'left', vertical: 'bottom'}}
targetOrigin={{horizontal: 'left', vertical: 'top'}}
animation={PopoverAnimationVertical}
onRequestClose={this.handleRequestClose}>
< Menu>
< MenuItem primaryText="Refresh" />
< MenuItem primaryText="Help & feedback" />
< MenuItem primaryText="Settings" />
< MenuItem primaryText="Sign out" />
</ Menu>
</ Popover>}
</ div>
);
}
}
export default PopoverTip;
ExampleComponent.js - from where I am calling the popover element and showing the popover
showPopover(event) {
event.preventDefault();
this.props.togglePopover(event.currentTarget);
};
<IconButton onClick={ this.showPopover.bind(this) }>
<HelpIco />
</IconButton>
<PopoverTip />
Please note that Popover functionality is working fine and I am also passing that event.currentTarget which is actually the current element.
The only issue I am facing is placement of that popover.
This is a bit late, but I just fixed this issue in my own project.
Because of a typo, I was passing undefined
to the anchorEl
prop of my <Popover>
component. Without a valid anchor, the Popover defaults to the top-left of the viewport, I believe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With