From 7cd8a5a2b230ac78c12cc40bddab10dcf9fce59f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 20 Jun 2018 18:01:37 +0100 Subject: [PATCH 1/3] allow chaining right click contextmenus Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/ContextualMenu.js | 26 +++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/components/structures/ContextualMenu.js b/src/components/structures/ContextualMenu.js index 91ec312f43e..e5b3bd0b71a 100644 --- a/src/components/structures/ContextualMenu.js +++ b/src/components/structures/ContextualMenu.js @@ -64,7 +64,9 @@ export default class ContextualMenu extends React.Component { // The component to render as the context menu elementClass: PropTypes.element.isRequired, // on resize callback - windowResize: PropTypes.func + windowResize: PropTypes.func, + // method to close menu + closeMenu: PropTypes.func, }; constructor() { @@ -73,6 +75,7 @@ export default class ContextualMenu extends React.Component { contextMenuRect: null, }; + this.onContextMenu = this.onContextMenu.bind(this); this.collectContextMenuRect = this.collectContextMenuRect.bind(this); } @@ -85,6 +88,25 @@ export default class ContextualMenu extends React.Component { }); } + onContextMenu(e) { + if (this.props.closeMenu) { + this.props.closeMenu(); + } + e.preventDefault(); + const x = e.clientX; + const y = e.clientY; + + setImmediate(() => { + const clickEvent = document.createEvent('MouseEvents'); + clickEvent.initMouseEvent( + 'contextmenu', true, true, window, 0, + 0, 0, x, y, false, false, + false, false, 0, null, + ); + document.elementFromPoint(x, y).dispatchEvent(clickEvent); + }); + } + render() { const position = {}; let chevronFace = null; @@ -195,7 +217,7 @@ export default class ContextualMenu extends React.Component { { chevron } - { props.hasBackground &&
} + { props.hasBackground &&
}
; } From 4508da56661a4e8bd80122ee1539bfddaf228449 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 20 Jun 2018 18:03:15 +0100 Subject: [PATCH 2/3] only override contextmenu if closeMenu is provided Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/ContextualMenu.js | 27 +++++++++++---------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/components/structures/ContextualMenu.js b/src/components/structures/ContextualMenu.js index e5b3bd0b71a..8b88cae479b 100644 --- a/src/components/structures/ContextualMenu.js +++ b/src/components/structures/ContextualMenu.js @@ -91,20 +91,21 @@ export default class ContextualMenu extends React.Component { onContextMenu(e) { if (this.props.closeMenu) { this.props.closeMenu(); + + e.preventDefault(); + const x = e.clientX; + const y = e.clientY; + + setImmediate(() => { + const clickEvent = document.createEvent('MouseEvents'); + clickEvent.initMouseEvent( + 'contextmenu', true, true, window, 0, + 0, 0, x, y, false, false, + false, false, 0, null, + ); + document.elementFromPoint(x, y).dispatchEvent(clickEvent); + }); } - e.preventDefault(); - const x = e.clientX; - const y = e.clientY; - - setImmediate(() => { - const clickEvent = document.createEvent('MouseEvents'); - clickEvent.initMouseEvent( - 'contextmenu', true, true, window, 0, - 0, 0, x, y, false, false, - false, false, 0, null, - ); - document.elementFromPoint(x, y).dispatchEvent(clickEvent); - }); } render() { From b23f84e1f53aacf0cc719857862f9dedfcdc8a2f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 22 Jun 2018 19:23:39 +0100 Subject: [PATCH 3/3] add XXX comment Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/ContextualMenu.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/structures/ContextualMenu.js b/src/components/structures/ContextualMenu.js index 8b88cae479b..adc8dfd11c2 100644 --- a/src/components/structures/ContextualMenu.js +++ b/src/components/structures/ContextualMenu.js @@ -96,6 +96,8 @@ export default class ContextualMenu extends React.Component { const x = e.clientX; const y = e.clientY; + // XXX: This isn't pretty but the only way to allow opening a different context menu on right click whilst + // a context menu and its click-guard are up without completely rewriting how the context menus work. setImmediate(() => { const clickEvent = document.createEvent('MouseEvents'); clickEvent.initMouseEvent(