From 9de6431ead5c9feabbb6846a4ea9fda9570886e9 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Wed, 23 May 2018 13:31:39 -0700 Subject: [PATCH] Protect against tab amounts that are not 1 or -1. --- src/components/combo_box/combo_box.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/combo_box/combo_box.js b/src/components/combo_box/combo_box.js index 3d9ef95c8827..3a1cc05af0f8 100644 --- a/src/components/combo_box/combo_box.js +++ b/src/components/combo_box/combo_box.js @@ -137,13 +137,17 @@ export class EuiComboBox extends Component { }; tabAway = amount => { + if (![-1, 1].includes(amount)) { + throw new Error(`tabAway expects amount to be -1 or 1, but received ${amount}`); + } + const tabbableItems = tabbable(document); if (document.activeElement === this.searchInput) { const searchInputIndex = tabbableItems.indexOf(this.searchInput); // Wrap to last tabbable if tabbing backwards. - if (amount < 0) { + if (amount === -1) { if (searchInputIndex === 0) { tabbableItems[tabbableItems.length - 1].focus(); return; @@ -159,7 +163,7 @@ export class EuiComboBox extends Component { const clearButtonIndex = tabbableItems.indexOf(this.clearButton); // Wrap to first tabbable if tabbing forwards. - if (amount > 0) { + if (amount === 1) { if (clearButtonIndex === tabbableItems.length - 1) { tabbableItems[0].focus(); return;