Skip to main content

LgRadioGroup / LgRadio

LgRadioGroup<TValue> binds a single value to a group of radio buttons; each option is an LgRadio carrying its value (Value) and label (Text or child content). An LgRadio must always be declared within an LgRadioGroup (an exception is thrown otherwise).

<LgRadioGroup Label="#Priority" @bind-Value="_model.Priority">
<Items>
<LgRadio Text="#PriorityLow" Value="Priority.Low" />
<LgRadio Text="#PriorityNormal" Value="Priority.Normal" />
<LgRadio Text="#PriorityHigh" Value="Priority.High" />
</Items>
</LgRadioGroup>
  • Namespace: Lagoon.UI.Components
  • Inherits from: LgInputBase<TValue> (LgRadioGroup); LgAriaComponentBase (LgRadio)
  • NuGet package: Lagoon.UI

Usage​

Demo​

Try this component in the Lagoon showcase.

Simple group​

TaskEditPage.razor
<LgRadioGroup Label="#Priority" @bind-Value="_model.Priority">
<Items>
<LgRadio Text="#PriorityLow" Value="Priority.Low" />
<LgRadio Text="#PriorityNormal" Value="Priority.Normal" />
<LgRadio Text="#PriorityHigh" Value="Priority.High" Tooltip="#PriorityHighHelp" />
</Items>
</LgRadioGroup>
TaskEditPage.razor.cs
public partial class TaskEditPage : LgPage
{
private readonly TaskVm _model = new();

private enum Priority
{
Low,
Normal,
High
}

private sealed class TaskVm
{
public Priority Priority { get; set; }
}
}

Orientation and style​

DisplayOrientation stacks options vertically (by default) or aligns them horizontally. DisplayKind chooses the rendering: classic round checkbox or "modern" style without a box.

DisplayModePage.razor
<LgRadioGroup Label="#DisplayMode"
DisplayOrientation="DisplayOrientation.Horizontal"
DisplayKind="RadioButtonDisplayKind.Modern"
@bind-Value="_model.Mode">
<Items>
<LgRadio Text="#ModeList" Value="1" />
<LgRadio Text="#ModeCards" Value="2" />
</Items>
</LgRadioGroup>
DisplayModePage.razor.cs
public partial class DisplayModePage : LgPage
{
private readonly DisplayVm _model = new();

private sealed class DisplayVm
{
public int Mode { get; set; } = 1;
}
}

Rich content and disabled option​

ChildContent of an LgRadio replaces the text label; Disabled disables an option without hiding it.

PlanPage.razor
<LgRadioGroup Label="#Plan" @bind-Value="_model.Plan">
<Items>
<LgRadio Value="@("standard")">
<strong>Standard</strong> — <LgIcon IconName="@IconNames.All.Check" />
</LgRadio>
<LgRadio Text="#PremiumPlan" Value="@("premium")" Disabled="true" />
</Items>
</LgRadioGroup>
PlanPage.razor.cs
public partial class PlanPage : LgPage
{
private readonly PlanVm _model = new();

private sealed class PlanVm
{
public string Plan { get; set; } = "standard";
}
}

Cancel a selection change​

OnChangingAsync is called before the assignment and allows canceling the change (args.Cancel); OnChange (inherited) is called after.

SubscriptionPage.razor
<LgRadioGroup Label="#Subscription"
OnChangingAsync="OnSubscriptionChangingAsync"
@bind-Value="_model.Subscription">
<Items>
<LgRadio Text="#Monthly" Value="@("monthly")" />
<LgRadio Text="#Yearly" Value="@("yearly")" />
</Items>
</LgRadioGroup>
SubscriptionPage.razor.cs
public partial class SubscriptionPage : LgPage
{
private readonly SubscriptionVm _model = new();

// Called before the change: blocks switching to monthly during an active commitment.
private Task OnSubscriptionChangingAsync(ChangingEventArgs<string> args)
{
if (args.NewValue == "monthly" && _model.HasCommitment)
{
args.Cancel = true;
ShowWarning("#CommitmentInProgress");
}
return Task.CompletedTask;
}

private sealed class SubscriptionVm
{
public string Subscription { get; set; } = "yearly";
public bool HasCommitment { get; set; } = true;
}
}

Properties​

LgRadioGroup<TValue>​

All [Parameter] properties of the component, including inherited ones.

