Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use either one of click / tap handlers in menus #581

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -264,7 +264,7 @@ class MenusPage extends React.Component {
" { 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} autoWidth={false}/>";

return (
Expand Down Expand Up @@ -366,7 +366,7 @@ class MenusPage extends React.Component {
return (
<CodeExample code={code}>
<div style={this.getStyles().exampleMenuNested}>
<mui.Menu menuItems={nestedMenuItems} onItemClick={this._onItemClick} onItemTap={this._onItemTap} autoWidth={false}/>
<mui.Menu menuItems={nestedMenuItems} onItemClick={this._onItemClick} autoWidth={false}/>
</div>
</CodeExample>
);
Expand All @@ -380,10 +380,6 @@ class MenusPage extends React.Component {
console.log("Menu Item Click: ", menuItem);
}

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

}

MenusPage.contextTypes = {
Expand Down
16 changes: 5 additions & 11 deletions src/menu/menu-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ var MenuItem = React.createClass({
data: React.PropTypes.string,
toggle: React.PropTypes.bool,
disabled: React.PropTypes.bool,
onTouchTap: React.PropTypes.func,
onClick: React.PropTypes.func,
onItemClick: React.PropTypes.func,
onToggle: React.PropTypes.func,
selected: React.PropTypes.bool
},
Expand Down Expand Up @@ -136,7 +135,7 @@ var MenuItem = React.createClass({
if (this.props.toggle) {
var {
toggle,
onClick,
onItemClick,
onToggle,
onMouseOver,
onMouseOut,
Expand All @@ -152,8 +151,7 @@ var MenuItem = React.createClass({
<div
key={this.props.index}
className={this.props.className}
onTouchTap={this._handleTouchTap}
onClick={this._handleOnClick}
onTouchTap={this._handleClick}
onMouseOver={this._handleMouseOver}
onMouseOut={this._handleMouseOut}
style={this.mergeAndPrefix(
Expand All @@ -175,12 +173,8 @@ var MenuItem = React.createClass({
);
},

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

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

_handleToggle: function(e, toggled) {
Expand Down
36 changes: 14 additions & 22 deletions src/menu/menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ var NestedMenuItem = React.createClass({
disabled={this.props.disabled}
iconRightStyle={iconCustomArrowDropRight}
iconRightClassName="muidocs-icon-custom-arrow-drop-right"
onClick={this._onParentItemClick}>
onItemClick={this._onParentItemClick}>
{this.props.text}
</MenuItem>
<Menu {...other}
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 @@ -123,11 +122,6 @@ 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 @@ -176,6 +170,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 @@ -261,7 +261,7 @@ var Menu = React.createClass({
attribute,
number,
toggle,
onClick,
onItemClick,
...other
} = menuItem;

Expand Down Expand Up @@ -313,8 +313,7 @@ var Menu = React.createClass({
menuItems={menuItem.items}
menuItemStyle={this.props.menuItemStyle}
zDepth={this.props.zDepth}
onItemClick={this._onNestedItemClick}
onItemTap={this._onNestedItemClick} />
onItemClick={this._onNestedItemClick} />
);
this._nestedChildren.push(i);
break;
Expand All @@ -335,8 +334,7 @@ var Menu = React.createClass({
toggle={menuItem.toggle}
onToggle={this.props.onToggle}
disabled={isDisabled}
onClick={this._onItemClick}
onTouchTap={this._onItemTap}>
onItemClick={this._onItemClick}>
{menuItem.text}
</MenuItem>
);
Expand Down Expand Up @@ -390,19 +388,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