Skip to content

Commit

Permalink
Scroll tab target into view
Browse files Browse the repository at this point in the history
  • Loading branch information
aceArt-GmbH committed May 13, 2024
1 parent cd5d8e1 commit 03b32b2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/app/atoms/tabs/Tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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}
</TabItem>
Expand Down

0 comments on commit 03b32b2

Please sign in to comment.