Select
InputInteractive dropdown for choosing a value with keyboard navigation.
@using Spectre.Console
@using RazorConsole.Components
<Select TItem="string" Options="@options" Value="@selectedValue" FocusedValue="@focusedValue"
FocusedValueChanged="@((v) => focusedValue = v)" ValueChanged="@((v) => selectedValue = v)"
Placeholder="Choose an option" />
@* add helper text *@
<Rows>
<Markup Content="@($"Selected: {selectedValue ?? "None"}")" Foreground="Color.Yellow" />
<Markup Content="@($"Focused: {focusedValue ?? "None"}")" Foreground="Color.Cyan" />
<Newline />
<Markup Content="Use arrow keys to navigate and Enter to select." Foreground="Color.Green" />
</Rows>
@code {
private string[] options = new[] { "Option 1", "Option 2", "Option 3" };
private string? selectedValue;
private string? focusedValue;
}Parameters
17| Name | Type | Default | Description |
|---|---|---|---|
Behavior | |||
FocusedValue | <TItem> | — | Currently highlighted option during keyboard navigation (may differ from committed Value). |
IsFocused | Boolean | — | Indicates whether the select currently has focus. |
SelectedIndicator | Char | — | Character used to indicate the focused option. |
SelectedOptionDecoration | Decoration | — | Text decoration for the focused option. |
UnselectedIndicator | Char | — | Character used to indicate non-focused options. |
Appearance | |||
OptionForeground | Color | — | Foreground color for non-focused options. |
SelectedOptionForeground | Color | — | Foreground color for the focused option. |
Events | |||
FocusedValueChanged | EventCallback<TItem> | — | Event raised when the focused option changes. |
IsFocusedChanged | EventCallback<Boolean> | — | Event raised when the focus state changes. |
ValueChanged | EventCallback<TItem> | — | Event raised when the committed value changes. |
Common | |||
Value | <TItem> | — | Currently committed option value. |
Other | |||
AdditionalAttributes | IReadOnlyDictionary<String, Object> | — | Additional attributes to apply to the root element. |
Comparer | IEqualityComparer<TItem> | — | Custom comparer for items in the list. Default is object.Equals() |
Expand | Boolean | — | Expands the rows layout to fill available space when true. |
Formatter | System.Func<{TItem>,System.String} | — | Custom formatter for the items in the list. Default is object.ToString() |
OptionDecoration | Decoration | — | Text decoration for non-focused options. |
Options | <TItem>[] | — | Available options rendered by the select. |