admin管理员组文章数量:1221320
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:
Happy for any suggestions on what Im doing wrong!
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!
Share Improve this question edited Jul 17, 2015 at 17:51 Dheeraj Vepakomma 28.7k18 gold badges85 silver badges107 bronze badges asked Apr 26, 2015 at 18:08 oskboroskbor 1,59218 silver badges35 bronze badges1 Answer
Reset to default 17 +50So, 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.
本文标签: javascriptReacttap events and materialuiStack Overflow
版权声明:本文标题:javascript - React, tap events and material-ui - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739321134a2158039.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论