Forms
TwTextfield
TwTextfield is a Blazor text input component. Bind Value, use Multiline for a textarea, add a clear button with Clearable, and validate with Validator.
Last updated
Textfield
Bind
Value to a labeled text input with a placeholder.RAZOR
<div class="md:flex-col flex-row flex gap-2">
<TwTextfield Label="Forename" @bind-Value="Forename" Placeholder="Please enter your forename" AriaLabel="Forename textfield" />
<TwTextfield Label="Surname" @bind-Value="Surname" Placeholder="Please enter your surname" AriaLabel="Surname textfield" />
</div>Disabled textfield
Use the
Disabled property to prevent interaction with the textfield.RAZOR
<TwTextfield Label="Forename" @bind-Value="Forename" Placeholder="Please enter your forename" AriaLabel="Forename textfield" Disabled />Readonly textfield
Use the
ReadOnly property to display a value that can't be edited.RAZOR
<TwTextfield Label="Account ID" @bind-Value="AccountId" Placeholder="Account ID" AriaLabel="Account ID textfield" ReadOnly />Outlined variant
Set
Variant="InputVariant.Outlined" for an outlined textfield style.RAZOR
<div class="md:flex-col flex-row flex gap-2">
<TwTextfield Label="Forename" @bind-Value="Forename" Placeholder="Please enter your forename" AriaLabel="Forename textfield" Variant="InputVariant.Outlined" />
<TwTextfield Label="Surname" @bind-Value="Surname" Placeholder="Please enter your surname" AriaLabel="Surname textfield" Variant="InputVariant.Outlined" />
</div>Filled variant
Set
Variant="InputVariant.Filled" for a filled textfield style.RAZOR
<div class="md:flex-col flex-row flex gap-2">
<TwTextfield Label="Forename" @bind-Value="Forename" Placeholder="Please enter your forename" AriaLabel="Forename textfield" Variant="InputVariant.Filled" />
<TwTextfield Label="Surname" @bind-Value="Surname" Placeholder="Please enter your surname" AriaLabel="Surname textfield" Variant="InputVariant.Filled" />
</div>Different input types
Use
InputType to render native input types such as email and password.RAZOR
<div class="md:flex-col flex-row flex gap-2">
<TwTextfield Label="Email" @bind-Value="Email" Placeholder="Enter your email address" AriaLabel="Email textfield" InputType="email" />
<TwTextfield Label="Password" @bind-Value="Password" Placeholder="Enter password" AriaLabel="Password textfield" InputType="password" />
</div>Invalid textfield
Set
Invalid and ErrorMessage to mark the textfield as failing validation. The message is rendered below the input and associated with it via aria-describedby so assistive technology announces it alongside the field.Please enter a valid email address.
RAZOR
<TwTextfield Label="Email" @bind-Value="InvalidEmail" Placeholder="Enter your email address" AriaLabel="Email textfield" Invalid ErrorMessage="Please enter a valid email address." />Dense textfield
Set
Dense for a more compact input with a smaller height and text size. Every single-line input shares the same dense height, so they line up when used side by side.RAZOR
<TwTextfield Label="Forename" @bind-Value="Forename" Placeholder="Please enter your forename" AriaLabel="Dense forename textfield" Dense />Clearable textfield
Set
Clearable to show an X button at the end of the field. It is disabled while the field is empty. Pressing it empties the field, runs Validator, invokes OnClear and moves focus back into the field. The button is not a Tab stop, since keyboard users can clear the text themselves, and it is hidden while the field is disabled or read-only.Cleared 0 times.
Start and end content
Use
StartContent and EndContent to draw content over the start or end of a single-line field, such as an icon or a unit. The field's padding is not widened for it, so add padding through Class so the text does not run underneath. Hide decorative content from screen readers with aria-hidden="true".RAZOR
<TwTextfield Label="Website" @bind-Value="Website" Placeholder="example.co.uk" Class="ps-9" Clearable>
<StartContent>
<TwIcon Icon="Icon.Globe" aria-hidden="true" />
</StartContent>
</TwTextfield>Validation on change
Pass a
Validator function to have the textfield validate itself whenever its value changes. Return null (or an empty string) when the value is valid, or an error message to automatically mark the field Invalid and display the returned message - no need to manage Invalid or ErrorMessage yourself.Asynchronous validation
Validator returns a Task<string?>, so it can perform asynchronous work such as an API call without blocking the UI. This example simulates checking username availability against a server.Multiline textfield
Set
Multiline to render a <textarea> for longer text such as comments or descriptions. It shows three lines by default and can be resized vertically by dragging its corner.RAZOR
<TwTextfield Label="Comments" @bind-Value="Comments" Placeholder="Tell us what you think" Multiline />Multiline rows
Use
Rows to set how many lines of text are visible before the field scrolls.RAZOR
<div class="md:flex-col flex-row flex gap-2">
<TwTextfield Label="Summary" @bind-Value="Summary" Placeholder="A one or two line summary" Multiline Rows="2" />
<TwTextfield Label="Description" @bind-Value="IssueDescription" Placeholder="Describe the issue in detail" Multiline Rows="6" />
</div>Auto-growing multiline
Set
AutoGrow to have the field grow taller as the user types instead of scrolling. Rows sets the starting height and MaxRows caps how tall it can grow, after which it scrolls. Browsers without support for the CSS field-sizing property keep the Rows height and scroll.RAZOR
<TwTextfield Label="Message" @bind-Value="Message" Placeholder="Start typing and the field grows with you" Multiline AutoGrow Rows="2" MaxRows="8" BindEvent="oninput" />Multiline variants
Multiline fields support every
Variant, so they match the single-line fields beside them.RAZOR
<div class="flex flex-col gap-4">
<TwTextfield Label="Default" @bind-Value="DefaultNotes" Placeholder="Notes" Multiline Variant="InputVariant.Default" />
<TwTextfield Label="Outlined" @bind-Value="OutlinedNotes" Placeholder="Notes" Multiline Variant="InputVariant.Outlined" />
<TwTextfield Label="Filled" @bind-Value="FilledNotes" Placeholder="Notes" Multiline Variant="InputVariant.Filled" />
</div>Dense multiline
Combine
Multiline with Dense for tighter padding and a smaller text size.RAZOR
<TwTextfield Label="Notes" @bind-Value="DenseNotes" Placeholder="Add a short note" Multiline Dense Rows="2" />Multiline character limit
Pass
maxlength through Attributes to limit how much can be typed, and bind on oninput to show a live count below the field.0 / 160
Multiline validation
Validator, Required, Disabled and ReadOnly work the same way on a multiline field. The error message is linked to the textarea with aria-describedby.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.