How to customize mat-select dropdown position?

后端 未结 4 766
难免孤独
难免孤独 2020-12-17 10:38

Its been couple of days since i have not found the solution for this. As there is an option for mat-menu that is overlaptrigger property but there is no property to perform

相关标签:
4条回答
  • 2020-12-17 11:14

    I've found the solution as disableOptionCentering direcrive for mat-select, so after using this dropdaown can be customized.

    from timmoy: https://github.com/angular/material2/pull/9885

    Example usage:

    <mat-select
        [(ngModel)]="currentPokemon"
        [required]="pokemonRequired" 
        [disabled]="pokemonDisabled" 
        #pokemonControl="ngModel" 
        disableOptionCentering>
    <mat-option 
        *ngFor="let creature of pokemon" 
        [value]="creature.value">
    {{ creature.viewValue }}
    </mat-option>
    </mat-select>
    
    0 讨论(0)
  • 2020-12-17 11:17
    <mat-select placeholder="Language" disableOptionCentering panelClass="myPanelClass">
        <mat-option *ngFor="let locale of locales" [value]="locale">
            {{locale}}
        </mat-option>
    </mat-select>
    

    Utilize disableOptionCentering and panelClass like I have above. Then within your styles.scss reference your panelClass and do

    .myPanelClass{
        margin-top: 30px !important; 
    }
    

    This worked for me. Note that the scss must be in your styles.scss not your component's scss file. You might not need to use important here, I have other classes around this so I did use it.

    0 讨论(0)
  • 2020-12-17 11:29

    //Add this

    .mat-select-panel-wrap{
        position: relative;
        top: 26px;
    }
    
    .mat-select-panel-wrap .mat-select-panel{
        min-width: calc(100% + 12px) !important;
        transform: translateX(4px) !important
    }
    

    //Change 26px, 12px and 4px to what suit you.

    0 讨论(0)
  • 2020-12-17 11:33

    try updating

    .cdk-overlay-pane  { 
      position:absolute;
      pointer-events:auto;
      box-sizing:border-box;
      z-index:1000;
      display:flex;
      max-width:100%;
      max-height:100%;
      transform:none !important; 
      margin-top:22px;
    } 
    

    which is in @angular\material\prebuilt-themes\indigo-pink.css.

    added transform:none !important; margin-top:22px; which is working well for me.

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