Forms
TwSelect
TwSelect is a Blazor select component for complex objects and numbers. Bind SelectedValue, or SelectedValues with Multiple, and set Placeholder and Required.
Last updated
Basic Select
Bind
SelectedValue and use Variant to switch between default, filled and outlined styles.Select with Complex Objects
Use
PropertyName to display a specific property when binding to a list of complex objects.Required Select
Set the
Required property to mark the select as a required field.Razor
<TwSelect T="string"
Label="Favourite Color"
Values="@colors"
@bind-SelectedValue="@selectedColor"
Required
AriaLabel="Color select" />
@if (!string.IsNullOrEmpty(selectedColor))
{
<p class="mt-3 text-sm text-gray-600 dark:text-gray-400">Selected Color: <strong>@selectedColor</strong></p>
}Disabled and Readonly Select
Use the
Disabled and ReadOnly properties to restrict interaction with the select.Select with Numbers
TwSelect works with numeric types as well as strings and objects.
Razor
<TwSelect T="int"
Label="Quantity"
Values="@quantities"
@bind-SelectedValue="@selectedQuantity"
Placeholder="Select quantity..."
AriaLabel="Quantity select" />
@if (selectedQuantity > 0)
{
<p class="mt-3 text-sm text-gray-600 dark:text-gray-400">Selected Quantity: <strong>@selectedQuantity</strong></p>
<p class="text-sm text-gray-600 dark:text-gray-400">Total Price: <strong>$@(selectedQuantity * 10)</strong></p>
}Dense Select
Set
Dense for a more compact select with a smaller height and text size, matching the other dense inputs. Multi-select is not affected, as its height follows its selected chips.Multi-select
Set
Multiple and bind SelectedValues (instead of SelectedValue) to let more than
one option be selected at once. It renders as a native <select multiple>, so mobile/touch browsers
still get their own platform multi-select UI rather than a bespoke one.
Selected Skills: C#
Razor
<TwSelect T="string"
Label="Skills"
Values="@skills"
Multiple
@bind-SelectedValues="@selectedSkills"
AriaLabel="Skills select" />
@if (selectedSkills.Any())
{
<p class="mt-3 text-sm text-gray-600 dark:text-gray-400">Selected Skills: <strong>@string.Join(", ", selectedSkills)</strong></p>
}Theme Configuration
Styling is controlled by
TwBlazorTheme.Components (a TwInputTheme), configured via the
AddTwBlazor() options callback described on the Get Started page.
Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
Inherited from TwTextfield - this component reuses that theme rather than defining its own.
| Property | Type | Controls |
|---|---|---|
DefaultInputVariant |
InputVariant | |
TextfieldBase |
string | |
SelectBase |
string | |
Size |
string | |
DenseSize |
string | |
SelectOption |
string | |
SelectNativeBackground |
string | |
SelectDefaultPadding |
string | |
SelectReadOnlyBackground |
string | |
SelectMultiTriggerLayout |
string | |
SelectNativeMultiOverlay |
string | |
SelectMultiOpenButton |
string | |
SelectPanelPosition |
string | |
SelectPanelSurface |
string | |
SelectPanelItemText |
string | |
LabelBase |
string | |
InputLegendBase |
string | |
OutlinedBorder |
string | |
FilledBorder |
string | |
FocusBorder |
string | |
FilledBackgroundColor |
string | |
ErrorMessage |
string |
Full reference: TwInputTheme on the API docs.