Avoid padding loading icon on button when no text
lukedukeus opened this issue Β· comments
π Bug Report
The loading spinner is automatically given some padding/margin on the left hand side when loading
π» Repro or Code Sample
<FluentButton IconEnd="@(new Icons.Regular.Size16.ArrowClockwise())" Title="Refresh" Loading="@refreshing" OnClick="@Refresh" Appearance="Appearance.Outline" />
@code {
private bool refreshing = false;
private async Task Refresh()
{
refreshing = true;
await Task.Delay(1000);
refreshing = false;
}
}
π€ Expected Behavior
There should only be padding if there is text. The spinner should remain centered within the button.
π― Current Behavior
π Possible Solution
from https://github.com/microsoft/fluentui-blazor/blob/dev/src/Core/Components/Button/FluentButton.razor
, it looks like RingStyle doesn't apply if a starting icon is specified, maybe it needs to apply regaurdless, or maybe modify RingStyle to look at the buttons content? (I have no clue, just making a guess)
In https://github.com/microsoft/fluentui-blazor/blob/dev/src/Core/Components/Button/FluentButton.razor.cs
private string RingStyle(Icon icon)
{
var size = icon.Width;
var inverse = Appearance == AspNetCore.Components.Appearance.Accent ? " filter: invert(1);" : string.Empty;
var paddingLeft = string.IsNullOrEmpty(ChildContent) ? 0 : -5
return $"width: {size}px; height: {size}px;padding-left:{paddingLeft };{inverse}";
}
workaround:
<FluentButton Title="Refresh" OnClick="@Refresh" Appearance="Appearance.Outline" Disabled="@refreshing">
@if (refreshing)
{
<FluentProgressRing Width="12px"/>
}
else
{
<FluentIcon Value="@(new Icons.Regular.Size16.ArrowClockwise())" />
}
</FluentButton>
Will be fixed in the component with next release. See PR mentioned above.