Skip to content

Commit

Permalink
Fix flickering menu position on-close; clean up shouldRender
Browse files Browse the repository at this point in the history
  • Loading branch information
bregenspan committed Apr 7, 2019
1 parent 682232f commit a8fa407
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions client/components/ContextMenu.jsx
@@ -1,12 +1,13 @@
/** @jsx h */
import {h, Component} from 'preact';
import {h} from 'preact';
import cls from 'classnames';
import PureComponent from '../lib/PureComponent';
import {store} from '../store';
import {elementIsOutside} from '../utils';

import s from './ContextMenu.css';

export default class ContextMenu extends Component {
export default class ContextMenu extends PureComponent {
constructor(props) {
super(props);
}
Expand All @@ -15,10 +16,6 @@ export default class ContextMenu extends Component {
this.boundingRect = this.node.getBoundingClientRect();
}

shouldComponentUpdate(nextProps) {
return this.props.visible || nextProps.visible;
}

componentDidUpdate(prevProps) {
if (this.props.visible && !prevProps.visible) {
document.addEventListener('mousedown', this.handleDocumentMousedown, true);
Expand Down Expand Up @@ -98,7 +95,10 @@ export default class ContextMenu extends Component {

getStyle() {
const {boundingRect} = this;
if (!this.props.visible || !boundingRect) return;

// Upon the first render of this component, we don't yet know
// its dimensions, so can't position it yet
if (!boundingRect) return;

const {coords} = this.props;

Expand Down

0 comments on commit a8fa407

Please sign in to comment.