Scroll tab target into view (#1580)
This commit is contained in:
parent
5817186129
commit
97d02fd7c8
1 changed files with 3 additions and 2 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue