Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding style to mat-option of mat-autocomplete

I have this HTML code here

<div style="width: 150px">
  <form class="example-form">
  <mat-form-field class="example-full-width">
    <input type="text" placeholder="Assignee" aria-label="Assignee" matInput [formControl]="myControl" [matAutocomplete]="auto">
    <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn">
      <mat-option *ngFor="let option of filteredOptions | async" [value]="option">
        {{option.name}}
      </mat-option>
    </mat-autocomplete>
  </mat-form-field>
</form>
</div>

The default behaviour of mat-option is using


  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis

  1. I want to break the long sentence into next line rather than using ... . The styling wont work :(

  2. I also need to override the font which I tried also using below code, but it wont override

mat-option {
    font-family: "Times New Roman", Times, serif; // does not work
  }

styling here

Please help.

like image 338
User985614 Avatar asked Sep 14 '25 16:09

User985614


1 Answers

You can add this to your CSS:

.mat-option{
  word-wrap:break-word !important;
  white-space:normal !important;
  font-family: "Times New Roman", Times, serif;
}

.mat-option-text{
  line-height:initial !important;
}
like image 145
Vincent Lim Avatar answered Sep 17 '25 07:09

Vincent Lim