Skip to main content

LgTagBox

LgTagBox allows you to enter a list of text values as tags. Each validated value (enter, semicolon, or comma by default) becomes a removable tag. The bound value is a List<string>.

<LgTagBox Label="#Keywords" @bind-Value="_model.Keywords" />
  • Namespace: Lagoon.UI.Components
  • Inherits from: LgInputBase<List<string>> → LgAriaComponentBase → LgComponentBase
  • NuGet package: Lagoon.UI

Usage​

Demonstration​

Try this component in the Lagoon showcase.

Simple input​

ArticlePage.razor
<LgTagBox Label="#Keywords"
Placeholder="#AddKeyword"
@bind-Value="_model.Keywords" />
ArticlePage.razor.cs
public partial class ArticlePage : LgPage
{
private readonly ArticleVm _model = new();

private sealed class ArticleVm
{
public List<string> Keywords { get; set; } = new();
}
}

Limits and duplicates​

MaxTags limits the number of tags, MaxChars limits tag length. AllowDuplicates allows the same value twice. NoWrap fixes the field height with horizontal scrolling beyond.

RecipientsPage.razor
<LgTagBox Label="#Recipients"
MaxTags="5"
MaxChars="50"
NoWrap="true"
@bind-Value="_model.Recipients" />
RecipientsPage.razor.cs
public partial class RecipientsPage : LgPage
{
private readonly RecipientsVm _model = new();

private sealed class RecipientsVm
{
public List<string> Recipients { get; set; } = new();
}
}

Validation keys and delimiter​

ConfirmKeys lists the key codes that validate a tag (default 13, 59, 44: enter, semicolon, comma). Delimiter is the separator used to join values (semicolon by default).

TagsPage.razor
@* Validation by enter key only, values joined by comma. *@
<LgTagBox Label="#Tags"
ConfirmKeys="_confirmKeys"
Delimiter=","
@bind-Value="_model.Tags" />
TagsPage.razor.cs
public partial class TagsPage : LgPage
{
// Key codes that validate a tag: 13 = enter.
private readonly List<int> _confirmKeys = new() { 13 };

private readonly TagsVm _model = new();

private sealed class TagsVm
{
public List<string> Tags { get; set; } = new();
}
}

Input mask​

InputMaskKind and InputMask constrain the format of each tag (like on LgTextBox). AutoUnmask returns the value without the mask and ClearIncomplete clears the input if the mask is incomplete.

PhoneListPage.razor
<LgTagBox Label="#PhoneNumbers"
InputMaskKind="InputMaskKind.Mask"
InputMask="99-99-99-99-99"
AutoUnmask="true"
ClearIncomplete="true"
@bind-Value="_model.PhoneNumbers" />
PhoneListPage.razor.cs
public partial class PhoneListPage : LgPage
{
private readonly PhoneListVm _model = new();

private sealed class PhoneListVm
{
public List<string> PhoneNumbers { get; set; } = new();
}
}

React to value changes​

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

LabelsPage.razor
<LgTagBox Label="#Labels"
OnChangingAsync="OnLabelsChangingAsync"
@bind-Value="_model.Labels" />
LabelsPage.razor.cs
public partial class LabelsPage : LgPage
{
private readonly LabelsVm _model = new();

// Called before change: refuses reserved labels.
private Task OnLabelsChangingAsync(ChangingEventArgs<List<string>> args)
{
if (args.NewValue is not null && args.NewValue.Contains("admin"))
{
args.Cancel = true;
ShowWarning("#ReservedLabel");
}
return Task.CompletedTask;
}

private sealed class LabelsVm
{
public List<string> Labels { get; set; } = new();
}
}

Properties​

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

