Skip to content

Instantly share code, notes, and snippets.

@averyvery
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save averyvery/3dd98f4ed378018164d6 to your computer and use it in GitHub Desktop.
Save averyvery/3dd98f4ed378018164d6 to your computer and use it in GitHub Desktop.
.disable-focus-styles *:focus {
outline: none;
}
module.exports = React.createClass({
getInitialState() {
return {
usingMouse : false,
focusedOnElement : false
}
},
_setUsingMouse(usingMouse) {
this.setState({usingMouse: usingMouse})
},
_setFocus(focused) {
this.setState({focusedOnElement: focused})
},
_userHasClicked() {
return this.state.usingMouse && this.state.focusedOnElement
},
render() {
const className = this._userHasClicked() ? 'disable-focus-styles' : ''
return (
<div className={className}
onKeyDown={this._setUsingMouse.bind(this, false)}
onMouseDown={this._setUsingMouse.bind(this, true)}
onFocus={this._setFocus.bind(this, true)}
onBlur={this._setFocus.bind(this, false)}>
<Nav/>
<RouteHandler {...this.props} />
</div>
)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment