Skip to content

Commit

Permalink
Always either one of click / tap handlers in menus
Browse files Browse the repository at this point in the history
Fixes mui#366.
  • Loading branch information
pomerantsev committed Apr 25, 2015
1 parent 23790d6 commit a06ffd1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 37 deletions.
8 changes: 2 additions & 6 deletions docs/src/app/components/pages/components/menus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var MenusPage = React.createClass({
" { payload: '2', text: 'Type', data: 'Announcement', icon: 'home' },\n" +
" { payload: '3', text: 'Caller ID', data: '(123) 456-7890', icon: 'home' }\n" +
"];\n\n" +
"//You can also pass an onItemTap or onItemClick callback prop.\n"
"//You can also pass an onItemClick callback prop.\n"
"<Menu menuItems={labelMenuItems} />";

return (
Expand Down Expand Up @@ -187,7 +187,7 @@ var MenusPage = React.createClass({
return (
<CodeExample code={code}>
<div className="example-menu-nested">
<mui.Menu menuItems={nestedMenuItems} onItemClick={this._onItemClick} onItemTap={this._onItemTap} />
<mui.Menu menuItems={nestedMenuItems} onItemClick={this._onItemClick} />
</div>
</CodeExample>
);
Expand All @@ -199,10 +199,6 @@ var MenusPage = React.createClass({

_onItemClick: function(e, key, menuItem) {
console.log("Menu Item Click: ", menuItem);
},

_onItemTap: function(e, key, menuItem) {
console.log("Menu Item Tap: ", menuItem);
}

});
Expand Down
10 changes: 2 additions & 8 deletions src/js/menu/menu-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var MenuItem = React.createClass({
data: React.PropTypes.string,
toggle: React.PropTypes.bool,
disabled: React.PropTypes.bool,
onTouchTap: React.PropTypes.func,
onClick: React.PropTypes.func,
onToggle: React.PropTypes.func,
selected: React.PropTypes.bool
Expand Down Expand Up @@ -73,8 +72,7 @@ var MenuItem = React.createClass({
<div
key={this.props.index}
className={classes}
onTouchTap={this._handleTouchTap}
onClick={this._handleOnClick}>
onTouchTap={this._handleClick}>

{icon}
{this.props.children}
Expand All @@ -88,11 +86,7 @@ var MenuItem = React.createClass({
);
},

_handleTouchTap: function(e) {
if (!this.props.disabled && this.props.onTouchTap) this.props.onTouchTap(e, this.props.index);
},

_handleOnClick: function(e) {
_handleClick: function(e) {
if (!this.props.disabled && this.props.onClick) this.props.onClick(e, this.props.index);
},

Expand Down
37 changes: 14 additions & 23 deletions src/js/menu/menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ var NestedMenuItem = React.createClass({
menuItems: React.PropTypes.array.isRequired,
zDepth: React.PropTypes.number,
disabled: React.PropTypes.bool,
onItemClick: React.PropTypes.func,
onItemTap: React.PropTypes.func
onItemClick: React.PropTypes.func
},

getDefaultProps: function() {
Expand Down Expand Up @@ -63,7 +62,6 @@ var NestedMenuItem = React.createClass({
ref="nestedMenu"
menuItems={this.props.menuItems}
onItemClick={this._onMenuItemClick}
onItemTap={this._onMenuItemTap}
hideable={true}
visible={this.state.open}
zDepth={this.props.zDepth + 1} />
Expand Down Expand Up @@ -97,13 +95,8 @@ var NestedMenuItem = React.createClass({
_onMenuItemClick: function(e, index, menuItem) {
if (this.props.onItemClick) this.props.onItemClick(e, index, menuItem);
this._closeNestedMenu();
},

_onMenuItemTap: function(e, index, menuItem) {
if (this.props.onItemTap) this.props.onItemTap(e, index, menuItem);
this._closeNestedMenu();
}

});


Expand Down Expand Up @@ -140,6 +133,12 @@ var Menu = React.createClass({
},

componentDidMount: function() {
if (process.env.NODE_ENV !== 'production' && this.props.onItemTap) {
var warning = 'onItemTap is deprecated and will be removed in future versions. ' +
'Please use onItemClick instead.';
console.warn(warning);
}

var el = React.findDOMNode(this);

//Set the menu width
Expand Down Expand Up @@ -227,8 +226,7 @@ var Menu = React.createClass({
disabled={isDisabled}
menuItems={menuItem.items}
zDepth={this.props.zDepth}
onItemClick={this._onNestedItemClick}
onItemTap={this._onNestedItemClick} />
onItemClick={this._onNestedItemClick} />
);
this._nestedChildren.push(i);
break;
Expand All @@ -246,8 +244,7 @@ var Menu = React.createClass({
number={menuItem.number}
toggle={menuItem.toggle}
disabled={isDisabled}
onClick={this._onItemClick}
onTouchTap={this._onItemTap}>
onClick={this._onItemClick}>
{menuItem.text}
</MenuItem>
);
Expand Down Expand Up @@ -301,19 +298,13 @@ var Menu = React.createClass({
},

_onNestedItemClick: function(e, index, menuItem) {
if (this.props.onItemClick) this.props.onItemClick(e, index, menuItem);
},

_onNestedItemTap: function(e, index, menuItem) {
if (this.props.onItemTap) this.props.onItemTap(e, index, menuItem);
var action = this.props.onItemClick || this.props.onItemTap;
if (action) action.call(this.props, e, index, menuItem);
},

_onItemClick: function(e, index) {
if (this.props.onItemClick) this.props.onItemClick(e, index, this.props.menuItems[index]);
},

_onItemTap: function(e, index) {
if (this.props.onItemTap) this.props.onItemTap(e, index, this.props.menuItems[index]);
var action = this.props.onItemClick || this.props.onItemTap;
if (action) action.call(this.props, e, index, this.props.menuItems[index]);
},

_onItemToggle: function(e, index, toggled) {
Expand Down

0 comments on commit a06ffd1

Please sign in to comment.