Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

refactor(tabs): adds support for non-fixed tabs #921

Closed
wants to merge 1 commit into from

Conversation

robertmesserle
Copy link
Contributor

Closes #825.
Closes #460.

@googlebot
Copy link

CLAs look good, thanks!

@ajoslin ajoslin added the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Dec 11, 2014
@@ -48,7 +48,8 @@ angular.module('material.components.tabs')
* @param {integer=} mdSelected Index of the active/selected tab
* @param {boolean=} mdNoInk If present, disables ink ripple effects.
* @param {boolean=} mdNoBar If present, disables the selection ink bar.
* @param {string=} mdAlignTabs Attribute to indicate position of tab buttons: bottom or top; default is `top`
* @param {string=} mdAlignTabs Attribute to indicate position of tab buttons: `bottom` or `top`; default is `top`
* @param {boolean=} mdStretchTabs Attribute to indicate whether or not to stretch tabs: `auto`, `yes`, or `no`; default is `auto`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options here:

yes: when there is only one page, tabs will stretch to fill the bar (even on desktop)
no: tabs will never stretch to fill the bar
auto: on mobile, single page tab bars will have their tabs stretch to fill the bar

@@ -196,7 +194,7 @@ function InkRippleService($window, $timeout) {

state.animating = true;

$timeout(function () {
scope.$evalAsync(function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the extra $digest ?

@gkalpak
Copy link
Member

gkalpak commented Dec 12, 2014

The commit message does not follow the guidelines btw (unknown type) 😄

@robertmesserle robertmesserle changed the title enhance(ripple): adds support for non-fixed tabs refactor(ripple): adds support for non-fixed tabs Dec 12, 2014
@robertmesserle robertmesserle force-pushed the wip-tab-refactor branch 3 times, most recently from ff5f516 to 97e392c Compare December 12, 2014 19:33
@robertmesserle
Copy link
Contributor Author

@gkalpak Great feedback, thanks!

if (scope.pagination && scope.pagination.tabData) {
var index = tabsCtrl.getSelectedIndex();
var data = scope.pagination.tabData.tabs[index] || { left: 0, right: 0, width: 0 };
var right = element.parent().prop('offsetWidth') - data.right;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this code could be refactored for DRY-ness:

var clazz = (lastIndex > index) ? 'md-transition-left'  :
            (lastIndex < index) ? 'md-transition-right' : 'md-no-transition';

element.css({ left: data.left + 'px', right: right + 'px' });

element.removeClass('md-transition-left md-transition-right md-no-transition');
element.addClass( clazz );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, revised this section of code.

@robertmesserle robertmesserle force-pushed the wip-tab-refactor branch 2 times, most recently from 5f17350 to a2c5961 Compare December 12, 2014 19:59
@ThomasBurleson
Copy link
Contributor

@robertmesserle - Is this ready for full review and merge into #master ?

@robertmesserle
Copy link
Contributor Author

@ThomasBurleson I believe so. I am still testing this, but I think it's ready for a full review.

element
.removeClass(classNames.join(' '))
.addClass(classNames[classIndex])
.css({ left: data.left + 'px', right: right + 'px' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concise 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I changed this to use percents originally was because it fixed problems when the tabbar or its container is resized.

Resizes can happen arbitrarily, and they won't always trigger a window resize event.

Is there any way we can make this use percentages again to set the ink bar's position?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The size of the container element is now hard-coded, so resizes should not impact this part.

(That is, the outer element stretches as needed, but the inner wrapper is hard-coded to a size far larger than we need to allow for pagination and calculation.)

filler: 0
};
//-- store 1-based page number
data.page = pages.length === 1 && index === tabs.length - 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any benefit in having 1-based page indices ? It is kind of confuding in a 0-based world :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking into refactoring this now. I initially used 1-based numbers because that was what pagesCount was using; however, I think 0-based is likely the way to go - especially now that pagesCount has been fully factored out.

@robertmesserle robertmesserle changed the title refactor(ripple): adds support for non-fixed tabs refactor(tabs): adds support for non-fixed tabs Dec 13, 2014
@robertmesserle robertmesserle force-pushed the wip-tab-refactor branch 2 times, most recently from 1a89582 to 3964754 Compare December 13, 2014 01:16
@@ -160,31 +146,108 @@ function TabPaginationDirective($mdConstant, $window, $$rAF, $$q, $timeout) {
}
}

function stretchTabs() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we actually change this to shouldStretchTabs()? The name stretchTabs() sounds like you're commanding it to do something, when in reality it's just returning a boolean.

@ThomasBurleson
Copy link
Contributor

@robertmesserle - ready for me to test and merge into master ?

@robertmesserle robertmesserle force-pushed the wip-tab-refactor branch 6 times, most recently from e269160 to 8da345b Compare December 16, 2014 22:39
Closes #825.
Closes #460.

refactor(tabs): added handling for when the tabs are initially hidden

refactor(tabs): switched to 0-based page indexes

refactor(tabs): wires up pagination to use $mdMedia rather than a hard-coded pixel size

In order to accomplish this, I had to move $mdMedia into its own file in the 'material.core' scope.

refactor(tabs): changes per Andrew's feedback

Renames `stretchTabs()` to `shouldStretchTabs()`
Uses `getElementsByTagName()` in place of `querySelectorAll()`
Uses cached version of `angular.element(tabs)`
Adds descriptive comment for `data.page` calculation

refactor(tabs): moves tabs definition to top of `postLink` method
@ajoslin ajoslin removed the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Dec 18, 2014
@robertmesserle robertmesserle deleted the wip-tab-refactor branch January 8, 2015 19:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support variable, shrink-wrapped sized tabs How to make tabs full width
6 participants