Table of Contents

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
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

Origin

Remarks

Defaults to BottomLeft.

CanRenderValue

Whether the Value can be found in the list of Items.

protected bool CanRenderValue { get; }

Property Value

bool

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

string

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

RenderFragment

Classname

protected string Classname { get; }

Property Value

string

ClearIcon

The icon displayed for the clear button when Clearable is true.

[Parameter]
[Category("Appearance")]
public string ClearIcon { get; set; }

Property Value

string

Remarks

Defaults to Clear.

Clearable

Shows a button for clearing any selected values.

[Parameter]
[Category("Behavior")]
public bool Clearable { get; set; }

Property Value

bool

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

string

Remarks

Defaults to ArrowDropUp.

Comparer

The comparer for testing equality of selected values.

[Parameter]
[Category("Behavior")]
public IEqualityComparer<T?>? Comparer { get; set; }

Property Value

IEqualityComparer<T>

Delimiter

The string used to separate multiple selected values.

[Parameter]
[Category("Behavior")]
public string Delimiter { get; set; }

Property Value

string

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

bool

Remarks

Defaults to false.

DropdownSettings

The behavior of the dropdown popover menu

[Category("Behavior")]
[Parameter]
public DropdownSettings DropdownSettings { get; set; }

Property Value

DropdownSettings

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

string

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

string

Remarks

Defaults to null. Multiple classes must be separated by spaces.

InputClassname

protected string InputClassname { get; }

Property Value

string

IsValueInList

protected bool IsValueInList { get; }

Property Value

bool

Items

The list of choices the user can select.

public IReadOnlyList<MudSelectItem<T>> Items { get; }

Property Value

IReadOnlyList<MudSelectItem<T>>

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

string

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

bool

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

int

Remarks

Defaults to 300.

MultiSelection

Allows multiple values to be selected via checkboxes.

[Parameter]
[Category("List behavior")]
public bool MultiSelection { get; set; }

Property Value

bool

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

Func<List<string>, string>

Remarks

Defaults to null.

OnClearButtonClick

Occurs when the clear button is clicked.

[Parameter]
public EventCallback<MouseEventArgs> OnClearButtonClick { get; set; }

Property Value

EventCallback<MouseEventArgs>

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

EventCallback

OnOpen

Occurs when this drop-down opens.

[Category("Behavior")]
[Parameter]
public EventCallback OnOpen { get; set; }

Property Value

EventCallback

OpenIcon

The icon for opening the popover of items.

[Parameter]
[Category("Appearance")]
public string OpenIcon { get; set; }

Property Value

string

Remarks

Defaults to ArrowDropDown.

OuterClass

The CSS classes applied to the outer div.

[Category("Appearance")]
[Parameter]
public string? OuterClass { get; set; }

Property Value

string

Remarks

Defaults to null. Multiple classes must be separated by spaces.

OuterClassname

protected string OuterClassname { get; }

Property Value

string

PopoverClass

The CSS classes applied to the popover.

[Parameter]
[Category("List appearance")]
public string? PopoverClass { get; set; }

Property Value

string

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

TimeSpan

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

DropdownWidth

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

bool

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

string

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

string

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

EventCallback<IEnumerable<T>>

Strict

Restricts the selected values to the ones defined in MudSelectItem<T> items.

[Parameter]
[Category("Behavior")]
public bool Strict { get; set; }

Property Value

bool

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

Func<T, string>

TransformOrigin

The transform origin point for the popover.

[Parameter]
[Category("List appearance")]
public Origin TransformOrigin { get; set; }

Property Value

Origin

Remarks

Defaults to TopLeft.

UncheckedIcon

The icon used for unselected items.

[Parameter]
[Category("List appearance")]
public string UncheckedIcon { get; set; }

Property Value

string

Remarks

Defaults to CheckBoxOutlineBlank. Only applies when MultiSelection is true.

Methods

BlurAsync()

Releases the focus from this component.

public override ValueTask BlurAsync()

Returns

ValueTask

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 object

The item to compare. Should be of type T for this component.

Clear()

Clears all selections.

public Task Clear()

Returns

Task

CloseMenu(bool)

Closes the drop-down menu.

public Task CloseMenu(bool focusAgain = true)

Parameters

focusAgain bool

Returns

Task

Remarks

Has no effect if Disabled or ReadOnly is true.

DisposeAsyncCore()

Called to dispose this instance.

protected override ValueTask DisposeAsyncCore()

Returns

ValueTask

FocusAsync()

Sets the focus to this component.

public override ValueTask FocusAsync()

Returns

ValueTask

ForceUpdate()

Forces the SelectedValuesChanged event to occur.

public override Task ForceUpdate()

Returns

Task

GetSelectedValuePresenter()

protected RenderFragment? GetSelectedValuePresenter()

Returns

RenderFragment

HasValue(T?)

Gets whether the value is currently selected.

protected override bool HasValue(T? value)

Parameters

value T

The 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

Task

OnInitialized()

protected override void OnInitialized()

OnParametersSet()

protected override void OnParametersSet()

OpenMenu()

Opens the drop-down menu.

public Task OpenMenu()

Returns

Task

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

ValueTask

SelectClearButtonClickHandlerAsync(MouseEventArgs)

Occurs when the Clear button has been clicked.

protected ValueTask SelectClearButtonClickHandlerAsync(MouseEventArgs e)

Parameters

e MouseEventArgs

Returns

ValueTask

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 int

The ordinal of the item to select (starting at 0). When MultiSelection is true, the item will be added to the selected items.

Returns

Task

SelectOption(object?)

Selects the item with the specified value.

public Task SelectOption(object? obj)

Parameters

obj object

The value to select. When MultiSelection is true, the selection is cleared if it was already selected.

Returns

Task

SelectRangeAsync(int, int)

Selects a portion of text within this component.

public override ValueTask SelectRangeAsync(int pos1, int pos2)

Parameters

pos1 int

The index of the first character to select. (Starting at 0.)

pos2 int

The index of the last character to select.

Returns

ValueTask

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 string
updateValue bool
selectedConvertedValues List<string>
multiSelectionTextFunc Func<List<string>, string>

Returns

Task

ToggleMenu()

Opens or closes the drop-down menu.

public Task ToggleMenu()

Returns

Task

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

Task

Remarks

This method is called when the Text property needs to be refreshed from current Value.

UpdateValuePropertyAsync(bool)

Occurs when the value has changed internally.

protected override Task UpdateValuePropertyAsync(bool updateText)

Parameters

updateText bool

Returns

Task

Remarks

This method is called when the Value property needs to be refreshed from current Text.

See Also