Skip to content

Commit

Permalink
[ListItem] Disable hover styles on touch devices. Fixes #858
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Nguyen committed Jun 20, 2015
1 parent ccb6a92 commit 064e7e4
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/lists/list-item.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var ListItem = React.createClass({
leftIcon: React.PropTypes.element,
onMouseOut: React.PropTypes.func,
onMouseOver: React.PropTypes.func,
onTouchStart: React.PropTypes.func,
rightAvatar: React.PropTypes.element,
rightIcon: React.PropTypes.element,
rightIconButton: React.PropTypes.element,
Expand All @@ -39,7 +40,8 @@ var ListItem = React.createClass({
getInitialState: function() {
return {
hovered: false,
rightIconButtonHovered: false
rightIconButtonHovered: false,
touch: false
};
},

Expand All @@ -53,6 +55,7 @@ var ListItem = React.createClass({
leftIcon,
onMouseOut,
onMouseOver,
onTouchStart,
rightAvatar,
rightIcon,
rightIconButton,
Expand Down Expand Up @@ -212,6 +215,7 @@ var ListItem = React.createClass({
linkButton={true}
onMouseOut={this._handleMouseOut}
onMouseOver={this._handleMouseOver}
onTouchStart={this._handleTouchStart}
style={mergedRootStyles}>
<div style={styles.innerDiv}>
{contentChildren}
Expand Down Expand Up @@ -267,17 +271,18 @@ var ListItem = React.createClass({
},

_handleMouseOver: function(e) {
this.setState({hovered: true});
if (this.props.onMouseOver) {
this.props.onMouseOver(e);
}
if (!this.state.touch) this.setState({hovered: true});
if (this.props.onMouseOver) this.props.onMouseOver(e);
},

_handleMouseOut: function(e) {
this.setState({hovered: false});
if (this.props.onMouseOut) {
this.props.onMouseOut(e);
}
if (this.props.onMouseOut) this.props.onMouseOut(e);
},

_handleTouchStart: function(e) {
this.setState({touch: true});
if (this.props.onTouchStart) this.props.onTouchStart(e);
}

});
Expand Down

0 comments on commit 064e7e4

Please sign in to comment.