Skip to content

Commit

Permalink
[Tabs] Fix issue where scrollable tabs auto move to selected tab (#16961
Browse files Browse the repository at this point in the history
)

Fixes #10826
  • Loading branch information
wereHamster authored and oliviertassinari committed Aug 13, 2019
1 parent 2a71c35 commit 9e4eba0
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/material-ui/src/Tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,28 +170,30 @@ const Tabs = React.forwardRef(function Tabs(props, ref) {

if (tabMeta && tabsMeta) {
if (vertical) {
startValue = Math.round(tabMeta.top - tabsMeta.top + tabsMeta.scrollTop);
startValue = tabMeta.top - tabsMeta.top + tabsMeta.scrollTop;
} else {
const correction = isRtl
? tabsMeta.scrollLeftNormalized + tabsMeta.clientWidth - tabsMeta.scrollWidth
: tabsMeta.scrollLeft;
startValue = Math.round(tabMeta.left - tabsMeta.left + correction);
startValue = tabMeta.left - tabsMeta.left + correction;
}
}

const newIndicatorStyle = {
[start]: startValue,
// May be wrong until the font is loaded.
[size]: tabMeta ? Math.round(tabMeta[size]) : 0,
[size]: tabMeta ? tabMeta[size] : 0,
};

if (
(newIndicatorStyle[start] !== indicatorStyle[start] ||
newIndicatorStyle[size] !== indicatorStyle[size]) &&
!isNaN(newIndicatorStyle[start]) &&
!isNaN(newIndicatorStyle[size])
) {
if (isNaN(indicatorStyle[start]) || isNaN(indicatorStyle[size])) {
setIndicatorStyle(newIndicatorStyle);
} else {
const dStart = Math.abs(indicatorStyle[start] - newIndicatorStyle[start]);
const dSize = Math.abs(indicatorStyle[size] - newIndicatorStyle[size]);

if (dStart >= 1 || dSize >= 1) {
setIndicatorStyle(newIndicatorStyle);
}
}
});

Expand Down

0 comments on commit 9e4eba0

Please sign in to comment.