Extending Radzen components

Hey, what is the recommended way of extending (Radzen) components? Typicaly, if i need to use some Radzen component 100 times with same set of parameters i'll wrap it in my own component. I'll set some parameters and the ones i'll potentionaly want to change i'll propagate from wrapper's own parameters. That's fine, but that way if i want in 2 instances from the initial 100 set some wrapped Radzen parameter i'm cut off and i need to expand my parameters. Is there a better way to do it?

[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object>? OtherAtributes { get; set; }

seems like a good fit potentionally but my wrapper components are not exactly 1:1 to the Blazor ones and i usually use CaptureUnmatchedValues to use on top element for standard html attributes.

Is there a better / recommended way?

Since you already use CaptureUnmatchedValues for the outer HTML element, you can use a separate dictionary parameter with a prefix convention for the inner component:

<div @attributes="OtherAttributes">
    <RadzenTextBox Value="@Value" @attributes="InnerAttributes" />
</div>

@codecode 
{
    [Parameter] 
    public string Value { get; set; }

    [Parameter] 
    Dictionary<string, object>? InnerAttributes { get; set; } 

    [Parameter(CaptureUnmatchedValues = true)]
    public Dictionary<string, object>? OtherAttributes { get; set; }
}

I didn't know that, cool... Not sure how blazor places atribute "class" given to my wrapper to OtherAttributes for applying to outer div and for example "MaxLength" to InnerAttributes for applying to the RadzenTextBox.

We use similar technique acrross all components that wraps HTML input - for example RadzenNumeric inherits from RadzenComponent which have Attributes:

and we have additionally InputAttributes for RadzenNumeric:

1 Like