Select
A select-only combobox with keyboard navigation and typeahead; it posts through a hidden input.
On this page
Examples
Select
Selected: none
<div class="flex w-full max-w-xs flex-col gap-3">
<KlyFormField Label="Country">
<KlySelect @bind-Value="_country" Items="Countries" Placeholder="Choose a country" data-testid="country" />
</KlyFormField>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="country-state">Selected: @(_country ?? "none")</p>
</div>
@code {
private string? _country;
private static readonly KlySelectItem[] Countries =
[
new("fr", "France"),
new("de", "Germany"),
new("it", "Italy"),
new("es", "Spain"),
new("ch", "Switzerland") { Disabled = true },
new("uk", "United Kingdom"),
];
}Counts, icons and groups
Count shows a number at the end of the row, Icon an icon before the label (a name, like every icon of Klyroo.UI) and Group lists the item under a heading. The headings are not options: the arrow keys and the typeahead skip them. Items without these properties render as before.
Selected: none
<div class="flex w-full max-w-xs flex-col gap-3">
<KlyFormField Label="Mailbox">
<KlySelect @bind-Value="_mailbox" Items="Mailboxes" Placeholder="Choose a mailbox" data-testid="mailbox" />
</KlyFormField>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="mailbox-state">Selected: @(_mailbox ?? "none")</p>
</div>
@code {
private string? _mailbox;
// Items with the same Group are listed under one heading, where the first of them is. The count is shown at the end of the row.
private static readonly KlySelectItem[] Mailboxes =
[
new("all", "All mail") { Icon = "mail", Count = 1204 },
new("inbox", "Inbox") { Icon = "inbox", Count = 12, Group = "Mailboxes" },
new("starred", "Starred") { Icon = "star", Count = 3, Group = "Mailboxes" },
new("sent", "Sent") { Icon = "bookmark", Group = "Mailboxes" },
new("archive", "Archive") { Icon = "folder", Count = 1840, Group = "Folders" },
new("projects", "Projects") { Icon = "folder-open", Count = 57, Group = "Folders" },
new("trash", "Trash") { Group = "Folders", Disabled = true },
];
}In a form
A form to move through with a remote control: Select edits a field, Back leaves it.
Selected: none
@* A small form to move through with a remote control (TV mode): Select/Enter edits a field, Back or Enter leaves it. *@
<div class="flex w-full max-w-xs flex-col gap-3" data-testid="tv-form">
<KlyFormField Label="Name"><KlyInput Value="Ada Lovelace" data-testid="tv-name" /></KlyFormField>
<KlyFormField Label="Country">
<KlySelect @bind-Value="_country" Items="Countries" Placeholder="Choose a country" data-testid="tv-country" />
</KlyFormField>
<KlyFormField Label="Bio"><KlyTextarea Rows="3" data-testid="tv-bio" /></KlyFormField>
<KlyButton Label="Save" data-testid="tv-save" />
<p class="text-sm text-(--klyroo-text-muted)" data-testid="tv-country-state">Selected: @(_country ?? "none")</p>
</div>
@code {
private string? _country;
private static readonly KlySelectItem[] Countries = [new("fr", "France"), new("de", "Germany"), new("it", "Italy")];
}Bound to an int foreign key
The value of an item has the type of the bound property: KlySelectItems.From builds the items of a lookup table (the key is the value, a column the label), and AsNullable() makes them fit an int? property.
CategoryId: 2, ParentId: null
<div class="flex w-full max-w-xs flex-col gap-3">
<KlyFormField Label="Category">
<KlySelect @bind-Value="_categoryId" Items="Categories" Placeholder="Choose a category" data-testid="category" />
</KlyFormField>
<KlyFormField Label="Parent category (optional)">
<KlySelect @bind-Value="_parentId" Items="OptionalCategories" Placeholder="None" data-testid="parent-category" />
</KlyFormField>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="category-state">CategoryId: @_categoryId, ParentId: @(_parentId?.ToString() ?? "null")</p>
</div>
@code {
private sealed record Category(int Id, string Name);
private static readonly Category[] Rows = [new(1, "Books"), new(2, "Games"), new(3, "Music"), new(4, "Toys")];
// The foreign key of a model: the item value is the key (an int), the label a column. The bound property is the int itself.
private int _categoryId = 2;
// A nullable foreign key: AsNullable() makes the items KlySelectItem<int?>, and clearing the field sets null.
private int? _parentId;
private static readonly IReadOnlyList<KlySelectItem<int>> Categories = KlySelectItems.From(Rows, c => c.Id, c => c.Name);
private static readonly IReadOnlyList<KlySelectItem<int?>> OptionalCategories = Categories.AsNullable();
}Bound to an enum
KlySelectItems.FromEnum lists the members of the enum in order, labeled by their name split into words or by a function you give it.
Status: InProgress, Priority: Normal
<div class="flex w-full max-w-xs flex-col gap-3">
<KlyFormField Label="Status">
<KlySelect @bind-Value="_status" Items="Statuses" data-testid="status" />
</KlyFormField>
<KlyFormField Label="Priority (custom labels)">
<KlySelect @bind-Value="_priority" Items="Priorities" data-testid="priority" />
</KlyFormField>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="status-state">Status: @_status, Priority: @_priority</p>
</div>
@code {
private enum OrderStatus { Draft, InProgress, ReadyToShip, Done }
private enum Priority { Low, Normal, High }
private OrderStatus _status = OrderStatus.InProgress;
private Priority _priority = Priority.Normal;
// One item per member, in the order of the enum. The default label splits the name into words: InProgress is "In progress".
private static readonly IReadOnlyList<KlySelectItem<OrderStatus>> Statuses = KlySelectItems.FromEnum<OrderStatus>();
private static readonly IReadOnlyList<KlySelectItem<Priority>> Priorities = KlySelectItems.FromEnum<Priority>(p => p switch
{
Priority.Low => "Whenever",
Priority.Normal => "This week",
_ => "Today",
});
}Bound to a Guid
Any value that has an invariant text works: it travels as that text and the control gives back the exact value of the option.
Selected: none
<div class="flex w-full max-w-xs flex-col gap-3">
<KlyFormField Label="Assignee">
<KlySelect @bind-Value="_assignee" Items="People" Placeholder="Choose a person" data-testid="assignee" />
</KlyFormField>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="assignee-state">Selected: @(_assignee == Guid.Empty ? "none" : _assignee.ToString())</p>
</div>
@code {
private sealed record Person(Guid Id, string Name);
private static readonly Person[] Team =
[
new(Guid.Parse("6f0d1c2e-7a41-4c6f-9a0e-1b2c3d4e5f60"), "Alma Ahlberg"),
new(Guid.Parse("a8b3e9d4-2f15-4e7b-8c91-0d6e7f8a9b10"), "Bastian Bianchi"),
new(Guid.Parse("c4d5e6f7-8a9b-4c0d-91e2-f3a4b5c6d7e8"), "Clara Carvalho"),
];
// A Guid key: the value of the property is the Guid, and Guid.Empty (the default) shows the placeholder.
private Guid _assignee;
private static readonly IReadOnlyList<KlySelectItem<Guid>> People = KlySelectItems.From(Team, p => p.Id, p => p.Name);
}Bound to a DateTime
A DateTime travels as ISO 8601, so the option with that exact instant is the selected one.
Selected: none
<div class="flex w-full max-w-xs flex-col gap-3">
<KlyFormField Label="Delivery slot">
<KlySelect @bind-Value="_slot" Items="Slots" Placeholder="Pick a slot" data-testid="slot" />
</KlyFormField>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="slot-state">Selected: @(_slot?.ToString("yyyy-MM-dd HH:mm") ?? "none")</p>
</div>
@code {
private static readonly DateTime Day = new(2026, 12, 1);
// The value of an item can be a DateTime: it travels as an invariant ISO 8601 text, so the exact value comes back.
private DateTime? _slot;
private static readonly IReadOnlyList<KlySelectItem<DateTime?>> Slots =
KlySelectItems.From([8, 10, 14, 16], hour => (DateTime?)Day.AddHours(hour), hour => $"{hour}:00 to {hour + 2}:00");
}API
KlySelect<TValue>
Select that opens a list of items in a popup, bound to a string, a number, an enum, a Guid , a date or any value that identifies an option, with optional icons and sections.
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. |
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 (required) |
IReadOnlyList |
The options, as KlySelectItem`1 ( KlySelectItem for strings). Items with a group are shown in sections. | |
Name |
string |
Form field name outside an EditForm . Inside one, the name comes from the bound expression. | |
Placeholder |
string |
Hint shown while the field is empty. | |
Required |
bool |
false |
Marks the control as required, for the browser and for assistive technology. |
Size |
KlySize? |
Defaults to the size of the enclosing KlyFormField , or medium. Values: Xs, Sm, Md, Lg, Xl. |
|
Ui |
SelectUi |
Per-instance class overrides of the slots of the select, see SelectUi . 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 |
The expression of the bound field. The compiler sets it with @bind-Value , and validation uses it to find the field. | |
Variant |
FieldVariant |
FieldVariant. |
Look of the field: Outline , Soft , Subtle , Ghost or None . Values: Outline, Soft, Subtle, Ghost, None. |
Ui slots
Ui takes a SelectUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlySelect`1 , after the theme and the app configuration. |
Base |
Classes merged into the base slot of KlySelect`1 , after the theme and the app configuration. |
Label |
Classes merged into the label slot of KlySelect`1 , after the theme and the app configuration. |
TrailingIcon |
Classes merged into the trailingIcon slot of KlySelect`1 , after the theme and the app configuration. |
Content |
Classes merged into the content slot of KlySelect`1 , after the theme and the app configuration. |
Listbox |
Classes merged into the listbox slot of KlySelect`1 , after the theme and the app configuration. |
Item |
Classes merged into the item slot of KlySelect`1 , after the theme and the app configuration. |
ItemLabel |
Classes merged into the itemLabel slot of KlySelect`1 , after the theme and the app configuration. |
ItemIcon |
Classes merged into the itemIcon slot of KlySelect`1 , after the theme and the app configuration. |
ItemLeadingIcon |
Classes merged into the itemLeadingIcon slot of KlySelect`1 , after the theme and the app configuration. |
ItemCount |
Classes merged into the itemCount slot of KlySelect`1 , after the theme and the app configuration. |
Group |
Classes merged into the group slot of KlySelect`1 , after the theme and the app configuration. |
GroupLabel |
Classes merged into the groupLabel slot of KlySelect`1 , after the theme and the app configuration. |
LeadingIcon |
Classes merged into the leadingIcon slot of KlySelect`1 , after the theme and the app configuration. |