Table of Contents

Class TwSelect<T>

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

Represents a generic select dropdown component that supports two-way data binding.

public class TwSelect<T> : TwPopoverPickerComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, ITwInputComponent, IAsyncDisposable

Type Parameters

T

The type of values in the dropdown options.

Inheritance
TwSelect<T>
Implements
Inherited Members

Remarks

The TwSelect component provides a flexible dropdown control that can bind to collections of any type. It supports customizable styling, placeholder text, required validation, and property-based display text. The component implements two-way binding through the SelectedValue and SelectedValueChanged parameters.

Constructors

TwSelect()

public TwSelect()

Properties

Multiple

Gets or sets whether more than one option can be selected at once.

[Parameter]
public bool Multiple { get; set; }

Property Value

bool

Remarks

A closed trigger (matching the single-select look) is always shown. On a device that prefers its own native picker (see PreferNativePicker), tapping it opens a real, invisible <select multiple> layered on top - so the platform's own multi-select UI (e.g. iOS/Android's full-screen sheet) still handles the interaction. Everywhere else, it opens a custom checkbox-list popover instead, since a native multi-select can't render as a closed, single-row trigger the way a single-select can. Bind SelectedValues/SelectedValuesChanged rather than SelectedValue/SelectedValueChanged when this is true.

Placeholder

Gets or sets the placeholder text displayed when no value is selected.

[Parameter]
public string Placeholder { get; set; }

Property Value

string

Remarks

When Multiple is true, this is shown on the closed trigger only while nothing is selected - it's replaced by a chip per selected option once at least one is picked.

PropertyName

Gets or sets the name of the property to display for complex objects.

[Parameter]
public string PropertyName { get; set; }

Property Value

string

Remarks

When Values contains complex objects, specify the property name to display as the option text. If null or empty, the object's ToString() method will be used.

Required

Gets or sets whether the select is required (no empty option will be shown).

[Parameter]
public bool Required { get; set; }

Property Value

bool

SelectedValue

Gets or sets the currently selected value.

[Parameter]
public T SelectedValue { get; set; }

Property Value

T

Remarks

Not used when Multiple is true - bind SelectedValues instead.

SelectedValueChanged

Gets or sets the callback that is invoked when the selected value changes.

[Parameter]
public EventCallback<T> SelectedValueChanged { get; set; }

Property Value

EventCallback<T>

SelectedValues

Gets or sets the currently selected values when Multiple is true.

[Parameter]
public IEnumerable<T> SelectedValues { get; set; }

Property Value

IEnumerable<T>

SelectedValuesChanged

Gets or sets the callback that is invoked when the selection changes while Multiple is true.

[Parameter]
public EventCallback<IEnumerable<T>> SelectedValuesChanged { get; set; }

Property Value

EventCallback<IEnumerable<T>>

Values

Gets or sets the collection of values to display in the dropdown.

[Parameter]
public IEnumerable<T> Values { get; set; }

Property Value

IEnumerable<T>

Methods

BuildRenderTree(RenderTreeBuilder)

Renders the component to the supplied RenderTreeBuilder.

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

OnAfterRenderAsync(bool)

Determines, via PreferNativePicker or JS-based device detection, whether Multiple's closed trigger should hand taps/clicks to a real invisible native <select multiple> instead of opening the custom checkbox popover.

protected override Task OnAfterRenderAsync(bool firstRender)

Parameters

firstRender bool

Returns

Task

OnParametersSet()

Invoked when the component's parameters have been set. Ensures that the component has a unique identifier by generating one if none is provided.

protected override void OnParametersSet()

Remarks

If the component's identifier is not set, a unique ID is generated based on the component's type name (with a 'Tw' prefix removed if present) and a GUID. This helps ensure that each component instance can be uniquely identified, which is useful for scenarios such as associating labels with form elements or targeting elements in client-side scripts.