Components: matBadge changes position after content is updated

Created on 6 Sep 2019  路  7Comments  路  Source: angular/components

Reproduction

https://stackblitz.com/edit/angular-f2fovj

  1. Wait 5 s, and see effect.

Expected Behavior

MatBadge should preserve its position after content is updated

Actual Behavior

MatBadge changes position after content is updated.

Environment

  • Angular:
  • CDK/Material:
  • Browser(s): Chrome (latest)
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 10
    image
P3 materiabadge

Most helpful comment

You can also just add "display: inline-block;" to the inline element instead of using mat-icon around it.

All 7 comments

Ok, the solution for this problem is not to use matBadge with _inline_ elements.

Is it supposed to be fixed or is it a limitation ?
I have strange behaviors too using badges with h1, h2 tags. The badge is moved to the right end of the page.

Regards

I found a hack for this issue
Use <mat-icon></mat-icon>
eg:
<mat-icon class="badge-icon" [matBadge]="data.responses?.length" matBadgePosition="above after" matBadgeOverlap="false" matBadgeSize="small" [matBadgeHidden]="data.responses.length < 1"></mat-icon>

You can also just add "display: inline-block;" to the inline element instead of using mat-icon around it.

Also affected with an Angular 10 (CLI 10.2.0, Material 10.2.7) application using a mat-checkbox inside a table header cell.

Worked around through the mat-icon as such :

        <th mat-header-cell *matHeaderCellDef>
          <mat-checkbox
             ...
-            [matBadgeColor]="items.length === 0 ? 'warn' : 'primary'"
-            [matBadge]="items.length"
           ></mat-checkbox>
+          <mat-icon
+            class="mat-checkbox-icon-badge"
+            [matBadgeColor]="items.length === 0 ? 'warn' : 'primary'"
+            [matBadge]="items.length"
+            matBadgePosition="above after"
+            matBadgeOverlap="true"
+          ></mat-icon>
         </th>
+.mat-checkbox-icon-badge {
+  height: 0px;
+  width: 0px;
+
+  .mat-badge-content {
+    right: -14px;
+    top: -25px;
+  }
+}

I use Font Awesome instead of Angular Icons and have the same issue. (I won't use Material Icons because they suck 馃構)

Any news? :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vitaly-t picture vitaly-t  路  3Comments

RoxKilly picture RoxKilly  路  3Comments

alanpurple picture alanpurple  路  3Comments

xtianus79 picture xtianus79  路  3Comments

michaelb-01 picture michaelb-01  路  3Comments