No results
3
Select
Byron edited this page 2026-10-02 23:20:50 +02:00
Table of contents
Important
The
<Select />component uses the customizable select selectors that might not be introduced in every browser yet. Said browsers will render a normal select dropdown, however the trigger element will look identical to browsers that do support these new selectors.
Forms with SSR
This component support model-binding, even when using <EditForm> in the static rendering mode. These examples use simple binding with a local variable for simplicity purposes.
Basic
<CleanSelect @bind-Value="@(value)"
Options="@(Basic.options)"
GetOptionValue="@(static (option) => option.Value)"
GetOptionLabel="@(static (option) => option.Label)"
GetOptionIcon="@(Basic.GetOptionIcon)"
AddNullOption
NullOptionLabel="Pick a fruit!">
</CleanSelect>
@code {
private string? value;
private static readonly SelectOption[] options =
[
new("apple", "Apple"),
new("banana", "Banana"),
new("cherry", "Cherry"),
new("mango", "Mango"),
];
private static RenderFragment? GetOptionIcon(SelectOption option) =>
(option.Value) switch
{
"apple" => Icons.Apple,
"cherry" => Icons.Cherry,
_ => null,
};
private readonly record struct SelectOption(string Value, string Label);
}
Multiple
Important
For a more advanced multi-select see the Combobox example.
Passing an array type for the Value parameter will add the multiple attribute to the rendered select.
<CleanSelect @bind-Value="@(value)"
Options="@(Multiple.options)"
GetOptionValue="@(static (option) => option.Value)"
GetOptionLabel="@(static (option) => option.Label)"
GetOptionIcon="@(Multiple.GetOptionIcon)"
AddNullOption
NullOptionLabel="Pick a fruit!">
</CleanSelect>
@code {
private string[] value = [];
private static readonly SelectOption[] options =
[
new("apple", "Apple"),
new("banana", "Banana"),
new("cherry", "Cherry"),
new("mango", "Mango"),
];
private static RenderFragment? GetOptionIcon(SelectOption option) =>
(option.Value) switch
{
"apple" => Icons.Apple,
"cherry" => Icons.Cherry,
_ => null,
};
private readonly record struct SelectOption(string Value, string Label);
}