Skip to main content

LgCheckBoxList

LgCheckBoxList<TValue> displays a checkbox group and binds the set of checked values to a collection (ICollection<TValue>). Each checkbox is declared with a LgCheckBoxListItem carrying its value and text.

<LgCheckBoxList Label="#Options" @bind-Value="_model.SelectedOptions">
<Items>
<LgCheckBoxListItem Text="#Option1" Value="1" />
<LgCheckBoxListItem Text="#Option2" Value="2" />
</Items>
</LgCheckBoxList>
  • Namespace : Lagoon.UI.Components
  • Inherits from : LgInputBase<ICollection<TValue>> → LgAriaComponentBase → LgComponentBase
  • NuGet package : Lagoon.UI

Usage​

Demonstration​

Try this component in the Lagoon showcase.

Simple group​

OptionsPage.razor
<LgCheckBoxList Label="#Options" @bind-Value="_model.SelectedOptions">
<Items>
<LgCheckBoxListItem Text="#Option1" Value="1" />
<LgCheckBoxListItem Text="#Option2" Value="2" />
<LgCheckBoxListItem Text="#Option3" Value="3" Disabled="true" />
</Items>
</LgCheckBoxList>
OptionsPage.razor.cs
public partial class OptionsPage : LgPage
{
private readonly OptionsVm _model = new();

private sealed class OptionsVm
{
// Bound collection: contains the values of the checked checkboxes.
public List<int> SelectedOptions { get; set; } = new();
}
}

Orientation and rendering​

DisplayOrientation stacks checkboxes vertically (default) or aligns them horizontally. CheckBoxKind renders each checkbox as a checkbox or toggle, and TextPosition places text to the left or right.

DaysPage.razor
<LgCheckBoxList Label="#WorkingDays"
DisplayOrientation="DisplayOrientation.Horizontal"
CheckBoxKind="CheckBoxKind.Toggle"
TextPosition="CheckBoxTextPosition.Right"
@bind-Value="_model.WorkingDays">
<Items>
<LgCheckBoxListItem Text="#Monday" Value="DayOfWeek.Monday" />
<LgCheckBoxListItem Text="#Tuesday" Value="DayOfWeek.Tuesday" />
<LgCheckBoxListItem Text="#Wednesday" Value="DayOfWeek.Wednesday" />
</Items>
</LgCheckBoxList>
DaysPage.razor.cs
public partial class DaysPage : LgPage
{
private readonly DaysVm _model = new();

private sealed class DaysVm
{
public List<DayOfWeek> WorkingDays { get; set; } = new();
}
}

Cancel a selection change​

OnChangingAsync is called before the collection is updated; args.ItemsToAdd / args.ItemsToRemove detail the change and args.Cancel cancels it.

ModulesPage.razor
<LgCheckBoxList Label="#Modules"
OnChangingAsync="OnModulesChangingAsync"
@bind-Value="_model.Modules">
<Items>
<LgCheckBoxListItem Text="#CoreModule" Value="@("core")" />
<LgCheckBoxListItem Text="#ReportingModule" Value="@("reporting")" />
</Items>
</LgCheckBoxList>
ModulesPage.razor.cs
public partial class ModulesPage : LgPage
{
private readonly ModulesVm _model = new();

// Called before the change: prevents unchecking the required module.
private Task OnModulesChangingAsync(ChangingCollectionEventArgs<string> args)
{
if (args.ItemsToRemove.Contains("core"))
{
args.Cancel = true;
ShowWarning("#CoreModuleRequired");
}
return Task.CompletedTask;
}

private sealed class ModulesVm
{
public List<string> Modules { get; set; } = new() { "core" };
}
}

Properties​

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

NameTypeDefaultDeclared inDescription
CheckBoxKindCheckBoxKindCheckLgCheckBoxListRendering of checkboxes: checkbox or toggle.
DisplayOrientationDisplayOrientationVerticalLgCheckBoxListOrientation of checkboxes.
ItemsRenderFragmentnullLgCheckBoxListThe checkboxes, declared with LgCheckBoxListItem.
OnChangingAsyncFunc<ChangingCollectionEventArgs<TValue>, Task>nullLgCheckBoxListCallback called before the collection change; the change can be canceled there.
TextPositionCheckBoxTextPositionLeftLgCheckBoxListText position of each checkbox.
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<ICollection<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 selection change.
OnResetEventCallback<ChangeEventArgs>—LgInputBaseCallback called on reset.
PolicyEditstringnullLgInputBasePolicy required to edit the group.
PolicyVisiblestringnullLgInputBasePolicy required to display the group.
ReadOnlyboolfalseLgInputBaseDisplays the selection in read-only mode.
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) of the reset button.
TooltipstringnullLgInputBaseTooltip.
TooltipIsHtmlboolfalseLgInputBaseIndicates whether the Tooltip content is in HTML format (otherwise plain text).
ValueICollection<TValue>nullLgInputBaseCollection of checked values (@bind-Value).
ValueChangedEventCallback<ICollection<TValue>>—LgInputBaseCallback for updating the bound collection.
ValueExpressionExpression<Func<ICollection<TValue>>>—LgInputBaseExpression identifying the bound property.
AriaLabelstringnullLgAriaComponentBaseValue of the aria-label attribute.
AriaLabelledBystringnullLgAriaComponentBaseValue of the aria-labelledby attribute.

LgCheckBoxListItem​

Each checkbox in the group is declared with a LgCheckBoxListItem :

NameTypeDefaultDescription
CssClassstringnullAdditional CSS classes for the checkbox.
DisabledboolfalseDisables the checkbox.
TextstringnullText of the checkbox.
TooltipstringnullTooltip of the checkbox.
TooltipIsHtmlboolfalseIndicates whether the Tooltip content is in HTML format.
ValueTValue—Value added to the collection when the checkbox is checked.
Cascading Parameters

LgCheckBoxList also consumes parameters automatically provided by ancestor components (you do not have to define them): ParentAuthorizeView (LgAuthorizeView) and the edit context of a parent LgEditForm.

Events​

EventTypeDescription
OnChangingAsyncFunc<ChangingCollectionEventArgs<TValue>, Task>Before the collection change; args.ItemsToAdd / args.ItemsToRemove detail the change, args.Cancel = true cancels it.
OnChangeEventCallback<ChangeEventArgs>After the collection change.
OnResetEventCallback<ChangeEventArgs>On group reset.

The enumerations used are documented on the base components: CheckBoxKind and CheckBoxTextPosition on LgCheckBox, DisplayOrientation on LgRadioGroup.

Best practices / Accessibility​

  • Initialize the bound collection with an empty list rather than null.
  • For a long list of choices, prefer LgSelect with multiple selection: the searchable dropdown list remains readable.
Complete Reference

All parameters (including inherited ones): API Reference — LgCheckBoxList.