-
Notifications
You must be signed in to change notification settings - Fork 3.4k
refactor(tabs): adds support for non-fixed tabs #921
Conversation
CLAs look good, thanks! |
@@ -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` |
There was a problem hiding this comment.
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
938cfe4
to
1fe7e73
Compare
@@ -196,7 +194,7 @@ function InkRippleService($window, $timeout) { | |||
|
|||
state.animating = true; | |||
|
|||
$timeout(function () { | |||
scope.$evalAsync(function () { |
There was a problem hiding this comment.
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 ?
The commit message does not follow the guidelines btw (unknown type) 😄 |
ff5f516
to
97e392c
Compare
@gkalpak Great feedback, thanks! |
97e392c
to
a999fa7
Compare
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; |
There was a problem hiding this comment.
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 );
There was a problem hiding this comment.
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.
5f17350
to
a2c5961
Compare
@robertmesserle - Is this ready for full review and merge into #master ? |
@ThomasBurleson I believe so. I am still testing this, but I think it's ready for a full review. |
a2c5961
to
f73684e
Compare
element | ||
.removeClass(classNames.join(' ')) | ||
.addClass(classNames[classIndex]) | ||
.css({ left: data.left + 'px', right: right + 'px' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concise 👍
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
1a89582
to
3964754
Compare
@@ -160,31 +146,108 @@ function TabPaginationDirective($mdConstant, $window, $$rAF, $$q, $timeout) { | |||
} | |||
} | |||
|
|||
function stretchTabs() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice.
There was a problem hiding this comment.
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.
ec4a6ac
to
db1729c
Compare
@robertmesserle - ready for me to test and merge into master ? |
e269160
to
8da345b
Compare
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
8da345b
to
a7f7ff8
Compare
Closes #825.
Closes #460.