Skip to content

Commit

Permalink
This fix issue #11
Browse files Browse the repository at this point in the history
  • Loading branch information
fkhadra committed May 18, 2017
1 parent 07f5f7b commit abf49d7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dist/ReactToastify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ReactToastify.min.js.map

Large diffs are not rendered by default.

31 changes: 20 additions & 11 deletions src/Component/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,22 @@ class ContextMenu extends Component {
eventManager.off(`display::${this.props.id}`);
}

hide = () => {
bindWindowEvent = () => {
window.addEventListener('resize', this.hide);
window.addEventListener('contextmenu', this.hide);
window.addEventListener('click', this.hide);
window.addEventListener('scroll', this.hide);
};

unBindWindowEvent = () => {
window.removeEventListener('resize', this.hide);
window.removeEventListener('contextmenu', this.hide);
window.removeEventListener('click', this.hide);
window.removeEventListener('scroll', this.hide);
};

hide = () => {
this.unBindWindowEvent();
this.setState({ visible: false });
};

Expand Down Expand Up @@ -114,7 +128,7 @@ class ContextMenu extends Component {
getMenuStyle() {
return {
left: this.state.x,
top: this.state.y,
top: this.state.y + 1,
opacity: 1
};
}
Expand All @@ -132,25 +146,21 @@ class ContextMenu extends Component {
}

show = e => {
e.stopPropagation();
const { x, y } = this.getMousePosition(e);
window.addEventListener('resize', this.hide);

this.bindWindowEvent();
this.setState({
visible: true,
x,
y,
target: e.target
}, this.setMenuPosition);

};

render() {
return this.state.visible
? <aside
className={cssClasses.CONTAINER}
onClick={this.hide}
onContextMenu={this.hide}
role="presentation"
>
?
<div
className={this.getMenuClasses()}
style={this.getMenuStyle()}
Expand All @@ -160,7 +170,6 @@ class ContextMenu extends Component {
{this.getMenuItem()}
</div>
</div>
</aside>
: null;
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/Component/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ class Item extends PureComponent {
leftIcon: '',
rightIcon: '',
disabled: false,
onClick: () => {},
onClick: () => {
},
target: {},
data: ''
};

handleClick = () => this.props.onClick(this.props.target, this.props.data);
handleClick = (e) => {
this.props.disabled
? e.stopPropagation()
: this.props.onClick(this.props.target, this.props.data);
};

buildItem() {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/scss/_menu.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.react-contexify-menu {
position: absolute;
position: fixed;
opacity: 0;
user-select: none;
background-color: #ffffff;
Expand Down
2 changes: 1 addition & 1 deletion src/scss/main.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@charset "UTF-8";

// Layout ------------------------------------------------------------ //
@import "container";
//@import "container";
@import 'menu';

//Themes ------------------------------------------------------------ //
Expand Down

0 comments on commit abf49d7

Please sign in to comment.