Welcome to the JavaScript feedback portal. We’re happy you’re here! If you have feedback on how to improve the JavaScript, we’d love to hear it!

  • Check out the features or bugs others have reported and vote on your favorites. Feedback will be prioritized based on popularity.
  • If you have feedback that’s not listed yet, submit your own.

Thanks for joining our community and helping improve Syncfusion products!

0
Votes

It looks like this has been reported before (against the Angular version), but you provided the reporter with a work-around and didn't fix the actual example code in your documentation. See here for previous report.

Running your documented example (directly in the documentation or via stackblitz) then if a user right-clicks on a node without having left-clicked on any node then an error is thrown of "Cannot read properties of null (reading 'classList')" (because no tree node is actually selected before the context menu is shown). If the user left-clicks on a node and then right-clicks on a different node the right click's context is the previous node (because right-clicking does not select the node and the context menu hook reads the currently selected node).

I can see that your example has a "nodeClick" function which is passed as the nodeClicked property on the treeview which would change the currently selected node on right-click if it was called when the user right-clicked on a node. However nodeClicked doesn't seem to fire when performing right-click on the treeview. My theory is that when this documentation How To example was written the TreeView nodeClicked event fired on right-click as well as left-click (and indeed I can see in the TreeView's clickHandler method that it would set isRightClick if it was responding to a right click, so it must have been written to handle right-clicks originally), but then perhaps at some point the way that nodeClicked was wired in was changed such that it doesn't fire for right-clicks any more (perhaps when abstracting to touch events rather than mouse events?).

So perhaps the underlying bug is that TreeView's nodeClicked event is not firing on right-clicks, only on left-clicks when the original intend was firing in response to both types of click? I suspect if you fixed it such that nodeClicked did fire on right-clicks as well as left-clicks then the treeview-context-menu example would start working properly. However if the intention at present is that the nodeClicked event will only fire on left-clicks and never on right-clicks then your example of hooking into context menu into TreeView is bugged as per my description earlier and, in my humble opinion, needs correcting!