Skip to content

Commit

Permalink
[Tabs] Small changes investigating #11624
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jul 22, 2018
1 parent c65d419 commit af30739
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions packages/material-ui/src/Tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import classNames from 'classnames';
import EventListener from 'react-event-listener';
import debounce from 'debounce'; // < 1kb payload overhead when lodash/debounce is > 3kb.
import { getNormalizedScrollLeft, detectScrollType } from 'normalize-scroll-left';
// TODO: should we fork it?
// https://github.com/michaelrhodes/scroll/issues/10
import scroll from 'scroll';
import ScrollbarSize from './ScrollbarSize';
import withStyles from '../styles/withStyles';
Expand Down Expand Up @@ -94,11 +96,10 @@ class Tabs extends React.Component {
}

componentDidUpdate(prevProps, prevState) {
this.updateScrollButtonState();

// The index might have changed at the same time.
// We need to check again the right indicator position.
this.updateIndicatorState(this.props);
this.updateScrollButtonState();

if (this.state.indicatorStyle !== prevState.indicatorStyle) {
this.scrollSelectedIntoView();
Expand Down Expand Up @@ -176,15 +177,11 @@ class Tabs extends React.Component {
};

handleLeftScrollClick = () => {
if (this.tabsRef) {
this.moveTabsScroll(-this.tabsRef.clientWidth);
}
this.moveTabsScroll(-this.tabsRef.clientWidth);
};

handleRightScrollClick = () => {
if (this.tabsRef) {
this.moveTabsScroll(this.tabsRef.clientWidth);
}
this.moveTabsScroll(this.tabsRef.clientWidth);
};

handleScrollbarSizeChange = ({ scrollbarHeight }) => {
Expand All @@ -198,13 +195,11 @@ class Tabs extends React.Component {
moveTabsScroll = delta => {
const { theme } = this.props;

if (this.tabsRef) {
const multiplier = theme.direction === 'rtl' ? -1 : 1;
const nextScrollLeft = this.tabsRef.scrollLeft + delta * multiplier;
// Fix for Edge
const invert = theme.direction === 'rtl' && detectScrollType() === 'reverse' ? -1 : 1;
scroll.left(this.tabsRef, invert * nextScrollLeft);
}
const multiplier = theme.direction === 'rtl' ? -1 : 1;
const nextScrollLeft = this.tabsRef.scrollLeft + delta * multiplier;
// Fix for Edge
const invert = theme.direction === 'rtl' && detectScrollType() === 'reverse' ? -1 : 1;
scroll.left(this.tabsRef, invert * nextScrollLeft);
};

scrollSelectedIntoView = () => {
Expand All @@ -229,7 +224,7 @@ class Tabs extends React.Component {
updateScrollButtonState = () => {
const { scrollable, scrollButtons, theme } = this.props;

if (this.tabsRef && scrollable && scrollButtons !== 'off') {
if (scrollable && scrollButtons !== 'off') {
const { scrollWidth, clientWidth } = this.tabsRef;
const scrollLeft = getNormalizedScrollLeft(this.tabsRef, theme.direction);

Expand Down

0 comments on commit af30739

Please sign in to comment.