Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make scrollable mat-list

I'm trying to build a mat-list inside a responsive height container with Angular 4.4.6 and Angular Material 2.0.0-beta.12. How can I make the mat-list scrollable without overflowing parent container?

Here's the stackblitz URL: https://stackblitz.com/edit/angular-material2-issue-tedisv?file=app%2Fapp.component.scss

:host{
  border: 3px dashed red;
  width: 100%;
  min-height: 150px;
  max-height: 350px;
  height: 10%;
  display: flex;
  flex-direction: column;
  mat-toolbar {
    flex-grow: 0;
  }
  mat-list {
    flex-grow: 1;
    border: 3px solid green;
  }
}
like image 533
Halil İbrahim Karaalp Avatar asked Oct 23 '17 10:10

Halil İbrahim Karaalp


People also ask

How do I make my mat list scrollable?

Virtual Scrolling can be easily implemented with MatList by adding cdk-virtual-scroll-viewport directive inside mat-list component. Make sure ScrollingModule will have to be imported in your module.

How do I create a horizontal scrolling container?

To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.

What is virtual scrolling?

Virtual scrolling allows the Grid component to display thousands of records on a single page. You can use this feature as an alternative to paging. Browser Support Notes: The following browsers do not support virtual scrolling because they do not support position: sticky : Android Browser before 5.0.


2 Answers

mat-list {
    flex-grow: 1;
    border: 3px solid green;
    overflow: auto;
}

I'm sure that i've tried overflow: auto; yesterday (before posting the question) and it didn't worked. But today it works. I may have faced a caching issue related to ng cli or browser cache.

like image 139
Halil İbrahim Karaalp Avatar answered Oct 22 '22 00:10

Halil İbrahim Karaalp


add the following css:

mat-list { overflow: auto; }
like image 23
J. Jerez Avatar answered Oct 22 '22 00:10

J. Jerez