Class MudSelect<T>
- Namespace
- MudBlazor
- Assembly
- MudBlazor.dll
A component for choosing an item from a list of options.
public class MudSelect<T> : MudBaseInput<T>, IComponent, IHandleEvent, IHandleAfterRender, IMudStateHasChanged, IFormComponent, IAsyncDisposable
Type Parameters
T
The kind of object being selected.
- Inheritance
-
MudBaseInput<T>MudSelect<T>
- Implements
- Inherited Members
- Extension Methods
Constructors
MudSelect()
public MudSelect()
Fields
_items
protected List<MudSelectItem<T>> _items
Field Value
- List<MudSelectItem<T>>
_shadowLookup
protected Dictionary<NullableObject<T?>, MudSelectItem<T>> _shadowLookup
Field Value
- Dictionary<NullableObject<T>, MudSelectItem<T>>
_valueLookup
protected Dictionary<NullableObject<T?>, MudSelectItem<T>> _valueLookup
Field Value
- Dictionary<NullableObject<T>, MudSelectItem<T>>
Properties
AnchorOrigin
The location where the popover will open from.
[Parameter]
[Category("List appearance")]
public Origin AnchorOrigin { get; set; }
Property Value
Remarks
Defaults to BottomLeft.
CanRenderValue
Whether the Value
can be found in the list of Items.
protected bool CanRenderValue { get; }
Property Value
Remarks
When false
, the Value
will be displayed as a string.
CheckedIcon
The icon used for selected items.
[Parameter]
[Category("List appearance")]
public string CheckedIcon { get; set; }
Property Value
Remarks
Defaults to CheckBox. Only applies when MultiSelection is true
.
ChildContent
The content within this component, typically a list of MudSelectItem<T> components.
[Parameter]
[Category("List behavior")]
public RenderFragment? ChildContent { get; set; }
Property Value
Classname
protected string Classname { get; }
Property Value
ClearIcon
The icon displayed for the clear button when Clearable is true
.
[Parameter]
[Category("Appearance")]
public string ClearIcon { get; set; }
Property Value
Remarks
Defaults to Clear.
Clearable
Shows a button for clearing any selected values.
[Parameter]
[Category("Behavior")]
public bool Clearable { get; set; }
Property Value
Remarks
Defaults to false
. When true
, the ClearIcon can be used to control the icon, and OnClearButtonClick occurs when the clear button is clicked.
CloseIcon
The icon for closing the popover of items.
[Parameter]
[Category("Appearance")]
public string CloseIcon { get; set; }
Property Value
Remarks
Defaults to ArrowDropUp.
Comparer
The comparer for testing equality of selected values.
[Parameter]
[Category("Behavior")]
public IEqualityComparer<T?>? Comparer { get; set; }
Property Value
Delimiter
The string used to separate multiple selected values.
[Parameter]
[Category("Behavior")]
public string Delimiter { get; set; }
Property Value
Remarks
Defaults to ", "
. Only applies when MultiSelection is true
.
Dense
Uses compact vertical padding for all items.
[Parameter]
[Category("List appearance")]
public bool Dense { get; set; }
Property Value
Remarks
Defaults to false
.
DropdownSettings
The behavior of the dropdown popover menu
[Category("Behavior")]
[Parameter]
public DropdownSettings DropdownSettings { get; set; }
Property Value
Remarks
Defaults to Fixed false Defaults to OverflowBehaviorFlipOnOpen
IndeterminateIcon
The icon used when at least one, but not all, items are selected.
[Parameter]
[Category("List appearance")]
public string IndeterminateIcon { get; set; }
Property Value
Remarks
Defaults to IndeterminateCheckBox. Only applies when MultiSelection is true
.
InputClass
The CSS classes applied to the input.
[Category("Appearance")]
[Parameter]
public string? InputClass { get; set; }
Property Value
Remarks
Defaults to null
. Multiple classes must be separated by spaces.
InputClassname
protected string InputClassname { get; }
Property Value
IsValueInList
protected bool IsValueInList { get; }
Property Value
Items
The list of choices the user can select.
public IReadOnlyList<MudSelectItem<T>> Items { get; }
Property Value
Remarks
Use MudSelectItem<T> components to provide more items.
ListClass
The CSS classes applied to the internal list.
[Parameter]
[Category("List appearance")]
public string? ListClass { get; set; }
Property Value
Remarks
Defaults to null
. Multiple classes must be separated by spaces.
LockScroll
Prevents scrolling while the dropdown is open.
[Parameter]
[Category("List behavior")]
public bool LockScroll { get; set; }
Property Value
Remarks
Defaults to false
.
MaxHeight
The maximum height, in pixels, of the popover of items.
[Parameter]
[Category("List appearance")]
public int MaxHeight { get; set; }
Property Value
Remarks
Defaults to 300
.
MultiSelection
Allows multiple values to be selected via checkboxes.
[Parameter]
[Category("List behavior")]
public bool MultiSelection { get; set; }
Property Value
Remarks
Defaults to false
. When false
, only one value can be selected at a time.
MultiSelectionTextFunc
The custom function for setting the Text
from a list of selected items.
[Parameter]
[Category("Behavior")]
public Func<List<string?>?, string>? MultiSelectionTextFunc { get; set; }
Property Value
Remarks
Defaults to null
.
OnClearButtonClick
Occurs when the clear button is clicked.
[Parameter]
public EventCallback<MouseEventArgs> OnClearButtonClick { get; set; }
Property Value
Remarks
Only occurs when Clearable is true
. This event occurs after the Text
and Value
have been cleared.
OnClose
Occurs when this drop-down closes.
[Category("Behavior")]
[Parameter]
public EventCallback OnClose { get; set; }
Property Value
OnOpen
Occurs when this drop-down opens.
[Category("Behavior")]
[Parameter]
public EventCallback OnOpen { get; set; }
Property Value
OpenIcon
The icon for opening the popover of items.
[Parameter]
[Category("Appearance")]
public string OpenIcon { get; set; }
Property Value
Remarks
Defaults to ArrowDropDown.
OuterClass
The CSS classes applied to the outer div
.
[Category("Appearance")]
[Parameter]
public string? OuterClass { get; set; }
Property Value
Remarks
Defaults to null
. Multiple classes must be separated by spaces.
OuterClassname
protected string OuterClassname { get; }
Property Value
PopoverClass
The CSS classes applied to the popover.
[Parameter]
[Category("List appearance")]
public string? PopoverClass { get; set; }
Property Value
Remarks
Defaults to null
. Multiple classes must be separated by spaces.
QuickSearchInterval
The TimeSpan interval for accepting characters for search input.
[Parameter]
[Category("Behavior")]
public TimeSpan QuickSearchInterval { get; set; }
Property Value
Remarks
Defaults to Zero for single-character searches.
Set to a value greater than zero to enable multi-character searches within the specified interval.
RelativeWidth
Determines the width of this Popover dropdown in relation to the parent container.
[Parameter]
[Category("Appearance")]
public DropdownWidth RelativeWidth { get; set; }
Property Value
Remarks
Defaults to Relative.
When Relative, restricts the max-width of the component to the width of the parent container
When Adaptive, restricts the min-width of the component to the width of the parent container
SelectAll
Shows a "Select all" checkbox to select all items.
[Parameter]
[Category("List behavior")]
public bool SelectAll { get; set; }
Property Value
Remarks
Defaults to false
. Only applies when MultiSelection is true
.
SelectAllCheckBoxIcon
The icon to display whether all, none, or some items are selected.
protected string SelectAllCheckBoxIcon { get; }
Property Value
Remarks
Only applies when MultiSelection is true
.
If all items are selected, CheckedIcon is returned.
If no items are selected, UncheckedIcon is returned.
Otherwise, IndeterminateIcon is returned.
SelectAllText
The text of the "Select all" checkbox.
[Parameter]
[Category("List appearance")]
public string SelectAllText { get; set; }
Property Value
Remarks
Defaults to "Select all"
. Only applies when SelectAll is true
.
SelectedValues
The currently selected values.
[Parameter]
[Category("Data")]
public IEnumerable<T?>? SelectedValues { get; set; }
Property Value
- IEnumerable<T>
Remarks
When MultiSelection is false
, only one value will be returned. When this value changes, SelectedValuesChanged occurs.
SelectedValuesChanged
Occurs when SelectedValues has changed.
[Parameter]
public EventCallback<IEnumerable<T?>?> SelectedValuesChanged { get; set; }
Property Value
Strict
Restricts the selected values to the ones defined in MudSelectItem<T> items.
[Parameter]
[Category("Behavior")]
public bool Strict { get; set; }
Property Value
Remarks
Defaults to false
. When true
, any values not defined will not be displayed.
ToStringFunc
The function for the Text
in drop-down items.
[Parameter]
[Category("List behavior")]
public Func<T?, string?>? ToStringFunc { get; set; }
Property Value
TransformOrigin
The transform origin point for the popover.
[Parameter]
[Category("List appearance")]
public Origin TransformOrigin { get; set; }
Property Value
Remarks
Defaults to TopLeft.
UncheckedIcon
The icon used for unselected items.
[Parameter]
[Category("List appearance")]
public string UncheckedIcon { get; set; }
Property Value
Remarks
Defaults to CheckBoxOutlineBlank. Only applies when MultiSelection is true
.
Methods
BlurAsync()
Releases the focus from this component.
public override ValueTask BlurAsync()
Returns
BuildRenderTree(RenderTreeBuilder)
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
__builder
RenderTreeBuilder
CheckGenericTypeMatch(object)
Throws an exception if the specified item is not compatible with this component.
public void CheckGenericTypeMatch(object selectItem)
Parameters
selectItem
objectThe item to compare. Should be of type
T
for this component.
Clear()
Clears all selections.
public Task Clear()
Returns
CloseMenu(bool)
Closes the drop-down menu.
public Task CloseMenu(bool focusAgain = true)
Parameters
focusAgain
bool
Returns
Remarks
Has no effect if Disabled
or ReadOnly
is true
.
DisposeAsyncCore()
Called to dispose this instance.
protected override ValueTask DisposeAsyncCore()
Returns
FocusAsync()
Sets the focus to this component.
public override ValueTask FocusAsync()
Returns
ForceUpdate()
Forces the SelectedValuesChanged event to occur.
public override Task ForceUpdate()
Returns
GetSelectedValuePresenter()
protected RenderFragment? GetSelectedValuePresenter()
Returns
HasValue(T?)
Gets whether the value is currently selected.
protected override bool HasValue(T? value)
Parameters
value
TThe value to test.
Returns
- bool
When
true
, the specified value exists in SelectedValues.
OnAfterRender(bool)
protected override void OnAfterRender(bool firstRender)
Parameters
firstRender
bool
OnAfterRenderAsync(bool)
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
firstRender
bool
Returns
OnInitialized()
protected override void OnInitialized()
OnParametersSet()
protected override void OnParametersSet()
OpenMenu()
Opens the drop-down menu.
public Task OpenMenu()
Returns
Remarks
Has no effect if Disabled
or ReadOnly
is true
.
RegisterShadowItem(MudSelectItem<T>?)
Links a selection item to this component.
public void RegisterShadowItem(MudSelectItem<T>? item)
Parameters
item
MudSelectItem<T>The item to add.
SelectAsync()
Selects the text within this component.
public override ValueTask SelectAsync()
Returns
SelectClearButtonClickHandlerAsync(MouseEventArgs)
Occurs when the Clear
button has been clicked.
protected ValueTask SelectClearButtonClickHandlerAsync(MouseEventArgs e)
Parameters
Returns
Remarks
This is the first event raised when the clear button is clicked.
The SelectedValues are cleared and the OnClearButtonClick event is raised.
SelectOption(int)
Selects the item at the specified index.
public Task SelectOption(int index)
Parameters
index
intThe ordinal of the item to select (starting at
0
). When MultiSelection istrue
, the item will be added to the selected items.
Returns
SelectOption(object?)
Selects the item with the specified value.
public Task SelectOption(object? obj)
Parameters
obj
objectThe value to select. When MultiSelection is
true
, the selection is cleared if it was already selected.
Returns
SelectRangeAsync(int, int)
Selects a portion of text within this component.
public override ValueTask SelectRangeAsync(int pos1, int pos2)
Parameters
pos1
intThe index of the first character to select. (Starting at
0
.)pos2
intThe index of the last character to select.
Returns
SetCustomizedTextAsync(string, bool, List<string?>?, Func<List<string?>?, string>?)
protected Task SetCustomizedTextAsync(string text, bool updateValue = true, List<string?>? selectedConvertedValues = null, Func<List<string?>?, string>? multiSelectionTextFunc = null)
Parameters
text
stringupdateValue
boolselectedConvertedValues
List<string>multiSelectionTextFunc
Func<List<string>, string>
Returns
ToggleMenu()
Opens or closes the drop-down menu.
public Task ToggleMenu()
Returns
Remarks
Has no effect if Disabled
or ReadOnly
is true
.
UnregisterShadowItem(MudSelectItem<T>?)
Unregisters a selection item to this component.
public void UnregisterShadowItem(MudSelectItem<T>? item)
Parameters
item
MudSelectItem<T>The item to remove.
UpdateTextPropertyAsync(bool)
Occurs when the value has changed internally.
protected override Task UpdateTextPropertyAsync(bool updateValue)
Parameters
updateValue
bool
Returns
Remarks
UpdateValuePropertyAsync(bool)
Occurs when the value has changed internally.
protected override Task UpdateValuePropertyAsync(bool updateText)
Parameters
updateText
bool