Skip to content
Form InputMenu

InputMenu

A text field with a list of suggestions: free text, or restricted to the suggestions.

On this page

Examples

Free text and strict

France
Germany
Italy
Spain
Portugal
France
Germany
Italy
Spain
Portugal

Free: none, strict: none

Razor
<div class="flex w-full max-w-xs flex-col gap-4">
    <KlyFormField Label="Search a country (free text)">
        <KlyInputMenu Items="Countries" @bind-Value="_free" Placeholder="Type a country" />
    </KlyFormField>
    <KlyFormField Label="Country (a suggestion is required)">
        <KlyInputMenu Items="Countries" Strict @bind-Value="_strict" Placeholder="Pick a country" />
    </KlyFormField>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="menu-state">Free: @(_free ?? "none"), strict: @(_strict ?? "none")</p>
</div>

@code {
    private string? _free;
    private string? _strict;

    private static readonly KlySelectItem[] Countries =
        [new("fr", "France"), new("de", "Germany"), new("it", "Italy"), new("es", "Spain"), new("pt", "Portugal")];
}

Groups, icons and counts

The same Count, Icon and Group of the items as the other menus; a heading disappears with its last suggestion while you type.

Ada Lovelace, 4
Alan Turing, 0
Grace Hopper, 11
Core team, 18
Docs team, 5

Assigned: nobody

Razor
<div class="flex w-full max-w-xs flex-col gap-3">
    <KlyFormField Label="Assign to">
        <KlyInputMenu Items="People" Strict @bind-Value="_person" Placeholder="Pick a person or a team" />
    </KlyFormField>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="assign-state">Assigned: @(_person ?? "nobody")</p>
</div>

@code {
    private string? _person;

    private static readonly KlySelectItem[] People =
    [
        new("ada", "Ada Lovelace") { Group = "People", Icon = "bell", Count = 4 },
        new("alan", "Alan Turing") { Group = "People", Icon = "bell", Count = 0 },
        new("grace", "Grace Hopper") { Group = "People", Icon = "bell", Count = 11 },
        new("core", "Core team") { Group = "Teams", Icon = "heart", Count = 18 },
        new("docs", "Docs team") { Group = "Teams", Icon = "heart", Count = 5 },
    ];
}

Remote suggestions

OptionsProvider loads the suggestions from a source (simulated here, 400 ms per call) as you type, after Debounce; the next page loads as the list scrolls. The strict field restores its value from a cursor-paged source and ResolveSelected names it. Interactive only: a statically rendered page shows a free text field without suggestions, and a strict field read only.

Free: none, strict: fr

Free field calls: 0

Last call: none

Strict field calls: 0

Last call: none

Razor
<div class="flex w-full max-w-xs flex-col gap-4">
    <KlyFormField Label="City or country (free text)">
        <KlyInputMenu OptionsProvider="_free.ByPage" PageSize="20" Placeholder="Type to search" @bind-Value="_text" data-testid="remote-free" />
    </KlyFormField>
    <KlyFormField Label="Country from the source (suggestion required)">
        <KlyInputMenu TValue="string" OptionsProvider="_strict.ByCursor" ResolveSelected="_strict.Resolve" Strict PageSize="20" Debounce="150" Placeholder="Pick a country"
                     Value="@_country" ValueChanged="@(v => _country = v)" data-testid="remote-strict" />
    </KlyFormField>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="remote-input-state">Free: @(_text ?? "none"), strict: @(_country ?? "none")</p>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="remote-free-requests">Free field calls: @_free.Requests</p>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="remote-free-last">Last call: @_free.Last</p>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="remote-strict-requests">Strict field calls: @_strict.Requests</p>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="remote-strict-last">Last call: @_strict.Last</p>
</div>

@code {
    private RemoteDirectory _free = default!;
    private RemoteDirectory _strict = default!;
    private string? _text;

    // A value restored from the address or a saved form: its page was never loaded, so ResolveSelected names it.
    private string? _country = "fr";

    protected override void OnInitialized()
    {
        _free = new RemoteDirectory { Changed = () => _ = InvokeAsync(StateHasChanged) };
        _strict = new RemoteDirectory { Changed = () => _ = InvokeAsync(StateHasChanged) };
    }
}

