1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

How to set auto width of mat-select based on longest option?

Discussão em 'Angular' iniciado por avishekdr, Agosto 12, 2025.

  1. avishekdr

    avishekdr Guest

    I've a mat-select dropdown and want to set the width of the dropdown field to be the length of the longest option available plus some 10/20px padding. Also a max-width should be there so that there's a limit till 30-40 characters. I'm using Angular 19.

    <mat-select>
    <mat-option>Abcd</mat-option>
    <mat-option>This is test value</mat-option> <!-- width should take the length of this -->
    </mat-select>

    Continue reading...

Compartilhe esta Página