Skip to content

Commit 2d79699

Browse files
authored
Implement internalized container style for counter badge (#4457)
1 parent 39c23a0 commit 2d79699

4 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/Core/Components/AppBar/FluentAppBarItem.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
@inherits FluentComponentBase
33

44
<div id=@Id @attributes="AdditionalAttributes" class="@ClassValue" style="@StyleValue" title="@(Tooltip ?? Text)">
5-
<FluentCounterBadge Count="@Count"
6-
ContainerStyle="display: inline;"
5+
<FluentCounterBadge @ref="@_counterBadge"
6+
Count="@Count"
77
Style="display: flex; flex-direction: column; align-items: center;"
88
Appearance="BadgeAppearance.Filled"
99
Color="BadgeColor.Danger"

src/Core/Components/AppBar/FluentAppBarItem.razor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Microsoft.FluentUI.AspNetCore.Components;
1414
/// </summary>
1515
public partial class FluentAppBarItem : FluentComponentBase, IAppBarItem
1616
{
17+
private FluentCounterBadge _counterBadge = default!;
18+
1719
/// <summary />
1820
public FluentAppBarItem(LibraryConfiguration configuration) : base(configuration)
1921
{
@@ -97,6 +99,15 @@ protected override void OnInitialized()
9799
}
98100
}
99101

102+
/// <summary />
103+
protected override void OnAfterRender(bool firstRender)
104+
{
105+
if (firstRender)
106+
{
107+
_counterBadge.SetContainerStyle("display: inline;");
108+
}
109+
}
110+
100111
/// <summary />
101112
protected virtual string? ClassValue => DefaultClassBuilder
102113
.AddClass("fluent-appbar-item")

src/Core/Components/Badge/FluentBadge.razor.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@ public FluentBadge(LibraryConfiguration configuration) : base(configuration) { }
119119
[Parameter]
120120
public sbyte? OffsetY { get; set; }
121121

122-
/// <summary>
123-
/// Gets or sets the CSS styles applied to the badge container.
124-
/// </summary>
125-
[Parameter]
126-
public string? ContainerStyle { get; set; }
127-
128122
/// <summary />
129123
protected override void OnParametersSet()
130124
{
@@ -153,6 +147,7 @@ protected string GetIconColor()
153147

154148
internal void SetContainerStyle(string style)
155149
{
156-
_containerStyle = style;
150+
_containerStyle = style;
151+
StateHasChanged();
157152
}
158153
}

src/Core/Components/Badge/FluentCounterBadge.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@namespace Microsoft.FluentUI.AspNetCore.Components
22
@using Microsoft.FluentUI.AspNetCore.Components.Extensions
33
@inherits FluentBadge
4-
<AddTag Name="fluent-counter-badge-container" TagWhen="@(() => _isAttached && _render)" style="@ContainerStyle">
4+
<AddTag Name="fluent-counter-badge-container" TagWhen="@(() => _isAttached && _render)" style="@_containerStyle">
55
@ChildContent
66
@if (_render)
77
{

0 commit comments

Comments
 (0)