diff --git a/src/components/combo_box/combo_box.js b/src/components/combo_box/combo_box.js index 31cbbfedab13..a547826db882 100644 --- a/src/components/combo_box/combo_box.js +++ b/src/components/combo_box/combo_box.js @@ -311,10 +311,16 @@ export class EuiComboBox extends Component { onFocus = () => { this.openList(); + + document.addEventListener('click', this.onDocumentFocusChange); + document.addEventListener('focusin', this.onDocumentFocusChange); } onBlur = () => { this.closeList(); + + document.removeEventListener('click', this.onDocumentFocusChange); + document.removeEventListener('focusin', this.onDocumentFocusChange); } onDocumentFocusChange = event => { @@ -366,16 +372,10 @@ export class EuiComboBox extends Component { break; case TAB: - if (e.shiftKey) { - if (this.tabAway(-1)) { - e.preventDefault(); - e.stopPropagation(); - } - } else { - if (this.tabAway(1)) { - e.preventDefault(); - e.stopPropagation(); - } + const amount = e.shiftKey ? -1 : 1; + if (this.tabAway(amount)) { + e.preventDefault(); + e.stopPropagation(); } break; } @@ -484,8 +484,6 @@ export class EuiComboBox extends Component { componentDidMount() { this._isMounted = true; - document.addEventListener('click', this.onDocumentFocusChange); - document.addEventListener('focusin', this.onDocumentFocusChange); // TODO: This will need to be called once the actual stylesheet loads. setTimeout(() => {