angular / angular/components

bug(COMPONENT): mat-icon-button needs to be wrapped to apply density

Offen
#30,118 2 Kommentare 8 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
area: material/button P3
Vorherrschende Sprache
TypeScript
Sterne
25k
Forks
6.8k
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
91

Beschreibung

### Is this a regression?

- [ ] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

_No response_

### Description

When applying custom density (via a custom CSS class) using Angular Material Theme API directly to Angular Material button (e.g., mat-flat-button, mat-stroked-button), the height is adjusted as expected. However, when the custom density context (the same CSS class as for mat-stroked-button etc) is applied directly to a button mat-icon-button, the size of it remains unchanged. The density changes are only applied if the mat-icon-button is wrapped in an element with the density class.

### Reproduction

StackBlitz link: https://stackblitz.com/edit/sb1-41rfph?file=src%2Fapp%2Fapp.component.scss
StackOverflow link: https://stackoverflow.com/questions/79227144/mat-icon-button-needs-to-be-wrapped-to-apply-density

Steps to reproduce:
1. Create css class:
`.ui-high-density {
@include mat.icon-button-density(-2);
}`

2. Apply css class .ui-high-density to button:
A. mat-flat-button
`Some text`
B. mat-icon-button
`Some text`

### Expected Behavior

The size of height on both, mat-flat-button and mat-icon-button, will change.

### Actual Behavior

The height change only on mat-flat-button and mat-icon-button stay the same.

When I wrapped mat-icon-button into div with class ui-hight-density, the height of button changed.
`

`
` `
` home`
` `
`
`

### Environment

- Angular: 18.2.11
- CDK/Material: 18.2.13
- Browser(s): Google Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): macOS Sonoma

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der StackBlitz-Reproduktion in src/app/app.component.scss und dem im Issue beschriebenen mat.icon-button-density(-2)-Mixin. Vergleiche, wie die Dichte direkt auf mat-flat-button angewendet wird, mit dem direkten mat-icon-button-Fall. Überprüfe anschließend, dass sich der Icon-Button ohne Wrapper in seiner Größe ändert und die Reproduktion dem erwarteten Verhalten entspricht.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
angular, scss, typescript
Bereich
frontend
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.