2

I'd like to disable the scrollbar when I have more than 5 options:

enter image description here

Code:

https://stackblitz.com/edit/angular-select-size?file=app/select-overview-example.html

Demo:

https://angular-select-size.stackblitz.io

I tried to use the "size" option, however I found that is not available:

<mat-option ng-size=8 *ngFor="let food of foods" [value]="food.value">
  {{food.viewValue}}
</mat-option>
Nick
  • 67
  • 2
  • 9
  • Possible duplicate of [Disable Scrolling when angular-material select is open](https://stackoverflow.com/questions/46888635/disable-scrolling-when-angular-material-select-is-open) – Saksham May 12 '19 at 12:54

5 Answers5

4

Previous answers did not work directly for me and I needed ::ng-deep (/deep/ to be deprecated see - What do /deep/ and ::shadow mean in a CSS selector?)

i.e.

::ng-deep .mat-select-panel {
  max-height: none !important;
}


::ng-deep .mat-select-panel {
  max-height: 400px!important;
}
Andrew Allen
  • 6,512
  • 5
  • 30
  • 73
2
//add this code to you styles.css

   ::ng-deep .mat-select-panel{
       max-height: none!important;
    }
1

You can edit the height of the select panel.

Add this code to your styles.css

.mat-select-panel {
  max-height: 400px !important;
}

The number 400px is a random one. If your data are too many you must add a bigger number.

https://stackblitz.com/edit/angular-select-size-8vkutp

tufonas
  • 303
  • 1
  • 7
1

Add this code to you global styles.css

.my-select.mat-select-panel{
  max-height: none!important;
}

Include panelClass="my-select" property in the mat-select component.

BrunoDee
  • 21
  • 4
  • Should be marked as the correct answer if you want to have max-height for a specific mat-select – mr3k Nov 10 '20 at 07:57
1

Solution if you don't want to use !important. The panel takes the id of the mat-select with -panel suffix :

<mat-select id="dumb-id"
...
::ng-deep #dumb-id-panel {
  max-height: none;
}
ibenjelloun
  • 7,425
  • 2
  • 29
  • 53