Short text and error states

MinLength keeps a text shorter than two letters from being searched. When the provider throws, the list shows a translated error with a Retry button (Enter in the field also retries). Turn the switch on, type, turn it off and retry.

Text: none

Source calls: 0

Razor
<div class="flex w-full max-w-xs flex-col gap-3">
    <KlySwitch @bind-Value="_failing" Label="The source is down" data-testid="remote-input-fail" />
    <KlyFormField Label="Look up a country">
        <KlyInputMenu OptionsProvider="_source.ByPage" PageSize="20" MinLength="2" Placeholder="Type two letters" @bind-Value="_text" data-testid="remote-input-error" />
    </KlyFormField>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="remote-input-error-state">Text: @(_text ?? "none")</p>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="remote-input-error-requests">Source calls: @_source.Requests</p>
</div>

@code {
    private RemoteDirectory _source = default!;
    private string? _text;

    // The switch flips what the simulated source does: with it on, every call throws and the list shows its error and Retry button.
    private bool _failing
    {
        get => _source.Fail;
        set => _source.Fail = value;
    }

    protected override void OnInitialized() => _source = new RemoteDirectory { Changed = () => _ = InvokeAsync(StateHasChanged), LatencyMs = 200 };
}

Named strict value

Items name a value without listing it: a strict field shows France, not fr, in every render mode, with no call to the source. OptionsKey works as on SelectMenu: when it changes, what was loaded is forgotten.

Selected: fr

Razor
<div class="flex w-full max-w-xs flex-col gap-3">
    <KlyFormField Label="Home country, named">
        <KlyInputMenu TValue="string" OptionsProvider="_source.ByPage" Items="Known" Strict PageSize="20" Value="@_country" ValueChanged="@(v => _country = v)" data-testid="remote-named-strict" />
    </KlyFormField>
    <p class="text-sm text-(--klyroo-text-muted)" data-testid="remote-named-strict-state">Selected: @(_country ?? "none")</p>
</div>

@code {
    private readonly RemoteDirectory _source = new();
    private string? _country = "fr";

    // Items name a value without listing it: France shows as France in every render mode, without a call to the source.
    private static readonly KlySelectItem[] Known = [new("fr", "France")];
}

API

KlyInputMenu<TValue>

Text input with a list of suggestions that filters as the user types, bound to the typed text (a string) or, with Strict or any other type, to the chosen option's value (a number, an enum, a Guid ...). The options can be static or fetched from .NET.

Parameters

