aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Duplicated Render while using child component

Open hungdluit opened this issue 8 years ago • 2 comments

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

image

hungdluit avatar May 03 '18 15:05 hungdluit

I think the base classes should be abstract and not have a template of their own

dlr1 avatar May 03 '18 16:05 dlr1

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.

SteveSandersonMS avatar May 03 '18 23:05 SteveSandersonMS