Select
Dropdown select input for picking from a list of options, styled to match the ShellUI design system.
Select renders a styled native <select> element by default. Set UseCustomSelect="true" to build a custom dropdown from SelectTrigger, SelectContent, and SelectItem; shellui add select installs them with Select.
Installation
bash
shellui add select
Usage
Basic
<div class="w-full max-w-sm">
<Select @bind-Value="_framework" UseCustomSelect="true">
<SelectTrigger>@(_framework ?? "Pick a framework...")</SelectTrigger>
<SelectContent>
<SelectItem Value="blazor">Blazor</SelectItem>
<SelectItem Value="next">Next.js</SelectItem>
<SelectItem Value="nuxt">Nuxt</SelectItem>
<SelectItem Value="sveltekit">SvelteKit</SelectItem>
</SelectContent>
</Select>
</div>
@code {
private string? _framework;
}
Bound to a model property
<div class="w-full max-w-sm">
<EditForm Model="_form">
<div class="space-y-4 w-60">
<Label For="role">Role</Label>
<Select @bind-Value="_form.Role" UseCustomSelect="true">
<SelectTrigger>@(_form.Role ?? "Select a role...")</SelectTrigger>
<SelectContent>
<SelectItem Value="admin">Admin</SelectItem>
<SelectItem Value="editor">Editor</SelectItem>
<SelectItem Value="viewer">Viewer</SelectItem>
</SelectContent>
</Select>
</div>
</EditForm>
</div>
@code {
private MyFormModel _form = new();
public class MyFormModel { public string? Role { get; set; } }
}
With grouped items
<div class="w-full max-w-sm">
<Select @bind-Value="_language" UseCustomSelect="true">
<SelectTrigger>@(_language ?? "Choose a language...")</SelectTrigger>
<SelectContent>
<p class="px-2 py-1 text-xs font-semibold text-muted-foreground">.NET</p>
<SelectItem Value="csharp">C#</SelectItem>
<SelectItem Value="fsharp">F#</SelectItem>
<p class="mt-1 px-2 py-1 text-xs font-semibold text-muted-foreground">JavaScript</p>
<SelectItem Value="ts">TypeScript</SelectItem>
<SelectItem Value="js">JavaScript</SelectItem>
</SelectContent>
</Select>
</div>
@code {
private string? _language;
}
Pre-selected value
<div class="w-full max-w-sm">
<Select @bind-Value="_theme">
<SelectTrigger />
<SelectContent>
<SelectItem Value="system">System</SelectItem>
<SelectItem Value="light">Light</SelectItem>
<SelectItem Value="dark">Dark</SelectItem>
</SelectContent>
</Select>
</div>
@code {
private string _theme = "system";
}
Read the selected value
Selected:
<div class="w-full max-w-sm">
<Select @bind-Value="_plan" UseCustomSelect="true" @bind-Value:after="OnPlanChanged">
<SelectTrigger>@(_plan ?? "Select plan...")</SelectTrigger>
<SelectContent>
<SelectItem Value="free">Free</SelectItem>
<SelectItem Value="pro">Pro</SelectItem>
<SelectItem Value="enterprise">Enterprise</SelectItem>
</SelectContent>
</Select>
<p class="text-sm text-muted-foreground">Selected: @_plan</p>
</div>
@code {
private string? _plan;
private void OnPlanChanged() => Console.WriteLine($"Plan changed to {_plan}");
}
Migration from v0.2.x
In v0.2.x Select was a single component with Items and @bind-SelectedValue. Replace it with the new compositional pattern:
razor
@* v0.2.x — OLD *@
<Select Items="_options" @bind-SelectedValue="_selected" Placeholder="Pick one..." />
@* v0.3.0 *@
<Select @bind-Value="_selected" UseCustomSelect="true">
<SelectTrigger>@(_selected ?? "Pick one...")</SelectTrigger>
<SelectContent>
@foreach (var opt in _options)
{
<SelectItem Value="@opt.Value">@opt.Label</SelectItem>
}
</SelectContent>
</Select>
API Reference
<Select>
| Parameter | Type | Default | Description |
|---|---|---|---|
Value |
string? |
null |
The currently selected value |
ValueChanged |
EventCallback<string?> |
— | Fires when the user selects an item |
Class |
string? |
null |
Additional CSS classes on the root element |
<SelectTrigger>
| Parameter | Type | Default | Description |
|---|---|---|---|
UseCustomSelect |
bool |
false |
Render SelectTrigger / SelectContent / SelectItem instead of a native <select> |
Class |
string? |
null |
Additional CSS classes |
<SelectContent>
| Parameter | Type | Default | Description |
|---|---|---|---|
ChildContent |
RenderFragment |
— | <SelectItem> elements |
Class |
string? |
null |
Additional CSS classes on the dropdown panel |
<SelectItem>
| Parameter | Type | Default | Description |
|---|---|---|---|
Value |
string |
— | The raw value submitted when this item is selected |
ChildContent |
RenderFragment |
— | Display label |
Class |
string? |
null |
Additional CSS classes |