Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Dirty fix: Do not ignore blur event when focus was initiated by the t…
Browse files Browse the repository at this point in the history
…ab key

Issue #1440, Issue #1421
  • Loading branch information
pablosichert committed Dec 22, 2017
1 parent 0365937 commit 355cd21
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/components/widget/List/RawList.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { Component } from "react";
import ReactCSSTransitionGroup from "react-addons-css-transition-group";

let lastKeyWasTab = false;

class RawList extends Component {
isFocused = false;
considerBlur = false;
Expand All @@ -15,6 +17,11 @@ class RawList extends Component {
};
}

componentWillMount() {
window.addEventListener("keydown", this.handleTab);
window.addEventListener("click", this.handleTab);
}

componentDidMount = () => {
const { autofocus, onRequestListData } = this.props;
if (this.dropdown && autofocus && onRequestListData) {
Expand Down Expand Up @@ -167,6 +174,11 @@ class RawList extends Component {
}
};

componentWillUnmount() {
window.removeEventListener("keydown", this.handleTab);
window.removeEventListener("click", this.handleTab);
}

focus = () => {
if (this.dropdown) {
this.dropdown.focus();
Expand Down Expand Up @@ -304,11 +316,12 @@ class RawList extends Component {
});
};

handleFocus = e => {
handleFocus = event => {
this.considerBlur = this.considerBlur || lastKeyWasTab;
this.isFocused = true;

if (e) {
e.preventDefault();
if (event) {
event.preventDefault();
}

const { onFocus, doNotOpenOnFocus, autofocus } = this.props;
Expand Down Expand Up @@ -394,6 +407,10 @@ class RawList extends Component {
}
};

handleTab = event => {
lastKeyWasTab = event.key == "Tab";
};

getRow = (option, index) => {
const { defaultValue } = this.props;
const { selected } = this.state;
Expand Down

0 comments on commit 355cd21

Please sign in to comment.