Mat-select panel min-width

前端 未结 4 1322
灰色年华
灰色年华 2021-02-10 15:00

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

and I don\'t know where its calculating t

相关标签:
4条回答
  • 2021-02-10 15:36

    You'll need to change viewEncapsulation to none at your component decorator.and then add following css to remove the transition effect.Have a look at viewencapsulation in angular docs https://angular.io/guide/component-styles#view-encapsulation.

    @Component({
    selector: 'app-selector',
    templateUrl: './template.html',
    styleUrls: ['./template.css'],
    encapsulation: ViewEncapsulation.None
    })
    //CSS
    .cdk-overlay-connected-position-bounding-box .cdk-overlay-pane .mat-select-panel.ng-animating {
    display: none;
    }
    
    0 讨论(0)
  • 2021-02-10 15:45

    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 :

    • Reason for the delay is that angular for dialog-boxes, create a cdk-overlay-pane inside the cdk-overlay-container container, So in case of mat-select it provides a min-width of 180px, which is overridden by our panel class in the slight delay.
    • Yes, there is a slight delay in opening of dialog box and customizing its width to the specified width provided in the panel class. But the delay is acceptable in the project that i was working on.
      So, you can find the demo for styling the mat-select component, as i have provided 2 components and you can modify any css properties.
    • Try to use styles using ::ng-deep or :host >>>, if not finding any luck,
      please paste the styles in style.css.


    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

    0 讨论(0)
  • 2021-02-10 15:50

    I used another approach. Just added this piece of code to global style.

    .mat-select-panel {
    // some your code
      &.ng-animating {
           visibility: hidden;
        }
      }
    

    You can try this solution on DEMO StackBlitz.
    Hack with opacity did not fix jumping width when select is closing.

    0 讨论(0)
  • 2021-02-10 15:59

    Try this way : define a panel class for your mat-select in the code and then in the global/app styling file just add:

    .panel-class-name .mat-select-panel {
     // add your styling here
    }
    

    It worked for me to add some component specific styling for material components.

    0 讨论(0)
提交回复
热议问题