9

The current drop-down box has width greater than the the width of the line:
enter image description here

Is there a way to get rid of the extra width?
enter image description here

Here is my current code:

html:

<mat-form-field>
    <mat-select disableOptionCentering placeholder="Choose an option">
      <mat-option [value]="option" *ngFor="let option of my_list">
          {{ option }}
      </mat-option>
    </mat-select>
</mat-form-field>


my_list:

export const my_list: string[] = [ "a", "b", "c", "d"];


style.css:

.mat-select-panel{
    margin-left: 15px;
    margin-top: 28px;
}
Meng
  • 1,148
  • 5
  • 15
  • 23
  • Possible duplicate: https://stackoverflow.com/questions/48605953/how-to-use-scroll-event-in-angular-material-mat-select – rikg93 Sep 18 '18 at 13:34
  • 3
    Hi RikG93, I don't think two posts are talking about the same thing. Here I want to reduce the width of the scrollable panel. The answer in the link provides a solution to load more when scrolling down in the scrollable panel. – Meng Sep 18 '18 at 13:47
  • 1
    Did you ever figure this out? I am trying to do the same. – cheesydoritosandkale Dec 26 '18 at 16:21
  • This is till a bug but here is a work around i found: https://github.com/angular/components/issues/14515 – Vlad Jul 24 '19 at 16:40
  • Did you try adding a class to the form container and set its width? – Jay Ordway Oct 24 '19 at 00:36

5 Answers5

6

For anyone still trying to figure out without making the actual select smaller or wider.

The mat-select-panel uses 100% of the mat-select width plus 32px

min-width: calc(100% + 32px)

You can override this styling with ng-deep:

::ng-deep .mat-select-panel {
    min-width: 100% !important;
}
3

Try this and change width:

   <mat-select style="width:10px">
rikg93
  • 1,101
  • 1
  • 11
  • 21
  • This moves the location of the mat-select-arrow. Is it possible to have the mat-select-arrow at the end and the width of scrollable panel = the width of the underline? – Meng Sep 18 '18 at 15:14
  • no this change the width, no the location. You could try min-width: calc(100%- 30px) where 30px is an example – rikg93 Sep 19 '18 at 11:23
2

Try this

.mat-select-panel:not([class*=mat-elevation-z]){ min-width: calc(100% + 0px) !important; }

Zubayer Bin Ayub
  • 310
  • 3
  • 11
2

set width at mat-form-field tag level. try this,

<mat-form-field style="width:50px">
0

\add class to mat-form-field tag

\and write style to that class

.input-container {
  width: 100%;
  \\  enter code here
}
Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62