Class RadzenLabel
A label component for associating descriptive text with form input components. RadzenLabel creates accessible labels linked to input fields via the HTML for/id relationship. Provides descriptive text for form inputs, improving usability and accessibility. When properly associated with an input (via the Component property), clicking the label focuses the input. Features association linking to input components via the Component property (matching the input's Name), proper label/input relationships for screen readers, click behavior that focuses the associated input, and content display via Text property or custom content via ChildContent. Always use labels with form inputs for better UX and accessibility compliance. The Component property should match the Name property of the input it describes.
Inherited Members
Namespace: Radzen.Blazor
Assembly: Radzen.Blazor.dll
Syntax
public class RadzenLabel : RadzenComponent, IComponent, IHandleEvent, IHandleAfterRender, IDisposable
Examples
Basic label with input:
<RadzenLabel Text="Email Address" Component="EmailInput" />
<RadzenTextBox Name="EmailInput" @bind-Value=@email />
Label with custom content:
<RadzenLabel Component="PasswordInput">
Password <span style="color: red;">*</span>
</RadzenLabel>
<RadzenPassword Name="PasswordInput" @bind-Value=@password />
Constructors
RadzenLabel()
A label component for associating descriptive text with form input components. RadzenLabel creates accessible labels linked to input fields via the HTML for/id relationship. Provides descriptive text for form inputs, improving usability and accessibility. When properly associated with an input (via the Component property), clicking the label focuses the input. Features association linking to input components via the Component property (matching the input's Name), proper label/input relationships for screen readers, click behavior that focuses the associated input, and content display via Text property or custom content via ChildContent. Always use labels with form inputs for better UX and accessibility compliance. The Component property should match the Name property of the input it describes.
Declaration
public RadzenLabel()
Examples
Basic label with input:
<RadzenLabel Text="Email Address" Component="EmailInput" />
<RadzenTextBox Name="EmailInput" @bind-Value=@email />
Label with custom content:
<RadzenLabel Component="PasswordInput">
Password <span style="color: red;">*</span>
</RadzenLabel>
<RadzenPassword Name="PasswordInput" @bind-Value=@password />
Properties
ChildContent
Gets or sets custom child content to render as the label text. When set, overrides the Text property for displaying complex label content.
Declaration
[Parameter]
public RenderFragment ChildContent { get; set; }
Property Value
| Type | Description |
|---|---|
| RenderFragment | The label content render fragment. |
Component
Gets or sets the name of the input component this label is associated with. Must match the Name property of the target input component to create the proper label/input relationship. When set, clicking the label will focus the associated input.
Declaration
[Parameter]
public string Component { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The target component's name for label association. |
Text
Gets or sets the label text to display. For simple text labels, use this property. For complex content, use ChildContent instead.
Declaration
[Parameter]
public string Text { get; set; }
Property Value
| Type | Description |
|---|---|
| string | The label text. Default is empty string. |
Methods
BuildRenderTree(RenderTreeBuilder)
A label component for associating descriptive text with form input components. RadzenLabel creates accessible labels linked to input fields via the HTML for/id relationship. Provides descriptive text for form inputs, improving usability and accessibility. When properly associated with an input (via the Component property), clicking the label focuses the input. Features association linking to input components via the Component property (matching the input's Name), proper label/input relationships for screen readers, click behavior that focuses the associated input, and content display via Text property or custom content via ChildContent. Always use labels with form inputs for better UX and accessibility compliance. The Component property should match the Name property of the input it describes.
Declaration
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
| Type | Name | Description |
|---|---|---|
| RenderTreeBuilder | __builder |
Overrides
GetComponentCssClass()
Gets the component CSS class.
Declaration
protected override string GetComponentCssClass()
Returns
| Type | Description |
|---|---|
| string |