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.Desktop and mobile behavior
On desktop, a single select opens an accessible listbox popover that you can drive with the arrow keys,
Home, End, type-ahead and Enter.
On iOS and Android it renders the browser's native <select> instead, so people get the platform's own picker.
Set PreferNativePicker to true or false to override the detection.
Select with complex objects
Use
PropertyName to display a specific property when binding to a list of complex objects.Clearable select
Set
Clearable for a button at the end of the field that clears the selection: SelectedValue goes back to its default, such as null, and a Multiple select's SelectedValues becomes empty. OnClear runs afterwards.
The button is shown in every mode, the native picker on iOS and Android included, and is disabled while nothing is selected. It is left out of the Tab order, so from the keyboard press Delete or Backspace on the field instead.
A Required single select always keeps a value, so it shows no clear button.
C#SQL
Item templates
Add an
ItemTemplate to draw each option in the list your own way. The closed field, and the chips of a Multiple select, still show the option's display text from PropertyName.
The native picker falls back to the display text
On iOS and Android the select uses the browser's native picker (see Desktop and mobile behavior), and a native<option> can only hold text.
There the template is not used: each option falls back to its display text from PropertyName, or ToString() when no property is named. The same happens when PreferNativePicker is true.
Keep the display text meaningful on its own, so the select still reads well on a phone.
Required select
Set the
Required property to mark the select as a required field. A select that is not required lists its Placeholder as the first option, and choosing it clears the selection, setting SelectedValue back to its default, such as null. A required select leaves the placeholder out, so a value always stays chosen.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. On desktop it opens the same listbox as a single select, with a tick beside each chosen option, and picking an option leaves the list open. It falls back to a native <select multiple> on iOS and Android, so mobile/touch browsers
still get their own platform multi-select UI rather than a bespoke one.
C#
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.
Full reference: TwInputTheme on the API docs.