aspnetcore
aspnetcore copied to clipboard
Duplicated Render while using child component
Version 0.3.0
CommandButton.cshtml
@using Microsoft.AspNetCore.Blazor
<div class="@GetClassNames()" ref="Root">
@ChildContent
@Text
</div>
@functions {
public ElementRef Root;
[Parameter]
protected RenderFragment ChildContent { get; set; }
[Parameter]
protected string Text { get; set; }
[Parameter]
protected ItemStyle Style { get; set; } = ItemStyle.None;
[Parameter]
protected bool IsOutLine { get; set; }
[Parameter]
protected ItemSize Size { get; set; } = ItemSize.Default;
private string GetClassNames()
{
IconButton a;
string buttonStyle = string.Empty;
if (Style != ItemStyle.None)
{
buttonStyle = Enum.GetName(typeof(ItemStyle), Style).ToLowerInvariant();
}
string outline = IsOutLine ? "outline" : string.Empty;
return ClassNames.Get("button", buttonStyle, outline);
}
}
IconButton.cshtml
@inherits CommandButton
<CommandButton Text=@Text Style=@Style>
<span class="@Icon"></span>
</CommandButton>
@functions {
[Parameter]
private string Icon { get; set; }
}
<IconButton Icon="mif-checkmark" Text="Click Me"></IconButton>
Rendered HTML

I think the base classes should be abstract and not have a template of their own
As far as I can tell, the render output is correct.
Your IconButton both inherits from and contains a CommandButton. So your render output will produce the output from CommandButton twice.
As @dlr1 comments, you should either not be inheriting from CommandButton, or CommandButton should not produce output.
We might change the APIs at some point to prevent people from doing this if it turns out to be a common mistake.