Skip to content

Commit

Permalink
feat: prevent default event propagation
Browse files Browse the repository at this point in the history
Ensures consistency for click and touch events on the same element.
cc: https://joshtronic.com/2015/04/19/handling-click-and-touch-events-on-the-same-element/
  • Loading branch information
francisfuzz committed Oct 29, 2019
1 parent 334a316 commit f7f3921
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class App extends React.Component {
this.changeColor = this.changeColor.bind(this)
}

changeColor() {
changeColor(event) {
event.preventDefault()
event.stopPropagation()

const newColors = this.state.colors.slice()
const nextColor = newColors.pop()
newColors.unshift(nextColor)
Expand All @@ -32,6 +35,7 @@ class App extends React.Component {
return (
<div
onClick={this.changeColor}
onTouchEnd={this.changeColor}
style={{
'minWidth': '90vw',
'minHeight': '90vh',
Expand Down

0 comments on commit f7f3921

Please sign in to comment.