{"action":"created","issue":{"url":"https://api.github.com/repos/vkbansal/react-contextmenu/issues/191","repository_url":"https://api.github.com/repos/vkbansal/react-contextmenu","labels_url":"https://api.github.com/repos/vkbansal/react-contextmenu/issues/191/labels{/name}","comments_url":"https://api.github.com/repos/vkbansal/react-contextmenu/issues/191/comments","events_url":"https://api.github.com/repos/vkbansal/react-contextmenu/issues/191/events","html_url":"https://github.com/vkbansal/react-contextmenu/issues/191","id":298422370,"number":191,"title":"connectMenu Silently Swallows Event (But it Would be Really Handy if it Passed it Along)","user":{"login":"machineghost","id":448908,"avatar_url":"https://avatars2.githubusercontent.com/u/448908?v=4","gravatar_id":"","url":"https://api.github.com/users/machineghost","html_url":"https://github.com/machineghost","followers_url":"https://api.github.com/users/machineghost/followers","following_url":"https://api.github.com/users/machineghost/following{/other_user}","gists_url":"https://api.github.com/users/machineghost/gists{/gist_id}","starred_url":"https://api.github.com/users/machineghost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/machineghost/subscriptions","organizations_url":"https://api.github.com/users/machineghost/orgs","repos_url":"https://api.github.com/users/machineghost/repos","events_url":"https://api.github.com/users/machineghost/events{/privacy}","received_events_url":"https://api.github.com/users/machineghost/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-02-19T22:56:03Z","updated_at":"2018-03-07T17:26:44Z","closed_at":null,"author_association":"NONE","body":"## Version\r\n1.9.1\r\n\r\n## Test Case\r\n\r\n    connectMenu(`foo)(MenuToConnect);\r\n\r\n## Steps to reproduce\r\n\r\nConnect a menu, trigger the menu, try to use the event that triggered the menu to decide what should be in the ContextMenu\r\n\r\n## Expected Behavior\r\n\r\nThe (dynamic, ie. connected via `connectMenu`) ContextMenu has access to the event that triggered the showing of it.\r\n\r\n## Actual Behavior\r\n\r\nAll that gets passed is:\r\n\r\n     <Child {...this.props} id={menuId} trigger={this.state.trigger} />;\r\n\r\nMeanwhile `e` gets lost back in `handleShow` (in https://github.com/vkbansal/react-contextmenu/blob/2ef4aae1aa624275f1c9f50d67417d39b2788d22/src/connectMenu.js).\r\n\r\nIt would be really nice if instead `handleShow` kept the event in state, then passed it to the `Child` when it rendered:\r\n\r\n            handleShow = (e) => {\r\n                // ...\r\n                this.setState({ e, trigger: filteredData }); // NOTE the added \"e, \"\r\n            }\r\n\r\n            handleHide = () => {\r\n                this.setState({ trigger: null });\r\n            }\r\n\r\n            render() {\r\n                return <Child {...this.props} e={this.state.e} id={menuId} trigger={this.state.trigger} />;\r\n            }\r\n        };\r\n\r\nThis way if I have fifty buttons on the page, instead of having to wrap each of them with a separate `<ContextMenuTrigger>`, I can just have one `<ContextMenuTrigger>` wrapping the lot of them, and then I can look at `e.target.id` (or `e.whatever`) to decide what options the resulting menu should offer.\r\n\r\nAlso this would eliminate many of the needs for nested triggers: instead of having to nest triggers one would only need the outermost trigger, which could then check the event to see if an inner (nested) element was responsible.\r\n\r\nI would be happy to submit a PR adding this functionality if desired."},"comment":{"url":"https://api.github.com/repos/vkbansal/react-contextmenu/issues/comments/371215773","html_url":"https://github.com/vkbansal/react-contextmenu/issues/191#issuecomment-371215773","issue_url":"https://api.github.com/repos/vkbansal/react-contextmenu/issues/191","id":371215773,"user":{"login":"machineghost","id":448908,"avatar_url":"https://avatars2.githubusercontent.com/u/448908?v=4","gravatar_id":"","url":"https://api.github.com/users/machineghost","html_url":"https://github.com/machineghost","followers_url":"https://api.github.com/users/machineghost/followers","following_url":"https://api.github.com/users/machineghost/following{/other_user}","gists_url":"https://api.github.com/users/machineghost/gists{/gist_id}","starred_url":"https://api.github.com/users/machineghost/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/machineghost/subscriptions","organizations_url":"https://api.github.com/users/machineghost/orgs","repos_url":"https://api.github.com/users/machineghost/repos","events_url":"https://api.github.com/users/machineghost/events{/privacy}","received_events_url":"https://api.github.com/users/machineghost/received_events","type":"User","site_admin":false},"created_at":"2018-03-07T17:26:44Z","updated_at":"2018-03-07T17:26:44Z","author_association":"NONE","body":"Philosophically I still see no reason why you wouldn't just do:\r\n\r\n    var originalEvent = theMouseDownEventThatTriggeredThings;\r\n\r\n    // then pass originalEvent into dispatchGlobalEvent and do:\r\n    event = new window.CustomEvent(eventName, { detail: opts, ... originalEvent });\r\n\r\n    // or maybe (since I'm not sure the above will work)\r\n    event = Object.assign(new window.CustomEvent(eventName, { detail: opts }), originalEvent);\r\n\r\nbut practically speaking providing the `target` alone would certainly handle my use case.\r\n\r\nThanks!\r\n"}}
{"actor":{"display_login":"machineghost"}}