Change the mat-autocomplete width?

后端 未结 5 2263
余生分开走
余生分开走 2021-02-13 17:42

It seems like the width is always the width of the input we\'re typing in. Is there no way to make it larger? I have a very small input and

相关标签:
5条回答
  • 2021-02-13 18:13

    Apart from what Athan Soulis says, I've found out by sheer coincidence that panelWidth also accepts value "fit", which does exactly what most of us is aiming for (make it as wide as needed). Not sure it's "any CSS sizing value", but it works.

    0 讨论(0)
  • 2021-02-13 18:28

    Just add the panelWidth property to the mat-autocomplete

    <mat-autocomplete [panelWidth]="300">
    

    0 讨论(0)
  • 2021-02-13 18:30

    I solved it with (dynamic):

     [panelWidth]="'auto'" 
    
    0 讨论(0)
  • 2021-02-13 18:33

    In the document for MatAutocomplete there is a property for exactly what you need:

    @Input() panelWidth: string | number

    Specify the width of the autocomplete panel. Can be any CSS sizing value, otherwise it will match the width of its host.

    By using this property you are not in the risk of meddling with anything else inherited from cdk-overlay-pane.

    For further customization you might find this property useful as well:

    @Input('class') classList: string

    Takes classes set on the host mat-autocomplete element and applies them to the panel inside the overlay container to allow for easy styling.

    0 讨论(0)
  • 2021-02-13 18:33

    mat-autocomplete styles are inherited from cdk-overlay-pane. In order to change width use below CSS.

    ::ng-deep .cdk-overlay-pane {
        /* Do you changes here */
          min-width:450px;
    }
    

    You can refer here for full example: https://stackblitz.com/edit/angular-vzetqy

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