Skip to content

Commit

Permalink
Protect against tab amounts that are not 1 or -1.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed May 23, 2018
1 parent fecf0be commit 9de6431
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/combo_box/combo_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 9de6431

Please sign in to comment.