diff --git a/docs/src/app/components/pages/components/Tabs/ExampleScrollable.jsx b/docs/src/app/components/pages/components/Tabs/ExampleScrollable.jsx new file mode 100644 index 00000000000000..e57f98ce3122eb --- /dev/null +++ b/docs/src/app/components/pages/components/Tabs/ExampleScrollable.jsx @@ -0,0 +1,176 @@ +import React from 'react'; +import Tabs from 'material-ui/lib/tabs/tabs'; +import Tab from 'material-ui/lib/tabs/tab'; +import Slider from 'material-ui/lib/slider'; + +const styles = { + headline: { + fontSize: 24, + paddingTop: 16, + marginBottom: 12, + fontWeight: 400, + }, +}; + +const TabsExampleScrollable = () => ( + + +
+

Tab One Template Example

+

+ This is an example of a tab template! +

+

+ You can put any sort of HTML or react component in here. It even keeps the component state! +

+ +
+
+ +
+

Tab Two Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Three Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Four Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Five Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Six Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Seven Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Eight Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Nine Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Ten Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Eleven Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Twelve Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Thirteen Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Fourteen Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Fifteen Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Sixteen Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Seventeen Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Eighteen Template Example

+

+ This is another example of a tab template! +

+
+
+ +
+

Tab Nineteen Template Example

+

+ This is another example of a tab template! +

+
+
+
+); + +export default TabsExampleScrollable; diff --git a/docs/src/app/components/pages/components/Tabs/Page.jsx b/docs/src/app/components/pages/components/Tabs/Page.jsx index 2920b27b5bba02..3312f548598cdb 100644 --- a/docs/src/app/components/pages/components/Tabs/Page.jsx +++ b/docs/src/app/components/pages/components/Tabs/Page.jsx @@ -9,6 +9,8 @@ import tabsExampleControlledCode from '!raw!./ExampleControlled'; import TabsExampleControlled from './ExampleControlled'; import tabsExampleSwipeableCode from '!raw!./ExampleSwipeable'; import TabsExampleSwipeable from './ExampleSwipeable'; +import tabsExampleScrollableCode from '!raw!./ExampleScrollable'; +import TabsExampleScrollable from './ExampleScrollable'; import tabsCode from '!raw!material-ui/lib/tabs/tabs'; import tabsText from './Tabs'; import tabCode from '!raw!material-ui/lib/tabs/tab'; @@ -26,6 +28,9 @@ const TabsPage = () => ( + + + diff --git a/src/tabs/tabs.jsx b/src/tabs/tabs.jsx index ae6ab912b68e02..5970d9736eb417 100644 --- a/src/tabs/tabs.jsx +++ b/src/tabs/tabs.jsx @@ -118,7 +118,7 @@ const Tabs = React.createClass({ getDefaultProps() { return { initialSelectedIndex: 0, - stretchTabContainer: false, + stretchTabContainer: true, }; }, @@ -151,8 +151,8 @@ const Tabs = React.createClass({ }, componentDidMount() { + window.requestAnimationFrame(this.handleWindowWidthChange); Events.on(window, 'resize', this.handleWindowWidthChange); - this.replaceState(this.getNewState()); }, componentWillReceiveProps(newProps, nextContext) { @@ -326,21 +326,24 @@ const Tabs = React.createClass({ let paginationChange = this.state.shouldPaginate !== nextShouldPaginate; if (paginationChange || tabContainerWidth !== this.state.tabContainerWidth || tabWrapperWidthChange) { let nextSelectedTab = tabInfo[this.state.selectedIndex]; - let tabScrollWrapper = this._getDOMNode(Constants.TAB_SCROLL_WRAPPER_REF_NAME); - let tabScrollWrapperLeftScroll = tabScrollWrapper.scrollLeft; - let tabScrollWrapperWidth = tabScrollWrapper.offsetWidth; - let tabPaginationButtonMargin = nextShouldPaginate ? Constants.TAB_PAGINATOR_BUTTON_DEFAULT_WIDTH : 0; - let tabVisible = nextSelectedTab.leftOffset - tabPaginationButtonMargin >= tabScrollWrapperLeftScroll - && tabScrollWrapperLeftScroll + tabScrollWrapperWidth - nextSelectedTab.rightOffset - - tabPaginationButtonMargin >= 0; - if (!tabVisible) { - let shouldScrollRight = tabScrollWrapperLeftScroll + tabScrollWrapperWidth - - nextSelectedTab.rightOffset - tabPaginationButtonMargin < 0; - // calculate how much to set tag scroll wrapper's scrollLeft to - if (shouldScrollRight) { - tabScrollWrapper.scrollLeft = nextSelectedTab.rightOffset + tabPaginationButtonMargin - tabScrollWrapperWidth; - } else { - tabScrollWrapper.scrollLeft = nextSelectedTab.leftOffset - tabPaginationButtonMargin; + if (nextSelectedTab !== undefined) { + let tabScrollWrapper = this._getDOMNode(Constants.TAB_SCROLL_WRAPPER_REF_NAME); + let tabScrollWrapperLeftScroll = tabScrollWrapper.scrollLeft; + let tabScrollWrapperWidth = tabScrollWrapper.offsetWidth; + let tabPaginationButtonMargin = nextShouldPaginate ? Constants.TAB_PAGINATOR_BUTTON_DEFAULT_WIDTH : 0; + let tabVisible = nextSelectedTab.leftOffset - tabPaginationButtonMargin >= tabScrollWrapperLeftScroll + && tabScrollWrapperLeftScroll + tabScrollWrapperWidth - nextSelectedTab.rightOffset + - tabPaginationButtonMargin >= 0; + if (!tabVisible) { + let shouldScrollRight = tabScrollWrapperLeftScroll + tabScrollWrapperWidth + - nextSelectedTab.rightOffset - tabPaginationButtonMargin < 0; + // calculate how much to set tag scroll wrapper's scrollLeft to + if (shouldScrollRight) { + tabScrollWrapper.scrollLeft = nextSelectedTab.rightOffset + tabPaginationButtonMargin + - tabScrollWrapperWidth; + } else { + tabScrollWrapper.scrollLeft = nextSelectedTab.leftOffset - tabPaginationButtonMargin; + } } } } @@ -365,7 +368,8 @@ const Tabs = React.createClass({ // stretch tabs if stretchTabContainer is true and if device screen size is large - let shouldStretch = stretchTabContainer && this.isDeviceSize(StyleResizable.statics.Sizes.LARGE); + let shouldStretch = stretchTabContainer && this.isDeviceSize(StyleResizable.statics.Sizes.LARGE) + && !this.state.shouldPaginate; let themeVariables = this.state.muiTheme.tabs; let styles = {