You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browser and OS versions: Google Chrome Version 61.0.3163.100 (Official Build) (64-bit)
Steps to reproduce
Create a react component annotated with @ContextMenuTarget hoc, implement any sample renderContextMenu() method (it doesn't matter), and implement a method like the following
You will see that this is undefined.
This is really bad since one probably needs to do something with the components props, like calling a callback injected by the parent component or redux.. etc..
Actual behavior
The HOC calls onContextMenuClose() but unbouded (no this)
Expected behavior
This should be the component instance.
I tried declaring the method as
onContextMenuClose = () => { }
And also binding it within the component constructor
Hi @javierfernandes, I didn't write this component, so I'm just delving into it for the first time. Zooming out, it seems like this is intentionally undefined inside JS decorators (discussion: wycats/javascript-decorators#72). If you want better control over what's going on, try the imperative API demonstrated in our Context Menu example:
/** * This component uses the imperative ContextMenu API. */
@PureRenderclassGraphNodeextendsReact.Component<{},{isContextMenuOpen: boolean}>{publicstate={isContextMenuOpen: false};publicrender(){constclasses=classNames("context-menu-node",{"context-menu-open": this.state.isContextMenuOpen});return<divclassName={classes}onContextMenu={this.showContextMenu}/>;}privateshowContextMenu=(e: React.MouseEvent<HTMLDivElement>)=>{// must prevent default to cancel parent's context menue.preventDefault();// invoke static API, getting coordinates from mouse eventContextMenu.show(<Menu><MenuItemiconName="search-around"text="Search around..."/><MenuItemiconName="search"text="Object viewer"/><MenuItemiconName="graph-remove"text="Remove"/><MenuItemiconName="group-objects"text="Group"/><MenuDivider/><MenuItemdisabled={true}text="Clicked on node"/></Menu>,{left: e.clientX,top: e.clientY},this.onContextMenuClose,);// indicate that context menu is open so we can add a CSS class to this elementthis.setState({isContextMenuOpen: true});};privateonContextMenuClose=()=>{this.setState({isContextMenuOpen: false});};}
Bug report
Steps to reproduce
Create a react component annotated with
@ContextMenuTarget
hoc, implement any samplerenderContextMenu()
method (it doesn't matter), and implement a method like the followingYou will see that
this
is undefined.This is really bad since one probably needs to do something with the components props, like calling a callback injected by the parent component or redux.. etc..
Actual behavior
The HOC calls onContextMenuClose() but unbouded (no this)
Expected behavior
This should be the component instance.
I tried declaring the method as
And also binding it within the component constructor
But still it doesn't work
The text was updated successfully, but these errors were encountered: