Created
April 22, 2017 22:44
-
-
Save jessebeach/7e3d25ab587ae06a30f03d8d3e1adeef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Grid extends React.Component { | |
_timeoutID; | |
constructor() { | |
this.state = { | |
isManagingFocus: false, | |
}; | |
} | |
render() { | |
return ( | |
<div | |
role="grid" | |
onBlur={this._onBlur} | |
onFocus={this._onFocus} | |
>{this.props.children}</div> | |
); | |
} | |
_onBlur() { | |
this._timeoutID = setTimeout(() => { | |
if (this.state.isManagingFocus) { | |
this.setState({ | |
isManagingFocus: false, | |
}); | |
} | |
}, 0); | |
} | |
_onFocus() { | |
clearTimeout(this._timeoutID); | |
if (!this.state.isManagingFocus) { | |
this.setState({ | |
isManagingFocus: true, | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Functional approach :