I am currently migrating from angular 16 to angular 17. Its a mat-icon to delete an entry from a list in a mat menu with some information text next to it. Before everything was aligned correctly but after the update the generated html code adds a span-tag with a class called "mat-mdc-menu-item-text". Angular automatically places all the text in the mat-menu-item in the mat-mdc-menu-item-text span and leaves the mat-icon outside of the generated span tag causing the icon to be completely misaligned with the text. Is there a possibility to deactivate this generated span or move the mat-icon into it?
Here the angular template
<div mat-menu-item *ngFor="let ele of arr; let i = index" class="one-row">
<mat-icon class="one-cell"
(click)="click($event, i)">clear
</mat-icon>
<span class="one-cell">
{{ele.info}}
</span>
<span class="one-cell">
{{ele.info2}}
</span>
</div>
</div>
And here is exemplary the html from chromes inspector for one row of the mat-menu:
<div class="one-row ...">
<mat-icon class="...">clear<mat-icon>
<span class="mat-mdc-menu-item-text">
<span class="...">ele.info</span>
<span class="...">ele.info2</span>
</span>
</div>
The <span class="mat-mdc-menu-item-text">
adds some padding and line-height that changes the design of the row completely.
2
Answers
While Naren Murali's answer, with setting the css properties, is correct, I generally do not want to use the
important
property if possible but I found another workaround: Since all the span tags get moved to the menu-item-text I wrapped the content of the mat-menu-item with another span and aligned it afterwards like thisapp.component.html
app.component.scss
Its not possible to remove generated html since its coming from the mat-menu programmatically, changing it involves modifying the library which is problematic, just write some CSS to override these changes and bring your UI back to its original state!