tabs: md-stretch-tabs="always" does not stretch tab labels
Actual Behavior:
What is the issue? *md-stretch-tabs="always" does not stretch the tab labels at any viewport sizeWhat is the expected behavior?Tab labels should stretch to fit the container's width
CodePen (or steps to reproduce the issue): *
CodePen Demo which shows your issue:https://codepen.io/anon/pen/zdVvVRDetails:The md-tabs element has md-stretch-tabs set to always. The tabs are not stretched. Changing the value to auto also does not function, even in mobile-sized viewports.
AngularJS Versions: *
AngularJS Version:1.5.5 & 1.6.5AngularJS Material Version:1.1.5
Additional Information:
Browser Type: *ChromeBrowser Version: *60.0.3112.90OS: *Windows 7Stack Traces:
I'm having the same issue, i updated angularJS (1.6.1 => 1.6.6) and material (1.1.4 => 1.1.5) versions and the problem continues. I tested in Chrome, Firefox and MS Edge browsers.
This was introduced by https://github.com/angular/material/commit/338ca278f40c5de8c0ac1173946492b45a41a22a#diff-6abc5f5dfc7791c07e58ae9d12975621R642
This change basically eliminates stretching tabs on larger screens.
If this change was on purpose then there is another bug: the maxWidth is lost after things like route changes. This is because this comparison blocks setting the maxWidth if it's the same as the previous value: https://github.com/angular/material/blob/338ca278f40c5de8c0ac1173946492b45a41a22a/src/components/tabs/js/tabsController.js#L190
So if you want full width stretching change:
function getMaxTabWidth () {
var elements = getElements(),
containerWidth = elements.canvas.clientWidth,
// See https://material.google.com/components/tabs.html#tabs-specs
specMax = 264;
// Do the spec maximum, or the canvas width; whichever is *smaller* (tabs larger than the canvas
// width can break the pagination) but not less than 0
return Math.max(0, Math.min(containerWidth - 1, specMax));
}
Back to:
function getMaxTabWidth () {
return $element.prop('clientWidth');
}
Or if you want reliable 264px maxWidth as per the spec change:
function handleMaxTabWidth (newWidth, oldWidth) {
if (newWidth !== oldWidth) {
var elements = getElements();
// Set the max width for the real tabs
angular.forEach(elements.tabs, function(tab) {
tab.style.maxWidth = newWidth + 'px';
});
// Set the max width for the dummy tabs too
angular.forEach(elements.dummies, function(tab) {
tab.style.maxWidth = newWidth + 'px';
});
$mdUtil.nextTick(ctrl.updateInkBarStyles);
}
}
To something like:
function handleMaxTabWidth (newWidth, oldWidth) {
var elements = getElements();
// Set the max width for the real tabs
angular.forEach(elements.tabs, function(tab) {
tab.style.maxWidth = newWidth + 'px';
});
// Set the max width for the dummy tabs too
angular.forEach(elements.dummies, function(tab) {
tab.style.maxWidth = newWidth + 'px';
});
if (newWidth !== oldWidth) {
$mdUtil.nextTick(ctrl.updateInkBarStyles);
}
}
Good call on the spec change. I hadn't noticed that.
This issue still happening in Angular Material 1.1.9
Looks like the spec now indicates that max tab size is 360px instead of 264px.