NameTypeDefaultDeclared inDescription
DisplayKindRadioButtonDisplayKindClassicLgRadioGroupDisplay style for radio buttons.
DisplayOrientationDisplayOrientationVerticalLgRadioGroupOrientation of options.
GroupNamestringnullLgRadioGroupName of the group (radio name attribute). Generated if absent.
ItemsRenderFragmentnullLgRadioGroupThe options, declared with LgRadio.
OnChangingAsyncFunc<ChangingEventArgs<TValue>, Task>nullLgRadioGroupCallback called before the value changes; the change can be canceled.
AdditionalAttributesIReadOnlyDictionary<string, object>nullLgInputBaseAdditional HTML attributes applied to the rendered element.
AutoFocusboolfalseLgInputBaseGives focus to the group on first render.
ConfirmationMessagestringnullLgInputBaseConfirmation message displayed before applying a selection change.
ContainerIInputContainer<TValue>nullLgInputBaseInternal use: attaches a GridView cell to the group.
CssClassstringnullLgInputBaseAdditional CSS classes.
DisabledboolfalseLgInputBaseDisables the entire group.
DisplayNamestringnullLgInputBaseField name used in error messages.
HideValidationMessageboolfalseLgInputBaseHides the validation message below the group.
LabelstringnullLgInputBaseLabel of the group.
LabelContentRenderFragmentnullLgInputBaseCustom content for the label area.
OnChangeEventCallback<ChangeEventArgs>—LgInputBaseCallback called after the selection changes.
OnResetEventCallback<ChangeEventArgs>—LgInputBaseCallback called on reset.
PolicyEditstringnullLgInputBasePolicy required to edit the group.
PolicyVisiblestringnullLgInputBasePolicy required to display the group.
ReadOnlyboolfalseLgInputBaseDisplays the selection as read-only.
Requiredbool?nullLgInputBaseRequired field. If null, inferred from the [Required] attribute of the bound property.
ResetButtonbool?nullLgInputBaseDisplays the reset button. If null, the application behavior configuration applies.
ResetTextstringnullLgInputBaseText of the reset button.
ResetTextAriaLabelstringnullLgInputBaseAccessible label (aria-label) for the reset button.
TooltipstringnullLgInputBaseTooltip for the group.
TooltipIsHtmlboolfalseLgInputBaseIndicates if the Tooltip content is HTML format (otherwise plain text).
ValueTValue—LgInputBaseSelected value (@bind-Value).
ValueChangedEventCallback<TValue>—LgInputBaseCallback for updating the bound value.
ValueExpressionExpression<Func<TValue>>—LgInputBaseExpression identifying the bound property.
AriaLabelstringnullLgAriaComponentBaseValue of the aria-label attribute.
AriaLabelledBystringnullLgAriaComponentBaseValue of the aria-labelledby attribute.

LgRadio<TValue>​

NameTypeDefaultDeclared inDescription
AdditionalAttributesIReadOnlyDictionary<string, object>nullLgRadioAdditional HTML attributes applied to the input element.
ChildContentRenderFragmentnullLgRadioRich content for the option label (instead of Text).
CssClassstringnullLgRadioAdditional CSS classes for the option.
DisabledboolfalseLgRadioDisables the option.
TextstringnullLgRadioLabel for the option.
TooltipstringnullLgRadioTooltip for the option.
TooltipIsHtmlboolfalseLgRadioIndicates if the Tooltip content is HTML format (otherwise plain text).
ValueTValue—LgRadioValue carried by this option.
AriaLabelstringnullLgAriaComponentBaseValue of the aria-label attribute.
AriaLabelledBystringnullLgAriaComponentBaseValue of the aria-labelledby attribute.
Cascading parameters

LgRadio receives its parent group through the cascading parameter RadioGroup (ILgRadioGroup) — it must be declared within the Items of an LgRadioGroup.

Events​

EventTypeDescription
OnChangingAsyncFunc<ChangingEventArgs<TValue>, Task>Before the selection changes; args.Cancel = true cancels it.
OnChangeEventCallback<ChangeEventArgs>After the selection changes.
OnResetEventCallback<ChangeEventArgs>On group reset.

Associated enumerations​

DisplayOrientation​

ValueDescription
VerticalOptions stacked vertically (default value).
HorizontalOptions aligned horizontally.

RadioButtonDisplayKind​

ValueDescription
ClassicRound checkbox displayed next to the label (default value).
ModernSelected text style, without a checkbox.

Best practices / accessibility​

  • For more than a few options, prefer LgSelect: the dropdown list remains readable as choices multiply.
  • Add a Tooltip to options whose short label deserves clarification, rather than lengthening the label.
Complete reference

All parameters (including inherited ones): API reference — LgRadioGroup · LgRadio.