Skip to content

Commit

Permalink
refactor(tabs): simplify looping through tabs logic
Browse files Browse the repository at this point in the history
refactor(tabs): simplify looping through tabs logic
  • Loading branch information
weronikaolejniczak committed Nov 21, 2024
1 parent 2075b01 commit 6a5fa56
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/eui/src/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ export const EuiTabs = forwardRef<EuiTabRef, EuiTabsProps>(
);

if (event.key === keys.ARROW_LEFT) {
const previousIndex = (currentIndex - 1 + tabs.length) % tabs.length;
const previousIndex =
(currentIndex === 0 ? tabs.length : currentIndex) - 1;
tabs[previousIndex].focus();
} else if (event.key === keys.ARROW_RIGHT) {
const nextIndex = (currentIndex + 1) % tabs.length;
const nextIndex =
currentIndex === tabs.length - 1 ? 0 : currentIndex + 1;
tabs[nextIndex].focus();
}
};
Expand Down

0 comments on commit 6a5fa56

Please sign in to comment.