fluentui-blazor: fix: `FluentButton` has `Icon` in wrong `slot` if `ChildContent`, when `null`, is left in markup
🐛 Bug Report
Using FluentButton to be, depending on a given parameter, either in “ico-only mode” or with a label next to the icon, the icon is added to the wrong slot.
💻 Repro or Code Sample
Create a razor component with this markup:
@* NOTE: Formatted for readability, bug still occurs if written as one-liner! *@
<FluentButton IconStart="new Microsoft.FluentUI.AspNetCore.Components.Icons.Regular.Size24.SignOut()">
@ChildContent
</FluentButton>
🤔 Expected Behavior
Button:
Code:
😯 Current Behavior
Button:
Code:
💁 Possible Solution
If ChildContent is null, i.e., “not there”, Icon should act accordingly & move into the default slot instead of start - this is even the default behavior of Razor, not only Blazor.
For now, I have to violate DRY by doing this:
@if (ChildContent is not null)
{
<FluentButton IconStart="Icon" Id="@Id">@ChildContent</FluentButton>
}
else
{
@* NOTE: In reality, I simplify the line below into an empty / self-closing / standalone tag *@
<FluentButton IconStart="Icon" Id="@Id"></FluentButton>
}
🔦 Context
Implementation of a button component, toggleable to either “icon-only” or “icon with label” mode.
🌍 Your Environment
- OS & Device: negligible
- Browser: Firefox Dev Edition, latest version
- .NET & Fluent UI Blazor: 8.0.10 & 4.10.2
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16
Best of luck with the demo!! I’ll be away a couple of days starting Wednesday, so not a lot of time anymore for any last minute fixes, I’m afraid. We’ll probably release v4.10.3 later today or tomorrow.
@Eagle3386 This is a problem when ‘transferring’ your
ChildContentobject. You must use theChildContentproperty and not render thisChildContentin your component. By requesting this rendering in your component, theFluentButton.ChildContentproperty is no longernullbutEmpty.I guess we both are in need of the weekend… 😁. Let’s look at it again next week.