I know this answer comes a little late, but I recently ran into a similar problem. I wanted to trigger an event on a nested component. I had a list with widgets like “radio” and “checkbox” (they were divs that behaved like checkboxes and / or switches), and in some other place of the application, if someone closed the toolbar, I needed uncheck it.
I found a fairly simple solution, not sure if this is the best practice, but it works.
var event = new MouseEvent('click', { 'view': window, 'bubbles': true, 'cancelable': false }); var node = document.getElementById('nodeMyComponentsEventIsConnectedTo'); node.dispatchEvent(event);
This triggered a click event on domNode, and my handler connected through a reaction was actually called so that it behaves as I would expect if someone clicked on an element. I have not tested onChange, but it should work, and I'm not sure how this will be true in really old versions of IE, but I believe that MouseEvent is supported, at least in IE9 and higher.
In the end, I moved away from this for my specific use case, because my component was very small (only part of my application was used, since I'm still learning it), and I could achieve the same thing differently without getting links to dom.
UPDATE:
As other comments pointed out, it is better to use this.refs.refname to get a link to the dom node. In this case, refname is the link that you linked to your component via <MyComponent ref='refname' /> .
Robert-W Oct 20 '14 at 9:46 a.m. 2014-10-20 21:46
source share