Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tabs] Small changes investigating #11624 #12239

Merged
merged 1 commit into from
Jul 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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