Name Type Default Description
Class string Classes added to the root element, merged last so they win over the theme.
Color KlyColor "primary" Semantic color of the control: a built-in KlyColor or the name of a color you defined. When not set, Color applies, else primary. Values: primary, secondary, success, info, warning, error, neutral.
Debounce int 250 With OptionsProvider : the quiet time in milliseconds after typing before the source is searched.
Disabled bool false Disables the control: it cannot be focused or changed and is not submitted.
Id string The id of the native control. Defaults to the one of the enclosing KlyFormField , else a generated one.
Items IReadOnlyList<IKlySelectItem<TValue>> The suggestions, filtered by what is typed. Not needed when OptionsProvider loads them; given together with it, these items are not listed but their labels are known (the label of a Strict value the provider has not returned yet). The parameter must be passed when there is no provider, and a null value ( Items="@_list" while the list is still loading) is an empty list, before and after it loads.
MinLength int 0 With OptionsProvider : the shortest text that is searched. A shorter, non-empty text shows a hint and lists nothing.
Name string Form field name outside an EditForm . Inside one, the name comes from the bound expression.
OptionsKey string With OptionsProvider : what the suggestions depend on besides the typed text (the country whose cities are suggested). When it changes (compared ordinally), the loaded pages, the search text, the cursor and the resolved label are forgotten, a Strict value is resolved again, and the list loads again the next time it opens. A new delegate with the same key keeps what was loaded. Without a key the source is assumed not to change.
OptionsProvider KlyOptionsProvider Loads the suggestions from a remote source, one page at a time, instead of listing Items . The browser stops filtering and the field searches the source with what is typed: the text is trimmed, sent after Debounce milliseconds of quiet and only when it has at least MinLength characters (an empty text lists the unfiltered suggestions; a Strict field searches the empty text when it opens, as it always lists everything); an older request is cancelled and an older answer never replaces a newer one. The next page loads as the list scrolls, a bit before its end, and by a "Load more" button. While loading the list is aria-busy and a polite status says so; when the provider throws, the list shows a translated error with a Retry button (Enter in the field also retries). Interactive only: a statically rendered page (and the prerender before the page becomes interactive) never calls the provider. A free text field then works as a plain text field with no suggestions; a field shows its value as it was given (read only, since no suggestion can be chosen) and still posts it. A parent that renders again with an equal or a new delegate keeps the loaded state; give the component a @key to start from scratch.
PageSize int 25 With OptionsProvider : the number of suggestions requested per page.
Placeholder string Hint shown while the field is empty.
Required bool false Marks the control as required, for the browser and for assistive technology.
ResolveSelected KlySelectedOptionsResolver With OptionsProvider and Strict : returns the option of the value when the loaded pages do not contain it (a value restored from the address or a saved form), so the field shows its label. Called once for that value, as soon as the component is interactive. Without it the field shows the raw value.
Size KlySize? Defaults to the size of the enclosing KlyFormField , or medium. Values: Xs, Sm, Md, Lg, Xl.
Strict bool false Only a suggestion is a valid value: Value is the chosen item's value and the field shows its label. Otherwise (the default) the typed text is the value and suggestions only complete it. Only a string can be typed: when is not String the field is always strict, whatever this parameter says.
Ui InputMenuUi Per-instance class overrides of the slots of the input menu, see InputMenuUi . They are merged after the theme and the Class parameter wins on the root slot.
Value (@bind-Value) TValue The value of the control. Bind it with @bind-Value .
ValueExpression Expression<Func<TValue>> The expression of the bound field. The compiler sets it with @bind-Value , and validation uses it to find the field.
Variant FieldVariant FieldVariant.Outline Look of the field: Outline , Soft , Subtle , Ghost or None . Values: Outline, Soft, Subtle, Ghost, None.

Ui slots

Ui takes a InputMenuUi with one class string per slot, merged after the theme.

Slot Styles
Root Classes merged into the root slot of KlyInputMenu`1 , after the theme and the app configuration.
Base Classes merged into the base slot of KlyInputMenu`1 , after the theme and the app configuration.
Trailing Classes merged into the trailing slot of KlyInputMenu`1 , after the theme and the app configuration.
TrailingIcon Classes merged into the trailingIcon slot of KlyInputMenu`1 , after the theme and the app configuration.
Content Classes merged into the content slot of KlyInputMenu`1 , after the theme and the app configuration.
Listbox Classes merged into the listbox slot of KlyInputMenu`1 , after the theme and the app configuration.
Item Classes merged into the item slot of KlyInputMenu`1 , after the theme and the app configuration.
ItemLabel Classes merged into the itemLabel slot of KlyInputMenu`1 , after the theme and the app configuration.
ItemIcon Classes merged into the itemIcon slot of KlyInputMenu`1 , after the theme and the app configuration.
ItemLeadingIcon Classes merged into the itemLeadingIcon slot of KlyInputMenu`1 , after the theme and the app configuration.
ItemCount Classes merged into the itemCount slot of KlyInputMenu`1 , after the theme and the app configuration.
Group Classes merged into the group slot of KlyInputMenu`1 , after the theme and the app configuration.
GroupLabel Classes merged into the groupLabel slot of KlyInputMenu`1 , after the theme and the app configuration.
Empty Classes merged into the empty slot of KlyInputMenu`1 , after the theme and the app configuration.
Scroller Classes merged into the scroller slot of KlyInputMenu`1 , after the theme and the app configuration.
Loading Classes merged into the loading slot of KlyInputMenu`1 , after the theme and the app configuration.
Spinner Classes merged into the spinner slot of KlyInputMenu`1 , after the theme and the app configuration.
Error Classes merged into the error slot of KlyInputMenu`1 , after the theme and the app configuration.
Announcer Classes merged into the announcer slot of KlyInputMenu`1 , after the theme and the app configuration.