Skip to main content

LgSuggestBox

LgSuggestBox is a text field that offers suggestions during input: matching values are displayed in a dropdown menu and the retained value remains free-form input (selecting a suggestion is optional). Suggestions come from a local list (Items) or a remote controller (ControllerUri).

<LgSuggestBox Label="#City" Items="_cities" @bind-Value="_model.City" />
  • Namespace : Lagoon.UI.Components
  • Inherits from : LgSuggestBoxBase<string> → LgTextBox → LgInputRenderBase<string> → LgInputBase<string> → LgAriaComponentBase → LgComponentBase
  • Interfaces : ILgDropDownComponent
  • NuGet Package : Lagoon.UI
Suggestion or selection?

LgSuggestBox accepts a free value; suggestions are only an input aid. To constrain the value to a closed list, use LgSelect.

Usage​

Demo​

Try this component in the Lagoon showcase.

Local suggestions​

Items provides the list of proposed values. The entered text filters the list (default Contains mode) and the menu only opens if there are results.

CityPage.razor
<LgSuggestBox Label="#City"
Items="_cities"
Placeholder="#TypeCityName"
@bind-Value="_model.City" />
CityPage.razor.cs
public partial class CityPage : LgPage
{
// Suggested values: input remains free, the list is only an aid.
private readonly List<string> _cities = new() { "Paris", "Lyon", "Marseille", "Toulouse", "Nantes" };

private readonly CityVm _model = new();

private sealed class CityVm
{
public string City { get; set; }
}
}

Remote suggestions with ControllerUri​

For a large or server-dependent list, ControllerUri points to a queryable action: the component automatically posts a data request to {ControllerUri}/$qd with the entered text, filter, and pagination.

SupplierPage.razor
<LgSuggestBox Label="#Supplier"
ControllerUri="api/suppliers/names"
MinSearchCharacter="2"
SeeAllEnabled="true"
@bind-Value="_model.Supplier" />
SupplierPage.razor.cs
public partial class SupplierPage : LgPage
{
private readonly SupplierVm _model = new();

private sealed class SupplierVm
{
public string Supplier { get; set; }
}
}

Endpoint contract​

ControllerUri points to a queryable action. The component calls {ControllerUri}/$qd in POST via the Lagoon remote loader; the source action remains exposed in GET and decorated with [Queryable].

GET + POST $qd — Suggestion search (ControllerUri)​

SuppliersController.cs
[ApiController]
[Route("api/suppliers")]
public class SuppliersController : LgControllerBase
{
private readonly ApplicationDbContext _db;

public SuppliersController(ApplicationDbContext db)
{
_db = db;
}

[HttpGet("names")]
[Queryable]
public IQueryable<string> GetNames()
{
// Returns IQueryable<string> to allow [Queryable] to apply the search text,
// pagination, and sorting sent by the component.
return _db.Suppliers.Select(s => s.Name);
}
}

Filtering, collation, and result count​

FilterTextSearchMode, TextFilterCollation, MinSearchCharacter and MaxItemsInView adjust search behavior. HighlightText highlights found text in results and SeeAllEnabled adds a "See all" button when more results are available than MaxItemsInView.

ProductPage.razor
<LgSuggestBox Label="#Product"
Items="_products"
FilterTextSearchMode="FilterTextSearchMode.StartsWith"
TextFilterCollation="CollationType.IgnoreCaseAndAccent"
MinSearchCharacter="1"
MaxItemsInView="10"
HighlightText="true"
@bind-Value="_model.Product" />
ProductPage.razor.cs
public partial class ProductPage : LgPage
{
private readonly List<string> _products = new() { "Écrou M6", "Écrou M8", "Vis M6", "Vis M8", "Rondelle M6" };

private readonly ProductVm _model = new();

private sealed class ProductVm
{
public string Product { get; set; }
}
}

Customize suggestion rendering​

ItemContent replaces the default rendering of a suggestion. With HighlightText, add the highlightable class to the element containing the text to highlight.

AccountPage.razor
<LgSuggestBox Label="#Account" Items="_accounts" HighlightText="true" @bind-Value="_model.Account">
<ItemContent Context="item">
<LgIcon IconName="@IconNames.All.PersonFill" />
<span class="highlightable">@item</span>
</ItemContent>
</LgSuggestBox>
AccountPage.razor.cs
public partial class AccountPage : LgPage
{
private readonly List<string> _accounts = new() { "compta-fournisseurs", "compta-clients", "banque" };

private readonly AccountVm _model = new();

private sealed class AccountVm
{
public string Account { get; set; }
}
}

Properties​

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

