is there a way to set a css class on a child component inside a Blazor component?
What i have right now is:
@using Microsoft.AspNetCore.Components;
@inherits ComponentBase
<div class="button-group-wrapper">
@SecondaryButton
<div class="floating-sticky-wrapper">
@PrimaryButton
</div>
</div>
@code {
[Parameter]
public RenderFragment PrimaryButton { get; set; }
[Parameter]
public RenderFragment SecondaryButton { get; set; }
}
I then "inject" the RenderFragments via:
<FloatingStickyButton>
<SecondaryButton>
<button type="button" class="button ...">Secondary</button>
</SecondaryButton>
<PrimaryButton>
<button type="submit" class="button button--primary ...">Primary</button>
</PrimaryButton>
</FloatingStickyButton>
What do i want?
I want to set the css class called "floating-sticky-button" on the primary button. But i would like to set this css class inside the component so that the programmer does not need to care about setting the class outside on the button element.
Something like this (Mind the @PrimaryButton here):
@using Microsoft.AspNetCore.Components;
@inherits ComponentBase
<div class="button-group-wrapper">
@SecondaryButton
<div class="floating-sticky-wrapper">
@PrimaryButton({class: 'floating-sticky-button'})
</div>
</div>
@code {
[Parameter]
public RenderFragment PrimaryButton { get; set; }
[Parameter]
public RenderFragment SecondaryButton { get; set; }
}
Unfortunately that doesn't work. Is there any way to do this?