Skip to content

[dev-v5] Update the ProgressBar.Visibility #3771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<FluentStack Orientation="@Orientation.Vertical">
<div>
Content before the ProgressBar
</div>
<FluentProgressBar Width="200px" Visible="@Visible" Style="height: 5px;" />
<div>
Content after the ProgressBar
</div>
</FluentStack>

<FluentSelect Items="@([true, false, null])"
OptionText="@(i => GetVisibleText(i) )"
TOption="bool?"
@bind-Value="@Visible" />

@code
{
bool? Visible = true;

string GetVisibleText(bool? visible)
{
return $"Visible = {(visible.HasValue ? (visible == true ? "true" : "false") : "null")}";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<FluentStack Orientation="@Orientation.Vertical">
<div>
Content before the ProgressBar
</div>
<FluentSpinner Visible="@Visible" />
<div>
Content after the ProgressBar
</div>
</FluentStack>

<FluentSelect Items="@([true, false, null])"
OptionText="@(i => GetVisibleText(i) )"
TOption="bool?"
@bind-Value="@Visible" />

@code
{
bool? Visible = true;

string GetVisibleText(bool? visible)
{
return $"Visible = {(visible.HasValue ? (visible == true ? "true" : "false") : "null")}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ The background color of the progress bar can be set using the `BackgroundColor`

{{ ProgressBarState }}

## Visible

The `Visible` parameter can be used to show or hide the progress bar.
This parameter is nullable:
- If `true` (default), the component is visible.
- If `false`, the component is hidden.
- If `null`, the component is hidden and not rendered.

{{ ProgressBarVisible }}

## API FluentProgressBar

{{ API Type=FluentProgressBar }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ In some situations, you may need to display a spinner on a dark background.

{{ SpinnerInverted }}

## Visible

The `Visible` parameter can be used to show or hide the progress bar.
This parameter is nullable:
- If `true` (default), the component is visible.
- If `false`, the component is hidden.
- If `null`, the component is hidden and not rendered.

{{ SpinnerVisible }}

## API FluentSpinner

{{ API Type=FluentSpinner }}
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Components/Progress/FluentProgressBar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@using Microsoft.FluentUI.AspNetCore.Components.Extensions
@inherits FluentComponentBase

@if (Visible)
@if (Visible.HasValue)
{
@if (HasCustomStyle)
{
Expand Down
8 changes: 6 additions & 2 deletions src/Core/Components/Progress/FluentProgressBar.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public partial class FluentProgressBar : FluentComponentBase, ITooltipComponent

/// <summary />
protected string? StyleValue => DefaultStyleBuilder
.AddStyle("visibility", "hidden", () => Visible == false)
.AddStyle("width", Width, () => !string.IsNullOrEmpty(Width))
.AddStyle("background-color", BackgroundColor, () => !string.IsNullOrEmpty(BackgroundColor))
.Build();
Expand Down Expand Up @@ -52,10 +53,13 @@ public partial class FluentProgressBar : FluentComponentBase, ITooltipComponent
public int? Value { get; set; }

/// <summary>
/// Gets or sets the visibility of the component
/// Gets or sets the visibility of the component.
/// If `true` (default), the component is visible.
/// If `false`, the component is hidden.
/// If `null`, the component is hidden and not rendered.
/// </summary>
[Parameter]
public bool Visible { get; set; } = true;
public bool? Visible { get; set; } = true;

/// <summary>
/// Gets or sets the component width.
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Components/Progress/FluentSpinner.razor
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@using Microsoft.FluentUI.AspNetCore.Components.Extensions
@inherits FluentComponentBase

@if (Visible)
@if (Visible.HasValue)
{
<fluent-spinner id="@Id"
class="@ClassValue"
Expand Down
8 changes: 6 additions & 2 deletions src/Core/Components/Progress/FluentSpinner.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ public partial class FluentSpinner : FluentComponentBase, ITooltipComponent

/// <summary />
protected string? StyleValue => DefaultStyleBuilder
.AddStyle("visibility", "hidden", () => Visible == false)
.Build();

/// <summary>
/// Gets or sets the visibility of the component
/// Gets or sets the visibility of the component.
/// If `true` (default), the component is visible.
/// If `false`, the component is hidden.
/// If `null`, the component is hidden and not rendered.
/// </summary>
[Parameter]
public bool Visible { get; set; } = true;
public bool? Visible { get; set; } = true;

/// <summary>
/// Gets or sets whether the spinner should be shown in an inverted color scheme (i.e. light spinner on dark background)
Expand Down
23 changes: 16 additions & 7 deletions tests/Core/Components/Progress/FluentProgressBarTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,28 @@
[Theory]
[InlineData(true)]
[InlineData(false)]
public void FluentProgressBar_Visible(bool visible)
[InlineData(null)]
public void FluentProgressBar_Visible(bool? visible)
{
// Act
var cut = Render(@<FluentProgressBar Visible="@visible" />);

// Assert
if (visible)
{
Assert.NotEmpty(cut.Markup);
}
else
switch (visible)
{
Assert.Empty(cut.Markup);
case true:
Assert.NotEmpty(cut.Markup);
Assert.DoesNotContain("visibility: hidden", cut.Markup);
break;

case false:
Assert.NotEmpty(cut.Markup);
Assert.Contains("visibility: hidden", cut.Markup);
break;

default:
Assert.Empty(cut.Markup);
break;
}
}

Expand Down
28 changes: 28 additions & 0 deletions tests/Core/Components/Progress/FluentSpinnerTests.razor
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@
}
}

[Theory]
[InlineData(true)]
[InlineData(false)]
[InlineData(null)]
public void FluentSpinner_Visible(bool? visible)
{
// Act
var cut = Render(@<FluentSpinner Visible="@visible" />);

// Assert
switch (visible)
{
case true:
Assert.NotEmpty(cut.Markup);
Assert.DoesNotContain("visibility: hidden", cut.Markup);
break;

case false:
Assert.NotEmpty(cut.Markup);
Assert.Contains("visibility: hidden", cut.Markup);
break;

default:
Assert.Empty(cut.Markup);
break;
}
}

#pragma warning disable CS0618
[Theory]
[InlineData(ProgressStroke.Small, "small")]
Expand Down