Skip to content

Commit

Permalink
refactor(tabs): simplify looping through tabs logic
Browse files Browse the repository at this point in the history
  • Loading branch information
weronikaolejniczak committed Nov 20, 2024
1 parent 22bbc04 commit b25165d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 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,11 @@ 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 ? 0 : currentIndex + 1;
tabs[nextIndex].focus();
}
};
Expand Down

0 comments on commit b25165d

Please sign in to comment.