Blazor Input Group
The Blazor Bootstrap InputGroup component extends form inputs with text, icon, checkbox, radio, button, and dropdown add-ons on either side. The examples below cover sizing, checkboxes and radios, multiple inputs, multiple add-ons and button add-ons.
INFO
InputGroup follows the
Bootstrap 5.3 input group .
It wraps
TextInput,
NumberInput,
CurrencyInput,
DateInput,
TimeInput,
TextAreaInput,
EnumInput, and Blazor's
InputFile.
PasswordInput and
AutoComplete already render their own input group, so they cannot be placed inside an
InputGroup.
Basic usage
#
Place text or icon add-ons before, after, or on both sides of an input.
How to use:
Add InputGroup and put the input and its InputGroupText add-ons inside, in display order.
Give the input an accessible name with aria-label or a <label> outside the group.
Set an Id on the InputGroupText and reference it from the input's aria-describedby so screen readers read the add-on with the input.
Keep help text outside the group.
This demo shows prefix, suffix, label-plus-help, icon, and textarea groups.
Example View Source
<InputGroup Class="mb-3">
<InputGroupText Id="basic-addon-at">@@</InputGroupText>
<TextInput @bind-Value="username" Placeholder="Username" aria-label="Username" aria-describedby="basic-addon-at" />
</InputGroup>
<InputGroup Class="mb-3">
<TextInput @bind-Value="recipient" Placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="basic-addon-domain" />
<InputGroupText Id="basic-addon-domain">@@example.com</InputGroupText>
</InputGroup>
<label for="basic-url" class="form-label">Your vanity URL</label>
<InputGroup Class="mb-3">
<InputGroupText Id="basic-addon-url">https://example.com/users/</InputGroupText>
<TextInput Id="basic-url" @bind-Value="vanityUrl" aria-describedby="basic-addon-url basic-url-help" />
</InputGroup>
<div class="form-text mb-3" id="basic-url-help">Example help text goes outside the input group.</div>
<InputGroup Class="mb-3">
<InputGroupText><Icon Name="IconName.Search" aria-hidden="true" /></InputGroupText>
<TextInput @bind-Value="search" Placeholder="Search" aria-label="Search" />
</InputGroup>
<InputGroup>
<InputGroupText>With textarea</InputGroupText>
<TextAreaInput @bind-Value="notes" aria-label="With textarea" />
</InputGroup>
@code {
private string? username;
private string? recipient;
private string? vanityUrl;
private string? search;
private string? notes;
}
Sizing
#
Set the size on the group, and every input and add-on inside it resizes.
How to use:
Set Size to InputGroupSize.Small or InputGroupSize.Large.
Do not size the individual inputs inside the group.
This demo shows small, default, and large groups, and small and large groups with a
Dropdown add-on.
Example View Source
<InputGroup Size="InputGroupSize.Small" Class="mb-3">
<InputGroupText Id="sizing-small">Small</InputGroupText>
<TextInput @bind-Value="small" aria-label="Small text input" aria-describedby="sizing-small" />
</InputGroup>
<InputGroup Class="mb-3">
<InputGroupText Id="sizing-default">Default</InputGroupText>
<TextInput @bind-Value="normal" aria-label="Default text input" aria-describedby="sizing-default" />
</InputGroup>
<InputGroup Size="InputGroupSize.Large" Class="mb-3">
<InputGroupText Id="sizing-large">Large</InputGroupText>
<TextInput @bind-Value="large" aria-label="Large text input" aria-describedby="sizing-large" />
</InputGroup>
<InputGroup Size="InputGroupSize.Small" Class="mb-3">
<TextInput @bind-Value="smallSearch" aria-label="Small search" />
<Dropdown Color="DropdownColor.Secondary">
<DropdownToggleButton>@smallScope</DropdownToggleButton>
<DropdownMenu Position="DropdownMenuPosition.End">
<DropdownItem @onclick="@(() => smallScope = "All")">All</DropdownItem>
<DropdownItem @onclick="@(() => smallScope = "Docs")">Docs</DropdownItem>
</DropdownMenu>
</Dropdown>
</InputGroup>
<InputGroup Size="InputGroupSize.Large">
<TextInput @bind-Value="largeSearch" aria-label="Large search" />
<Dropdown Color="DropdownColor.Secondary">
<DropdownToggleButton>@largeScope</DropdownToggleButton>
<DropdownMenu Position="DropdownMenuPosition.End">
<DropdownItem @onclick="@(() => largeScope = "All")">All</DropdownItem>
<DropdownItem @onclick="@(() => largeScope = "Docs")">Docs</DropdownItem>
</DropdownMenu>
</Dropdown>
</InputGroup>
@code {
private string? small;
private string? normal;
private string? large;
private string? smallSearch;
private string? largeSearch;
private string smallScope = "All";
private string largeScope = "All";
}
Checkboxes and radios
#
Put a checkbox or radio inside an add-on instead of text.
How to use:
Place an <input class="form-check-input mt-0"> of type checkbox or radio inside InputGroupText.
Give the checkbox or radio an aria-label, because it has no visible label.
Give radios in the same set the same name.
This demo enables an email field with a checkbox and picks a contact method with radios.
Example View Source
<InputGroup Class="mb-3">
<InputGroupText>
<input class="form-check-input mt-0" type="checkbox" @bind="newsletter" aria-label="Subscribe to the newsletter" />
</InputGroupText>
<TextInput @bind-Value="email" Placeholder="Email for the newsletter" aria-label="Email for the newsletter" Disabled="@(!newsletter)" />
</InputGroup>
<InputGroup>
<InputGroupText>
<input class="form-check-input mt-0" type="radio" name="contact-method" checked="@(contactMethod == "phone")" @onchange="@(() => contactMethod = "phone")" aria-label="Contact me by phone" />
</InputGroupText>
<TextInput @bind-Value="phone" Placeholder="Phone number" aria-label="Phone number" />
<InputGroupText>
<input class="form-check-input mt-0" type="radio" name="contact-method" checked="@(contactMethod == "email")" @onchange="@(() => contactMethod = "email")" aria-label="Contact me by email" />
</InputGroupText>
<TextInput @bind-Value="contactEmail" Placeholder="Email" aria-label="Contact email" />
</InputGroup>
<div class="mt-3">Newsletter: <b>@(newsletter ? "on" : "off")</b>, contact method: <b>@contactMethod</b></div>
@code {
private bool newsletter = true;
private string? email;
private string contactMethod = "phone";
private string? phone;
private string? contactEmail;
}
A group can hold more than one input. Validation styling is supported only for groups with a single input, as in Bootstrap.
How to use:
Place the inputs side by side inside InputGroup.
Give each input its own aria-label.
This demo collects a first and last name.
Example View Source
<InputGroup>
<InputGroupText>First and last name</InputGroupText>
<TextInput @bind-Value="firstName" aria-label="First name" />
<TextInput @bind-Value="lastName" aria-label="Last name" />
</InputGroup>
@code {
private string? firstName;
private string? lastName;
}
Multiple add-ons
#
Stack several add-ons on one side, or use add-ons on both sides.
How to use:
Add several InputGroupText components next to each other.
Mix them freely with the input.
This demo shows currency and unit add-ons around a
NumberInput.
Example View Source
<InputGroup Class="mb-3">
<InputGroupText>$</InputGroupText>
<InputGroupText>0.00</InputGroupText>
<NumberInput TValue="decimal?" @bind-Value="amountBefore" aria-label="Dollar amount (with dot and two decimal places)" />
</InputGroup>
<InputGroup Class="mb-3">
<NumberInput TValue="decimal?" @bind-Value="amountAfter" aria-label="Dollar amount (with dot and two decimal places)" />
<InputGroupText>$</InputGroupText>
<InputGroupText>0.00</InputGroupText>
</InputGroup>
<InputGroup>
<InputGroupText>Weight</InputGroupText>
<NumberInput TValue="int?" @bind-Value="weight" aria-label="Weight in kilograms" />
<InputGroupText>kg</InputGroupText>
</InputGroup>
@code {
private decimal? amountBefore;
private decimal? amountAfter;
private int? weight;
}
Use
Button components as add-ons, one or more on each side.
How to use:
Place Button components before or after the input inside InputGroup.
Give icon-only or symbol-only buttons an aria-label.
This demo shows a paste button, a search button, and a seat counter with buttons on both sides.
Example View Source
<InputGroup Class="mb-3">
<Button Color="ButtonColor.Secondary" Outline="true" @onclick="Paste">Paste</Button>
<TextInput @bind-Value="text" Placeholder="Click Paste to fill" aria-label="Text with a button add-on before it" />
</InputGroup>
<InputGroup Class="mb-3">
<TextInput @bind-Value="query" Placeholder="Search docs" aria-label="Search docs" />
<Button Color="ButtonColor.Primary" @onclick="Search">Search</Button>
</InputGroup>
<InputGroup>
<Button Color="ButtonColor.Secondary" Outline="true" @onclick="Decrease" aria-label="Decrease seats">−</Button>
<Button Color="ButtonColor.Secondary" Outline="true" @onclick="Increase" aria-label="Increase seats">+</Button>
<NumberInput TValue="int" @bind-Value="seats" Min="1" Max="20" EnableMinMax="true" aria-label="Seats" />
<Button Color="ButtonColor.Danger" Outline="true" @onclick="Reset">Reset</Button>
<Button Color="ButtonColor.Success" Outline="true" @onclick="Save">Save</Button>
</InputGroup>
<div class="mt-3">@message</div>
@code {
private string? text;
private string? query;
private int seats = 2;
private string? message;
private void Paste() => text = "Pasted text";
private void Search() => message = $"Searching for \"{query}\".";
private void Decrease() => seats = Math.Max(1, seats - 1);
private void Increase() => seats = Math.Min(20, seats + 1);
private void Reset() => seats = 2;
private void Save() => message = $"Saved {seats} seats.";
}
Use a
Dropdown as an add-on to let users choose an option that changes the input.
How to use:
Place a Dropdown with a DropdownToggleButton and DropdownMenu before or after the input.
Set Position="DropdownMenuPosition.End" on the menu when the dropdown is the last add-on.
This demo picks a search field and a currency.
Example View Source
<InputGroup Class="mb-3">
<Dropdown Color="DropdownColor.Secondary">
<DropdownToggleButton>@field</DropdownToggleButton>
<DropdownMenu>
<DropdownItem @onclick="@(() => field = "Title")">Title</DropdownItem>
<DropdownItem @onclick="@(() => field = "Author")">Author</DropdownItem>
<DropdownItem @onclick="@(() => field = "Tag")">Tag</DropdownItem>
</DropdownMenu>
</Dropdown>
<TextInput @bind-Value="term" Placeholder="@($"Search by {field.ToLowerInvariant()}")" aria-label="@($"Search by {field.ToLowerInvariant()}")" />
</InputGroup>
<InputGroup>
<NumberInput TValue="decimal?" @bind-Value="price" aria-label="Price" />
<Dropdown Color="DropdownColor.Secondary">
<DropdownToggleButton>@currency</DropdownToggleButton>
<DropdownMenu Position="DropdownMenuPosition.End">
<DropdownItem @onclick="@(() => currency = "USD")">USD</DropdownItem>
<DropdownItem @onclick="@(() => currency = "EUR")">EUR</DropdownItem>
<DropdownItem @onclick="@(() => currency = "INR")">INR</DropdownItem>
</DropdownMenu>
</Dropdown>
</InputGroup>
@code {
private string field = "Title";
private string? term;
private decimal? price;
private string currency = "USD";
}
Combine an action button with a split dropdown toggle.
How to use:
Place a Dropdown with Split="true", a DropdownActionButton, and a DropdownToggleButton next to the input.
Give the split toggle screen-reader text with a visually-hidden span, because it has no visible text.
This demo sends, schedules, or saves a message.
Example View Source
<InputGroup>
<TextInput @bind-Value="message" Placeholder="Write a message" aria-label="Message" />
<Dropdown Color="DropdownColor.Primary" Split="true">
<DropdownActionButton @onclick="Send">Send</DropdownActionButton>
<DropdownToggleButton>
<span class="visually-hidden">More send options</span>
</DropdownToggleButton>
<DropdownMenu Position="DropdownMenuPosition.End">
<DropdownItem @onclick="Schedule">Schedule send</DropdownItem>
<DropdownItem @onclick="SaveDraft">Save as draft</DropdownItem>
</DropdownMenu>
</Dropdown>
</InputGroup>
<div class="mt-3">@status</div>
@code {
private string? message;
private string? status;
private void Send() => status = $"Sent: \"{message}\"";
private void Schedule() => status = "Scheduled for tomorrow at 9:00.";
private void SaveDraft() => status = "Saved as draft.";
}
Select menus and file inputs work in input groups too.
How to use:
Use EnumInput for a select, or Blazor's InputFile with class="form-control" for a file input.
To label the control with the add-on, set For on InputGroupText to the control's id; the add-on then renders as a <label>.
This demo labels a select and a file input with add-ons and pairs a select with a button.
Example View Source
Priority
High Medium Low
High Medium Low
Apply
Upload
<InputGroup Class="mb-3">
<InputGroupText For="input-group-priority">Priority</InputGroupText>
<EnumInput TEnum="Priority" Id="input-group-priority" @bind-Value="priority" />
</InputGroup>
<InputGroup Class="mb-3">
<EnumInput TEnum="Priority" @bind-Value="priority" aria-label="Priority" />
<Button Color="ButtonColor.Secondary" Outline="true" @onclick="Apply">Apply</Button>
</InputGroup>
<InputGroup>
<InputGroupText For="input-group-file">Upload</InputGroupText>
<InputFile id="input-group-file" class="form-control" OnChange="OnFileChange" />
</InputGroup>
<div class="mt-3">@status</div>
@code {
private int priority = (int)Priority.Medium;
private string? status;
private void Apply() => status = $"Priority set to {(Priority)priority}.";
private void OnFileChange(InputFileChangeEventArgs e) => status = $"Selected {e.File.Name}.";
}
Wrapping
#
Input groups wrap by default so validation messages fit. Turn wrapping off to keep everything on one line.
How to use:
This demo shows both behaviors in a narrow container.
Example View Source
<div style="max-width: 16rem;">
<div class="mb-1">Wraps (default):</div>
<InputGroup Class="mb-3">
<InputGroupText>A long add-on label</InputGroupText>
<TextInput @bind-Value="wrapped" aria-label="Wrapping input" />
</InputGroup>
<div class="mb-1">No wrap:</div>
<InputGroup NoWrap="true">
<InputGroupText>A long add-on label</InputGroupText>
<TextInput @bind-Value="noWrap" aria-label="Non-wrapping input" />
</InputGroup>
</div>
@code {
private string? wrapped;
private string? noWrap;
}
A group with a single input shows its validation message below the group, with the corners intact.
How to use:
Place the input inside InputGroup in an EditForm.
Add ValidationMessage as the last child of the InputGroup.
This demo requires a username and a budget before the form can be submitted.
Example View Source
@using System.ComponentModel.DataAnnotations
<EditForm Model="signup" OnValidSubmit="HandleValidSubmit" OnInvalidSubmit="() => submitted = false">
<DataAnnotationsValidator />
<label class="form-label" for="validation-username">Username</label>
<InputGroup Class="mb-3">
<InputGroupText Id="validation-addon">@@</InputGroupText>
<TextInput Id="validation-username" @bind-Value="signup.Username" aria-describedby="validation-addon" />
<ValidationMessage For="() => signup.Username" />
</InputGroup>
<label class="form-label" for="validation-budget">Monthly budget</label>
<InputGroup Class="mb-3">
<InputGroupText>$</InputGroupText>
<NumberInput TValue="decimal?" Id="validation-budget" @bind-Value="signup.Budget" />
<InputGroupText>.00</InputGroupText>
<ValidationMessage For="() => signup.Budget" />
</InputGroup>
<Button Type="ButtonType.Submit" Color="ButtonColor.Primary">Submit</Button>
</EditForm>
@if (submitted)
{
<div class="mt-3">Welcome, @signup.Username!</div>
}
@code {
private Signup signup = new();
private bool submitted;
private void HandleValidSubmit() => submitted = true;
public class Signup
{
[Required(ErrorMessage = "Please choose a username.")]
[StringLength(20, MinimumLength = 3, ErrorMessage = "Use 3 to 20 characters.")]
public string? Username { get; set; }
[Required(ErrorMessage = "Please enter a budget.")]
[Range(1, 10000, ErrorMessage = "Enter a budget from 1 to 10,000.")]
public decimal? Budget { get; set; }
}
}
The Blazor Bootstrap inputs that render a single input element work inside an input group.
How to use:
Use TextInput, NumberInput, CurrencyInput, DateInput, TimeInput, TextAreaInput, or EnumInput inside InputGroup.
Do not nest PasswordInput or AutoComplete; they already render their own input group.
This demo shows currency, date, and time inputs with add-ons.
Example View Source
<InputGroup Class="mb-3">
<InputGroupText>Price</InputGroupText>
<CurrencyInput TValue="decimal" @bind-Value="price" Locale="en-US" aria-label="Price" />
<InputGroupText>per month</InputGroupText>
</InputGroup>
<InputGroup Class="mb-3">
<InputGroupText><Icon Name="IconName.CalendarDate" aria-hidden="true" /></InputGroupText>
<DateInput TValue="DateOnly?" @bind-Value="date" aria-label="Check-in date" />
</InputGroup>
<InputGroup>
<InputGroupText><Icon Name="IconName.Clock" aria-hidden="true" /></InputGroupText>
<TimeInput TValue="TimeOnly?" @bind-Value="time" aria-label="Arrival time" />
</InputGroup>
@code {
private decimal price = 49;
private DateOnly? date;
private TimeOnly? time;
}