components icon indicating copy to clipboard operation
components copied to clipboard

[Tabs] Md-tab height: 100% does not give all height of group

Open Hanzofm opened this issue 9 years ago • 18 comments

Hi,

I'm having problems to adjust content of a tab to 100% of height of md-tab-group

For example:

<md-tab-group style="background-color: lightblue; height: 100%">// this works all bk is blue
<md-tab label="Info" style="background-color: indianred; height: 100%">//not work
<div style="background-color: yellow; height: 100%"></div>//with % not work, with px works
</md-tab>
</md-tab-group>

My problem is that md-tab-group expands his height to total of height. But the atribute height of md-tab doesn't fit to 100% of md-tab-group.

Because of that the content, even if I set the height to 100% it doesn't fit to 100% of height

If I set thet height attribute of the <div> to for example 500px it works correctly

I have this problem since I added <!doctype html> to my index.html

Versions: Beta.5 Angular 4

What would be doing wrong?

Hanzofm avatar May 16 '17 14:05 Hanzofm

Closing since this is a question rather than an issue. Please feel free to ask our great community in other avenues such as StackOverflow or Gitter. Note that it will help if you re-create your template in a plunkr so others can assist you better.

andrewseguin avatar May 16 '17 21:05 andrewseguin

But In my opinion @andrewseguin it is more a problem than a question.

This is a plunker that recreate the problem

https://plnkr.co/edit/eyklxDVFbsxEnLKyCbi1?p=preview

And this is a screenshot of my custom problem

https://i.stack.imgur.com/8uDvd.png

The problem is that the content inside of a <md-tab> is not able to work with percentages when all other content yes

Hanzofm avatar May 17 '17 07:05 Hanzofm

Thanks for the example, I see that the problem is in the .mat-tab-body-wrapper which does not carry down information of the height to its children since it does not stretch the full height of it's parent.

Next time it definitely helps to follow the issue template and provide reproduction steps. Otherwise it's harder for us to know what is being described and how to replicate it.

Fix has been made in #4631

andrewseguin avatar May 17 '17 21:05 andrewseguin

Sorry for the bad news, but it looks like we'll need to dig deeper into coming up with a solution. Safari doesn't quite match the flexbox spec and translate height down correctly to children.

This would be a great bug for community contribution

andrewseguin avatar May 19 '17 20:05 andrewseguin

Thanks for your work!

Hanzofm avatar May 27 '17 08:05 Hanzofm

@andrewseguin I've had to add an absolute positioned element in my nested flexbox layouts when I wanted 100% height. This Plunk adds the fix you made and tweaks the mat-body-content class:

.mat-tab-body-wrapper {
  flex-grow: 1;
}
.mat-tab-body-content {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

Tested on my iPhone - os10.3.2. SO links for reference: link, link

RobJacobs avatar May 31 '17 00:05 RobJacobs

Did some digging, it seems PR #1788 introduced this issue, In the tab-group.scss, the flex-grow: 1 was removed from the mat-tab-body-wrapper class and the mat-tab-body-active class was introduced which sets the position: relative. This overrides the position: absolute on the mat-tab-body class which comes from the mat-fill include.

RobJacobs avatar May 31 '17 13:05 RobJacobs

@RobJacobs I played around with the problem and your solution and as soon as the div actually contains content, I get weird behavior with the absolute positioning. Here's your Plunk with content. Notice the Scrollbar, that's not supposed to be there.

When I set the absolute positioning onto the div with the height:100% style it's fixed. See here.

I have no idea if this helps anyone, but I just wanted to bring it up.

KeTr avatar Jun 13 '17 11:06 KeTr

@KeTr Not sure what's going on with the p element, but that's what is causing the scroll bars to appear. The user-agent style adds a 16px margin top and bottom to p elements and for some reason that is leaking out to the parent div. I created another plunk that abstracts the classes/styles to help diagnose the issue.

RobJacobs avatar Jun 13 '17 16:06 RobJacobs

I played around with this some more, my previous idea with absolute positioning broke the dynamic-tab-height implementation. The only way I've gotten this to work so far is by making all the child tab body containers flex. Adding

.mat-tab-body-wrapper {
    flex-grow: 1;
}

.mat-tab-body {
    display: flex !important;
    flex-direction: column;
}

.mat-tab-body-content {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

The important flag on the .mat-tab-body is to override the display: block style already existing on that class, obviously the real fix would replace the display: block and !important would not be needed. This also seems to fix the issue @KeTr uncovered using a 'p' element.

I also changed the inner div style from: height: 100% to: flex-grow: 1. plunk has been updated, tested on a Mac with OSX v 10.11.6 with Safari version 10.0.3

RobJacobs avatar Jun 13 '17 19:06 RobJacobs

@RobJacobs could you make a pull request with your fix?

reginbald avatar Jul 10 '17 11:07 reginbald

Following change help me sort my issue:-

/deep/.mat-tab-body-wrapper{ height: 100%!important; }

vaishalichawla26 avatar Jan 22 '18 05:01 vaishalichawla26

The following also works for me (same as above without important).

::ng-deep .mat-tab-body-wrapper {
  height: 100%
}

Angular docs says /deep/ is deprecated, what's the alternative to deep?

daicoden avatar Apr 23 '18 20:04 daicoden

@andrewseguin @mmalerba If @CDDelta is working here I suggest to add the "has pr" label to this issue.

saulotoledo avatar May 19 '18 15:05 saulotoledo

Is there any reason why the PR hasn't still been merged after 5 months?

darkbasic avatar May 23 '18 19:05 darkbasic

@vaishalichawla26 @daicoden

I think flex-grow should be prefered. Otherwise it's as of now the only solution that worked for me.

Cheers!

::ng-deep .mat-tab-body-wrapper {
    flex-grow: 1;
}

Knacktus avatar Jun 18 '18 10:06 Knacktus

This works for me! :ok:

html:

<mat-tab-group id="group">
  <mat-tab label="Tab 1">
    <div class="tab-content-container"> Content 1</div>
  </mat-tab>   

  <mat-tab label="Tab 2">
     <div class="tab-content-container"> Content 2</div>
  </mat-tab>

  <mat-tab label="Tab 3">
     <div class="tab-content-container"> Content 3</div>
  </mat-tab>
</mat-tab-group>

scss:

#group {
  height: 100%; // Whole group height.

  ::ng-deep .mat-tab-body-wrapper {
    height: 100%; // Tabs body height. I also don't like ng-deep, but there is no other way :(
  }

  .tab-content-container {
    height: 100%;  // Content height.
  }
}

ooow avatar Feb 01 '19 12:02 ooow

@andrewseguin according to your answer https://github.com/angular/components/pull/15839#issuecomment-1082347069 does this issue still make sense?

viniciusschuelter avatar Aug 12 '22 00:08 viniciusschuelter