I am new to the angular-material libary (and material design spec in general), I have used bootstrap for years, so am not sure I am implementing mat-grid-list correctly, but I have the follwing:
<mat-card>
<mat-grid-list cols="2">
<mat-grid-tile>
<mat-grid-tile-header>Clocked In</mat-grid-tile-header>
<mat-list>
<mat-list-item>
<button mat-raised-button color="warn">
{{user.firstName}} {{user.lastName}}
</button>
</mat-list-item>
</mat-list>
</mat-grid-tile>
<mat-grid-tile>
<mat-grid-tile-header>Clocked Out</mat-grid-tile-header>
<mat-list>
<mat-list-item>
<button mat-raised-button color="accent">
{{user.firstName}} {{user.lastName}}
</button>
</mat-list-item>
</mat-list>
</mat-grid-tile>
</mat-grid-list>
This is based off of the angular-material example, to which I have included a working stackblitz example: https://stackblitz.com/edit/angular-cccnjp?file=app%2Fsidenav-responsive-example.html
As you can see, the buttons have been rendered inside the mat-grid-tile-header and the mat-card has not expanded to accomodate the content provided (as I would expect)
EDIT: So, I did try using the rowHeight="fit" attribute on the mat-grid-list but this doesn't render any content, I would expect this to expand the height of mat-grid-list depending on content, but this is not working.
https://stackblitz.com/edit/angular-cccnjp-ylmzf9?file=app/sidenav-responsive-example.html
UPDATE: ugly working solution
So I managed to acheive this with some (quite ugly) css…
<mat-card class="height100p">
<mat-grid-list cols="2">
<mat-grid-tile class="mat-grid-tile-custom">
<mat-grid-tile-header>Clocked In</mat-grid-tile-header>
<mat-list class="custom-mat-list">
<mat-list-item>
<button mat-raised-button color="warn">
{{user.firstName}} {{user.lastName}}
</button>
</mat-list-item>
</mat-list>
</mat-grid-tile>
<mat-grid-tile class="mat-grid-tile-custom">
<mat-grid-tile-header>Clocked Out</mat-grid-tile-header>
<mat-list class="custom-mat-list">
<mat-list-item>
<button mat-raised-button color="accent">
{{user.firstName}} {{user.lastName}}
</button>
</mat-list-item>
</mat-list>
</mat-grid-tile>
</mat-grid-list>
.height100p {
height: 100%;
}
.mat-grid-tile-custom {
overflow: visible!important;
}
.custom-mat-list { /* this is bad! */
padding-top: 50%!important;
}
.mat-grid-tile-custom .mat-figure {
align-items: unset!important;
}
As you can see, the glaring error/problem here is the .custom-mat-list with a padding-top of 50%, this will be different between browsers, although technically this works, I don't think its a long term solution, if anuone has any thoughts/improvements or suggestions I would be very grateful.
Stackblitz example: https://stackblitz.com/edit/angular-cccnjp-3dieg1?file=app%2Fsidenav-responsive-example.css
Best Answer
mat-grid-list
andmat-list
layout component. It's not use to be content each other. You should pick one as a layout.For example you trying combine
mat-button-toggle
andmat-button
. like this:it doesn't work like that, right?
if your purpose to use 2 dimension, you can use grid only like this:
TL;DR;
Don't combine
list view
andgrid
, choose one. Or you will break material design spec, see grid Documentation.UPDATE
For loop data with to listview, use tab layout. check this out for sample:
Link:
https://stackblitz.com/edit/angular-cccnjp-ufqtvj?file=app/sidenav-responsive-example.html