From 97d02fd7c84457b25a80e18974435ee8f8bb7b86 Mon Sep 17 00:00:00 2001 From: aceArt-GmbH <33117017+aceArt-GmbH@users.noreply.github.com> Date: Tue, 14 May 2024 05:49:04 +0200 Subject: [PATCH] Scroll tab target into view (#1580) --- src/app/atoms/tabs/Tabs.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/app/atoms/tabs/Tabs.jsx b/src/app/atoms/tabs/Tabs.jsx index 39800ce..bcdc8ef 100644 --- a/src/app/atoms/tabs/Tabs.jsx +++ b/src/app/atoms/tabs/Tabs.jsx @@ -41,8 +41,9 @@ TabItem.propTypes = { function Tabs({ items, defaultSelected, onSelect }) { const [selectedItem, setSelectedItem] = useState(items[defaultSelected]); - const handleTabSelection = (item, index) => { + const handleTabSelection = (item, index, target) => { if (selectedItem === item) return; + target.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' }); setSelectedItem(item); onSelect(item, index); }; @@ -57,7 +58,7 @@ function Tabs({ items, defaultSelected, onSelect }) { selected={selectedItem.text === item.text} iconSrc={item.iconSrc} disabled={item.disabled} - onClick={() => handleTabSelection(item, index)} + onClick={(e) => handleTabSelection(item, index, e.currentTarget)} > {item.text}