Skip to content

Commit

Permalink
[Tabs] Small changes investigating #11624 (#12239)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jul 22, 2018
1 parent c65d419 commit 95b2e2c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = [
name: 'The size of all the modules of material-ui.',
webpack: true,
path: 'packages/material-ui/build/index.js',
limit: '94.8 KB',
limit: '94.9 KB',
},
{
name: 'The main bundle of the docs',
Expand Down
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
3 changes: 2 additions & 1 deletion packages/material-ui/src/Tabs/Tabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('<Tabs />', () => {
};

before(() => {
shallow = createShallow({ untilSelector: 'Tabs' });
shallow = createShallow({ untilSelector: 'Tabs', disableLifecycleMethods: true });
classes = getClasses(<Tabs onChange={noop} value={0} />);
mount = createMount();
});
Expand Down Expand Up @@ -627,6 +627,7 @@ describe('<Tabs />', () => {
<Tab />
</Tabs>,
);
wrapper.setState({ mounted: true });
assert.strictEqual(wrapper.find(TabIndicator).props().style.backgroundColor, 'green');
});
});
Expand Down

0 comments on commit 95b2e2c

Please sign in to comment.