NameTypeDefaultDeclared inDescription
AllowDuplicatesboolfalseLgTagBoxAllows the same tag multiple times.
AutoUnmaskboolfalseLgTagBoxReturns the value without the mask when InputMask is used.
ClearIncompleteboolfalseLgTagBoxClears the value if the input mask is incomplete.
ConfirmKeysList<int>[13, 59, 44]LgTagBoxKey codes that validate a tag (enter, semicolon, comma by default).
Delimiterstring";"LgTagBoxSeparator used to join values.
InputMaskstringnullLgTagBoxInput mask applied to each tag.
InputMaskKindInputMaskKindNoneLgTagBoxType of input mask.
InputMaskPlaceholderstringnullLgTagBoxCharacter filling empty positions in the input mask (for example # with the mask 99-99-99-99-99 displays ##-##-##-##-##). Do not confuse with Placeholder. Without a value, the default mask character (_) is kept.
MaxCharsint?nullLgTagBoxMaximum length of a tag.
MaxTagsint?nullLgTagBoxMaximum number of tags. Once reached, the CSS class bootstrap-tagsinput-max is applied.
NoWrapboolfalseLgTagBoxFixes the field height; beyond that, a horizontal scroll bar appears.
OnChangingAsyncFunc<ChangingEventArgs<List<string>>, Task>nullLgTagBoxCallback called before value changes; the change can be canceled here.
PlaceholderstringnullLgTagBoxHint text displayed when the field is empty. Distinct from InputMaskPlaceholder.
TagCssClassstring"label label-info"LgTagBoxCSS classes applied to each tag.
AdditionalAttributesIReadOnlyDictionary<string, object>nullLgInputBaseAdditional HTML attributes applied to the rendered element.
AutoFocusboolfalseLgInputBaseGives focus to the field on first render.
ConfirmationMessagestringnullLgInputBaseConfirmation message displayed before applying a value change.
ContainerIInputContainer<List<string>>nullLgInputBaseInternal use: attaches a GridView cell to the field.
CssClassstringnullLgInputBaseAdditional CSS classes.
DisabledboolfalseLgInputBaseDisables the field.
DisplayNamestringnullLgInputBaseField name used in error messages.
HideValidationMessageboolfalseLgInputBaseHides the validation message under the field.
LabelstringnullLgInputBaseField label.
LabelContentRenderFragmentnullLgInputBaseCustom content for the label area.
OnChangeEventCallback<ChangeEventArgs>—LgInputBaseCallback called after the value changes.
OnResetEventCallback<ChangeEventArgs>—LgInputBaseCallback called when the field is reset by the clear button.
PolicyEditstringnullLgInputBasePolicy required to modify the field.
PolicyVisiblestringnullLgInputBasePolicy required to display the field.
ReadOnlyboolfalseLgInputBaseDisplays values as read-only.
Requiredbool?nullLgInputBaseRequired field. If null, inferred from the [Required] attribute of the bound property.
ResetButtonbool?nullLgInputBaseDisplays the clear button. If null, the application behavior configuration applies.
ResetTextstringnullLgInputBaseClear button text.
ResetTextAriaLabelstringnullLgInputBaseAccessible label (aria-label) of the clear button.
TooltipstringnullLgInputBaseTooltip.
TooltipIsHtmlboolfalseLgInputBaseIndicates if Tooltip content is in HTML format (otherwise plain text).
ValueList<string>nullLgInputBaseBound value (@bind-Value).
ValueChangedEventCallback<List<string>>—LgInputBaseCallback for updating the bound value.
ValueExpressionExpression<Func<List<string>>>—LgInputBaseExpression identifying the bound property.
AriaLabelstringnullLgAriaComponentBaseValue of the aria-label attribute.
AriaLabelledBystringnullLgAriaComponentBaseValue of the aria-labelledby attribute.
Cascading parameters

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

Events​

EventTypeDescription
OnChangingAsyncFunc<ChangingEventArgs<List<string>>, Task>Before the list changes; args.Cancel = true cancels the change.
OnChangeEventCallback<ChangeEventArgs>After the list changes.
OnResetEventCallback<ChangeEventArgs>On reset by the clear button.

Best practices / accessibility​

  • Initialize the bound property with an empty list rather than null to simplify processing code.
  • To suggest values during input rather than free input, prefer LgSuggestBox or LgSelect with multiple selection.
Complete reference

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