material icon indicating copy to clipboard operation
material copied to clipboard

tabs: md-stretch-tabs="always" does not stretch tab labels

Open tyrdavis opened this issue 9 years ago • 5 comments

Actual Behavior:

  • What is the issue? * md-stretch-tabs="always" does not stretch the tab labels at any viewport size
  • What 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/zdVvVR
  • Details: 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.5
  • AngularJS Material Version: 1.1.5

Additional Information:

  • Browser Type: * Chrome
  • Browser Version: * 60.0.3112.90
  • OS: * Windows 7
  • Stack Traces:

tyrdavis avatar Sep 07 '17 17:09 tyrdavis

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.

ricardofilho6 avatar Sep 25 '17 11:09 ricardofilho6

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);
    }
  }

kylemacfarlane avatar Oct 07 '17 07:10 kylemacfarlane

Good call on the spec change. I hadn't noticed that.

tyrdavis avatar Oct 10 '17 19:10 tyrdavis

This issue still happening in Angular Material 1.1.9

pgarriga avatar Jun 06 '18 13:06 pgarriga

Looks like the spec now indicates that max tab size is 360px instead of 264px.

Splaktar avatar Jun 10 '18 20:06 Splaktar