Scroll tab target into view (#1580)

This commit is contained in:
aceArt-GmbH 2024-05-14 05:49:04 +02:00 committed by GitHub
parent 5817186129
commit 97d02fd7c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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}
</TabItem>