bug(mat-button): several issues with mat-icon inside mat-button
- Dominant language
- TypeScript
- Stars
- 25k
- Forks
- 6.8k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 91
Description
### Is this a regression?
- [X] Yes, this behavior used to work in the previous version
### The previous version in which this bug was not present was
14
### Description
There are several issues when you are trying to use `mat-icon` inside `mat-button`.
Issue 1.
Button layout is not consistent if we are using `ng-container`, `mat-icon` is put in `.mdc-button__label` which leads to inconsistence in how styles are applied to an icon and text near it.
Of course `ng-container` as a structural component shouldn't have influence on how button is structured.
```
```
Issue 2.
Icon placed after text is appearing before text.
```
Label
```
### Reproduction
Steps to reproduce showing all 3 issues:
[Open that stackblitz](https://stackblitz.com/edit/angular-tyswc6?file=src/app/icon-overview-example.html)
### Expected Behavior
Issue 1.
`mat-icon` or any other custom content should be either inside or outside `.mdc-button__label` no matter what structural directives are used
Issue 2.
`mat-icon` should be at the same position relative to the text as it is in code
### Actual Behavior
Issue 1.
`mat-icon` is inside `.mdc-button__label` if inside `ng-container` in code and outside - if not
Issue 2.
`mat-icon` do not preserve an order implemented in code
### Environment
- Angular: 15.1.1
- CDK/Material: 15.1.1
- Browser(s): any
- Operating System (e.g. Windows, macOS, Ubuntu): any
Contributor guide
Research direction
Open the linked StackBlitz reproduction and compare mat-button/mat-icon behavior in Angular Material 15.1.1, including icons inside ng-container and after text. Done means custom content has consistent placement and mat-icon preserves the order written in the template.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100