Forms
TwInputGroup
TwInputGroup wraps a Blazor input with text, icons or buttons before, after, above or below it, drawn as a single field.
Last updated
Please be aware this component is new, may have bugs and/or be subject to change. Please report any bugs at
https://github.com/twblazor/twblazor/issues.
Icons
Put a
TwIcon in a TwInputGroupAddon. An addon sits at the start of the input by default; set Align="InputGroupAlign.InlineEnd" to put it at the end. Start and end follow the layout direction, so they swap sides in a right to left layout.Text
Use
TwInputGroupText for a protocol, a currency symbol or a unit. It is added to the input's aria-describedby, so a screen reader reads it with the field. Use as many addons as you need on either side.https://
.com
$
USD
Password toggle
Combine an icon at the start with a button at the end that switches the field between
password and text.Multiline text with block addons
Set
Align to InputGroupAlign.BlockStart or InputGroupAlign.BlockEnd to put an addon on its own row above or below the input, such as a toolbar, a character counter or a send button for a Multiline text field.To: design-team
0/280
Variants
The group draws the field for its
Variant - Default, Outlined or Filled - and the input inside takes off its own border, background and rounding. Without a Variant, the group uses the theme's default input variant, the same as the inputs.Dense
Set
Dense on the group for the compact height. The input and the buttons inside it shrink to match, so the group lines up with other dense inputs.Other inputs
Any single-line input can go in a group: a
TwSelect, a TwMaskedInput, a TwNumeric, a TwAutocomplete or a picker such as TwDatePicker.kg
Validation and disabled
An invalid input turns the group's border red, and its message is shown below the group rather than inside it, still linked to the input through
aria-describedby. A disabled input dims the whole group.@
Use at least 3 characters.
Custom styling
Class styles the group itself and is merged with the theme's classes, so it can replace the rounding or border colour. RootClass styles the element that also holds the label and messages.RAZOR
<TwInputGroup AriaLabel="Search the docs" Variant="InputVariant.Outlined" Rounded="Rounded.Full" Class="border-purple-600 dark:border-purple-400">
<TwInputGroupAddon><TwIcon Icon="Icon.Search" /></TwInputGroupAddon>
<TwTextfield T="string" InputType="search" AriaLabel="Search the docs" Placeholder="Search the docs" @bind-Value="search" />
<TwInputGroupAddon Align="InputGroupAlign.InlineEnd">
<TwInputGroupButton Label="Search" Variant="ButtonVariant.Filled" Color="Color.Primary" />
</TwInputGroupAddon>
</TwInputGroup>Accessibility
The group is rendered with
role="group" and named by its Label (or AriaLabel). Set For to the input's Id so the label names the input too and clicking it focuses the input; otherwise give the input its own AriaLabel. Text in a TwInputGroupText is added to the input's aria-describedby; set DescribesInput="false" for text that adds nothing, such as a live counter. Icons are decorative and hidden from screen readers unless they have an AriaLabel. Addons are placed by Align rather than by their order in the markup, but Tab follows the markup, so write them in the order they appear. The group's focus ring follows the input, while each button in an addon shows its own.
Theme configuration
Styling is controlled by
TwBlazorTheme.Components (a TwInputGroupTheme), 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.
| Property | Type | Controls |
|---|---|---|
Root |
string | |
Group |
string | |
Padding |
string | |
DefaultPadding |
string | |
FocusBorder |
string | |
InvalidBorder |
string | |
Disabled |
string | |
Control |
string | |
ControlRoot |
string | |
ControlRootOutlinedOffset |
string | |
ControlRootUnderlinedOffset |
string | |
Addon |
string | |
AddonInlineStart |
string | |
AddonInlineEnd |
string | |
AddonBlockStart |
string | |
AddonBlockEnd |
string | |
Text |
string | |
Button |
string | |
ButtonDense |
string | |
IconButtonDense |
string |
Full reference: TwInputGroupTheme on the API docs.