Skip to content

Commit babc3fa

Browse files
authored
fix(angular/badge): fix badge positioning on icon (#2246)
This fixes the positioning of badges on icons. Since I couldn't find any cases where the badge was positioned "above" on an icon, I would not consider this fix as a breaking change. Fixes #2225
1 parent 0121a8e commit babc3fa

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

src/angular/badge/badge.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ another object.
55
### Badge position
66

77
By default, the badge will be placed `above`. Alternatively `after` can be used.
8+
For `SbbIcon` components, the badge will always be placed in the top right corner of the icon,
9+
independent of the value of the position attribute.
810

911
### Badge visibility
1012

src/angular/styles/_typography.scss

+5
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,11 @@ textarea {
17461746
right: 0;
17471747
}
17481748

1749+
:where(.sbb-icon):is(.sbb-badge-above, .sbb-badge-after) & {
1750+
top: calc(#{sbb.pxToRem(-2)} * var(--sbb-scaling-factor));
1751+
right: 0;
1752+
}
1753+
17491754
.sbb-badge-hidden & {
17501755
display: none;
17511756
}

src/components-examples/angular/badge/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ng_module(
1515
deps = [
1616
"//src/angular/badge",
1717
"//src/angular/button",
18+
"//src/angular/icon",
1819
"@npm//@angular/core",
1920
],
2021
)
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
<h3 sbbBadge="4" [sbbBadgeHidden]="hidden">Text with a badge</h3>
22

3+
<h3>Icon with a badge</h3>
4+
<p>
5+
<sbb-icon svgIcon="bell-medium" sbbBadge="4" [sbbBadgeHidden]="hidden"></sbb-icon>
6+
</p>
7+
38
<button sbb-button (click)="toggleBadgeVisibility()">Toggle Badge</button>

src/components-examples/angular/badge/badge-overview/badge-overview-example.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component } from '@angular/core';
22
import { SbbBadgeModule } from '@sbb-esta/angular/badge';
33
import { SbbButtonModule } from '@sbb-esta/angular/button';
4+
import { SbbIcon } from '@sbb-esta/angular/icon';
45

56
/**
67
* @title Badge overview
@@ -9,7 +10,7 @@ import { SbbButtonModule } from '@sbb-esta/angular/button';
910
selector: 'sbb-badge-overview-example',
1011
templateUrl: 'badge-overview-example.html',
1112
standalone: true,
12-
imports: [SbbBadgeModule, SbbButtonModule],
13+
imports: [SbbBadgeModule, SbbButtonModule, SbbIcon],
1314
})
1415
export class BadgeOverviewExample {
1516
hidden = false;

0 commit comments

Comments
 (0)