Im trying out material-ui
and react
and I'm running into an issue with events not firing. I have installed the react-tap-event-plugin
and I call injectTapEventPlugin()
while bootstrapping the application.
toggleMenu
is never called in the following snippet:
/** @jsx React.DOM */ var React = require('react'); var mui = require('material-ui'); var LeftNav = mui.LeftNav; var MenuItem = mui.MenuItem; var AppBar = mui.AppBar; var App = React.createClass({ getInitialState: function () { return { message: 'Hello World!' }; }, toggleMenu: function () { console.log('clicked hamburger'); //<-- This is never fired this.refs.menu.toggle(); }, render: function() { var menuItems = [{ route: 'get-started', text: 'Get Started' }]; return ( <div> <AppBar onMenuIconButtonTouchTap = {this.toggleMenu} title = "Hej" /> <LeftNav ref = "menu" docked = {false} menuItems = {menuItems} /> </div> ); } }); module.exports = App;
The full code example can be checked out from here: https://github.com/oskbor/lunch-mirror
Happy for any suggestions on what Im doing wrong!
Material UI is our favorite React UI library and to be honest there isn't even a second UI library for React that we can even recommend. It's extremely difficult to make a good UI library for a variety of reasons.
Using the components is simple. Just import the component from the library and render it like any other React component. The nice thing about the components is that they all contain their own styles, so there isn't a global CSS file that you have to worry about.
This is not patched to include the touchTap events, so no touchTap event was ever actually getting fired, because the React that you were including was not properly getting patched. Thanks for contributing an answer to Stack Overflow!
How to Use Material UI Documentation. On the Material UI site, click the upper left menu and you'll see a sidebar. We'll first talk about the two sections: Components and Component API. The main difference between these 2 sections is that the Components section contains examples/demos and explanations for each component while ...
So, I was not able to determine why this is the cause, but I think the problem is how you are splitting your build into 2 separate files.
If I change up your GulpFile to exclude the building of vendors.js
and remove the line
appBundler.external(options.development ? dependencies : []);
it will build a single js file with all the dependencies in it and everything works as expected.
My theory on why:
When you remove the dependencies from the main.js
bundle, the main bundle ends up including just what it needs, which includes just the small pieces of React that the tap-event plugin needs. react/lib/SyntheticUIEvent
, etc. So, those small pieces get patched to include the touchTap events.
But, in the vendors bundle, you have the full React, which is what you require in your app. This is not patched to include the touchTap events, so no touchTap event was ever actually getting fired, because the React that you were including was not properly getting patched.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With