NameTypeDefaultDeclared inDescription
ControllerUristringnullLgSuggestBoxBase<TItem>URI of the controller used to load suggestions remotely.
DropDownMaxHeightint-1LgSuggestBoxBase<TItem>Maximum height of the dropdown menu, in pixels. -1 uses available space.
FilterTextSearchModeFilterTextSearchModeContainsLgSuggestBoxBase<TItem>Comparison mode used to filter the search text.
HighlightTextboolfalseLgSuggestBoxBase<TItem>Highlights found text in the displayed suggestions.
ItemContentRenderFragment<string>nullLgSuggestBoxBase<TItem>Custom template to render a suggestion.
ItemsIEnumerable<string>nullLgSuggestBoxBase<TItem>Local source of suggestions.
MaxItemsInViewint8LgSuggestBoxBase<TItem>Maximum number of suggestions displayed. 0 displays all results.
MinSearchCharacterint0LgSuggestBoxBase<TItem>Minimum number of characters before starting the search.
SeeAllEnabledboolfalseLgSuggestBoxBase<TItem>Displays a "See all" button when more results are available than MaxItemsInView.
TextFilterCollationCollationType?nullLgSuggestBoxBase<TItem>Case and accent sensitivity. If null, the application behavior configuration applies.
AllowResizeboolfalseLgTextBoxAllows resizing when TextMode is TextBoxMode.Multiline.
AutoCompleteboolfalseLgTextBoxEnables browser autocomplete if true; otherwise the autocomplete="off" attribute is rendered.
AutoUnmaskboolfalseLgTextBoxReturns the value without the mask when InputMask is used.
ClearIncompleteboolfalseLgTextBoxClears the value if the input mask is incomplete.
DataListList<string>nullLgTextBoxList of values used to render a datalist associated with the input.
InputMaskstringnullLgTextBoxInput mask applied to the text field.
InputMaskKindInputMaskKindNoneLgTextBoxType of input mask.
InputMaskPlaceholderstringnullLgTextBoxCharacter filling the empty positions of the input mask (for example # with the mask 99-99-99-99-99 displays ##-##-##-##-##). Not to be confused with Placeholder. Without a value, the mask's default character (_) is retained.
MaxLengthint?nullLgTextBoxMaximum number of characters.
MaxRowsint?nullLgTextBoxMaximum number of rows when TextMode is TextBoxMode.Multiline.
MinRowsint?nullLgTextBoxMinimum number of rows when TextMode is TextBoxMode.Multiline.
OnChangeDisabledboolfalseLgTextBoxDisables the native onchange handler of the field.
OnChangingAsyncFunc<ChangingEventArgs<string>, Task>nullLgTextBoxCallback called before value change; the change can be cancelled here.
OnFocusEventCallback<FocusEventArgs>—LgTextBoxCallback called on focus (also triggers initial search).
OnInputEventCallback<ChangeEventArgs>—LgTextBoxCallback called on input (oninput), used by the search.
OnKeyUpEventCallback<KeyboardEventArgs>—LgTextBoxCallback called on key release.
PlaceholderstringnullLgTextBoxPlaceholder text displayed when the field is empty. Distinct from InputMaskPlaceholder.
Rowsint?nullLgTextBoxNumber of rows when TextMode is TextBoxMode.Multiline.
TextModeTextBoxMode?nullLgTextBoxText field mode. null renders a simple text field.
PrefixstringnullLgInputRenderBasePrefix displayed in the field.
PrefixTypeInputLabelTypeTextLgInputRenderBaseNature of the prefix.
SuffixstringnullLgInputRenderBaseSuffix displayed in the field.
SuffixTypeInputLabelTypeTextLgInputRenderBaseNature of the suffix.
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<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 below the field.
LabelstringnullLgInputBaseField label.
LabelContentRenderFragmentnullLgInputBaseCustom content of the label area.
OnChangeEventCallback<ChangeEventArgs>—LgInputBaseCallback called after value change.
OnResetEventCallback<ChangeEventArgs>—LgInputBaseCallback called when the field is reset by the clear button.
PolicyEditstringnullLgInputBasePolicy required to edit the field.
PolicyVisiblestringnullLgInputBasePolicy required to display the field.
ReadOnlyboolfalseLgInputBaseDisplays the field 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 the Tooltip content is in HTML format (otherwise plain text).
ValuestringnullLgInputBaseBound value (@bind-Value).
ValueChangedEventCallback<string>—LgInputBaseUpdate callback for the bound value.
ValueExpressionExpression<Func<string>>—LgInputBaseExpression identifying the bound property.
AriaLabelstringnullLgAriaComponentBaseValue of the aria-label attribute.
AriaLabelledBystringnullLgAriaComponentBaseValue of the aria-labelledby attribute.
Cascading parameters

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

Events​

EventTypeDescription
OnChangingAsyncFunc<ChangingEventArgs<string>, Task>Before value change; set args.Cancel = true to cancel the change.
OnChangeEventCallback<ChangeEventArgs>After value change (input validated or suggestion selected).
OnInputEventCallback<ChangeEventArgs>On input; this is also the event that triggers the search.
OnKeyUpEventCallback<KeyboardEventArgs>On key release.
OnFocusEventCallback<FocusEventArgs>On focus (triggers initial search).
OnResetEventCallback<ChangeEventArgs>On reset by the clear button.

Associated enumerations​

The enumerations of the suggest family (FilterTextSearchMode, CollationType, InputMaskKind, TextBoxMode) are documented on the LgNavigationBox page, which shares the same base LgSuggestBoxBase.

Best practices / accessibility​

  • Set MinSearchCharacter to 2 or 3 with ControllerUri to limit server requests on first characters.
  • The bound value remains free-form input: validate it on the model side if only suggested values are acceptable — or use LgSelect for a closed list.
Complete reference

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