@inherits BlazorComponentBase
<button @attributes="@AdditionalAttributes">@ChildContent</button>
@code{
[Parameter]public RenderFragment? ChildContent { get; set; }
[CascadingParameter]EditContext? CascadedEditContext { get; set; }
protected override void BuildCssClass(ICssClassBuilder builder)
{
if(CascadedEditContext is not null)
{
builder.Append("modified");
var valid = CascadedEditContext.GetValidationMessages().Any();
if(valid)
{
builder.Remove("invalid");
}
}
}
}
public class Button : BlazorComponentBase, IHasChildContent
{
[Parameter]public RenderFragment? ChildContent { get; set; }
[CascadingParameter]EditContext? CascadedEditContext { get; set; }
protected override void BuildCssClass(ICssClassBuilder builder)
{
if(CascadedEditContext is not null)
{
builder.Append("modified");
var valid = CascadedEditContext.GetValidationMessages().Any();
if(valid)
{
builder.Remove("invalid");
}
}
}
}