From 6a5fa5687097bc091f24d281412e1065bcfb3754 Mon Sep 17 00:00:00 2001 From: Weronika Olejniczak Date: Wed, 20 Nov 2024 14:49:48 +0100 Subject: [PATCH] refactor(tabs): simplify looping through tabs logic refactor(tabs): simplify looping through tabs logic --- packages/eui/src/components/tabs/tabs.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/eui/src/components/tabs/tabs.tsx b/packages/eui/src/components/tabs/tabs.tsx index aea6d5c32cc..eaa0ca38edc 100644 --- a/packages/eui/src/components/tabs/tabs.tsx +++ b/packages/eui/src/components/tabs/tabs.tsx @@ -80,10 +80,12 @@ export const EuiTabs = forwardRef( ); 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(); } };