Skip to content

Commit

Permalink
[EnhancedButton] Listen to tabs on the window.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Nguyen committed Aug 21, 2015
1 parent 3651ec8 commit ae90552
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/enhanced-button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const PureRenderMixin = React.addons.PureRenderMixin;
const StylePropable = require('./mixins/style-propable');
const Colors = require('./styles/colors');
const Children = require('./utils/children');
const Events = require('./utils/events');
const KeyCode = require('./utils/key-code');
const FocusRipple = require('./ripples/focus-ripple');
const TouchRipple = require('./ripples/touch-ripple');

let styleInjected = false;
let listening = false;
let tabPressed = false;

function injectStyle() {
Expand All @@ -27,6 +29,15 @@ function injectStyle() {
}
}

function listenForTabPresses() {
if (!listening) {
Events.on(window, 'keydown', (e) =>{
tabPressed = e.keyCode === KeyCode.TAB;
});
listening = true;
}
}

const EnhancedButton = React.createClass({

mixins: [PureRenderMixin, StylePropable],
Expand Down Expand Up @@ -94,6 +105,7 @@ const EnhancedButton = React.createClass({

componentDidMount() {
injectStyle();
listenForTabPresses();
},

render() {
Expand Down Expand Up @@ -233,9 +245,6 @@ const EnhancedButton = React.createClass({

_handleKeyDown(e) {
if (!this.props.disabled && !this.props.disableKeyboardFocus) {
if (e.keyCode === KeyCode.TAB) {
tabPressed = true;
}
if (e.keyCode === KeyCode.ENTER && this.state.isKeyboardFocused) {
this._handleTouchTap(e);
}
Expand Down

0 comments on commit ae90552

Please sign in to comment.