angular-materialangular5angular-material2angular-material-6

Mat-select panel min-width


I'm trying to customize mat-select with multiple checkboxes. for some reason the panel get wrong min-width as below:

enter image description here

and I don't know where its calculating this min-width. also I tried to add panelClass and override the min-width from this class, for example:

<mat-select #multipleSelect (selectionChange)="selectItem($event.value)" panelClass="multiple-panel" multiple>      

&.multiple-panel {
   min-width: 200px !important;
}

but when opening the dropdown its open with the original width (like in the pic) and after few millisecond"jump" to the custom min-width defined on the panel class.

I find the mat-select very hard to style. anybody knows how to solve this problem?


Solution

  • You can style your mat-select dialog box by giving a panel class (as you mentioned).
    Please follow this demo : https://stackblitz.com/edit/angular-matselect-style?file=src/styles.css
    to see the styled mat-select components.

    Reason :


    Update 1 :
    Tried css animations, and opacity for making smooth opening of the mat-select options.

    .panel-class-applied-on-mat-select {
      animation-name: opacityDelay !important;
      animation-duration: 0.3s !important;
    }
    
    @keyframes opacityDelay {
       0%   {opacity: 0;}
      25%  {opacity: 0;}
      50%  {opacity: 0;}
      75%  {opacity: 0;}
      100% {opacity: 1;}
    }
    

    Updated StackBlitz Demo