The Ignite UI for Blazor Select component allows a single selection from a list of items, placed in a dropdown. This form control offers a quick items list navigation, including selection, based on a single or multiple characters match.
Blazor Select Example
EXAMPLE
MODULES
RAZOR
CSS
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
// required for registering IgniteUIBlazorusing IgniteUI.Blazor.Controls;
namespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Infragistics Blazor
builder.Services.AddIgniteUIBlazor(typeof(IgbSelectModule));
await builder.Build().RunAsync();
}
}
}cs
/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/css
Like this sample? Get access to our complete Ignite UI for Blazor toolkit and start building your own apps in minutes. Download it for free.
Build modern web experiences with 60+ reusable components, including the fastest Data Grid, high-performance Charts, a full set of ready-to-use features, and more.
Before using the IgbSelect component, you need to register it together with its additional components:
// in Program.cs file
builder.Services.AddIgniteUIBlazor(typeof(IgbSelectModule));
razor
You will also need to link an additional CSS file to apply the styling to the IgbSelect component. The following needs to be placed in the wwwroot/index.html file in a Blazor Web Assembly project or the Pages/_Host.cshtml file in a Blazor Server project:
The IgbSelect component can be used inside a Form component, thus it exposes a Name property to be registered with. It also has a Label, and Placeholder properties. The Outlined property is used for styling purposes only when it comes to the Material theme. Except for the default slot, the component provides a few other slots including header, footer, helper-text, prefix, suffix, and toggle-icon. The component size can be changed using the --ig-size CSS variable.
Item
The IgbSelectItem component allows the users to declaratively specify a list of options to be used by the IgbSelect control. Each item provides a Value property that represents the data it carries upon selection. The IgbSelectItem has a default slot which allows you to specify the text content of the item. This text content will be used as value in case the Value property is not present on the IgbSelectItem. You could also provide custom content to be rendered before or after the IgbSelectItem content using the prefix and suffix slots. You could predefine a selected item by setting the Selected property. You could also disable some or all items via the Disabled property.
EXAMPLE
MODULES
RAZOR
CSS
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
// required for registering IgniteUIBlazorusing IgniteUI.Blazor.Controls;
namespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Infragistics Blazor
builder.Services.AddIgniteUIBlazor(typeof(IgbSelectModule));
builder.Services.AddIgniteUIBlazor(typeof(IgbIconModule));
await builder.Build().RunAsync();
}
}
}cs
/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/css
Header
You can use the IgbSelectHeader to provide a header for a group of items.
EXAMPLE
MODULES
RAZOR
CSS
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
// required for registering IgniteUIBlazorusing IgniteUI.Blazor.Controls;
namespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Infragistics Blazor
builder.Services.AddIgniteUIBlazor(typeof(IgbSelectModule));
await builder.Build().RunAsync();
}
}
}cs
Multiple IgbSelectItems can be placed between the opening and closing brackets of an IgbSelectGroup component so that users can visually group them together. The IgbSelectGroup can be labelled via its label slot and disabled via its Disabled property.
Keep in mind that if a select group is disabled, you cannot enable separate items of it.
EXAMPLE
MODULES
RAZOR
CSS
using System;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Text;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
// required for registering IgniteUIBlazorusing IgniteUI.Blazor.Controls;
namespaceInfragistics.Samples
{
publicclassProgram
{
publicstaticasync Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
// registering Infragistics Blazor
builder.Services.AddIgniteUIBlazor(typeof(IgbSelectModule));
builder.Services.AddIgniteUIBlazor(typeof(IgbIconModule));
await builder.Build().RunAsync();
}
}
}cs
/*
CSS styles are loaded from the shared CSS file located at:
https://static.infragistics.com/xplatform/css/samples/
*/css
<IgbSelect><IgbSelectGroup><spanslot="label">Europe</span><IgbSelectItem><IgbIcon @ref="IconRef"slot="prefix"name="place"collection="material"></IgbIcon>
Germany
<spanslot="suffix">DE</span></IgbSelectItem><IgbSelectItem><IgbIconslot="prefix"name="place"collection="material"></IgbIcon>
France
<spanslot="suffix">FR</span></IgbSelectItem><IgbSelectItem><IgbIconslot="prefix"name="place"collection="material"></IgbIcon>
Spain
<spanslot="suffix">ES</span></IgbSelectItem></IgbSelectGroup></IgbSelect>razor
Validation
In addition, the IgbSelect supports most of the IgbInput properties, such as Required, Disabled, Autofocus, etc. The component also exposes a method bound to its validation:
reportValidity - checks for validity and focuses the component if invalid.
Keyboard Navigation
When the select is focused and the list of options is not visible:
Open the Select using the ALT + ↑↓ combination or by clicking on the Space or the Enter key.
Close the Select using the ALT + ↑ or ↓ combination or any of the Enter, Space, Esc or IgbTab keys.
Using the ←→ keys will select the previous item in the list.
Using the ↑↓ keys will select the next item in the list.
Using the Home or End keys will select the first or last item in the list.
Typing characters will query the list of items and select the one that most closely matches the current user input.
When the select is focused and the list of options is visible:
Using the Enter or Space keys will select an item and close the list.
Using the ←→ keys will activate the previous item in the list.
Using the ↑↓ keys will activate the next item in the list.
Using the Home or End keys will activate the first or last item in the list.
The IgbSelect component supports only single selection of items.