Example of keyboard navigations in ASP.NET MVC MultiColumnComboBox Control
This sample demonstrates keyboard navigations support in the MultiColumn Combobox.
@Html.UiMultiColumnComboBox("keyboardnav", new UiMultiColumnComboBoxOptions
{
Placeholder = "Select any product",
Fields = new UiDropDownFields { Text = "ProductName", Value = "ProductID" },
Columns = new List<UiDropDownColumn>
{
new UiDropDownColumn { Field = "ProductID", Header = "Product ID", Width = 100 },
new UiDropDownColumn { Field = "ProductName", Header = "Product Name", Width = 200 },
new UiDropDownColumn { Field = "UnitPrice", Header = "UnitPrice", Width = 90 },
new UiDropDownColumn { Field = "UnitsInStock", Header = "Units In Stock", Width = 120 }
},
PopupHeight = "210px",
PopupWidth = "650px",
DataSource = (IEnumerable<DropdownsDemoController.ProductDetails>)ViewData["data"]
})
<style>
.control-section .control-wrapper { margin: 0 auto; width: 300px; padding-top: 30px; }
.control-section .control-wrapper label { display: block; margin-bottom: 6px; font-weight: 600; }
</style>
@using Lumen.UI.Mvc.Demo.Controllers
<div class="control-section">
<div class="control-wrapper">
<label>Select a product</label>
@Html.UiMultiColumnComboBox("keyboardnav", new UiMultiColumnComboBoxOptions
{
Placeholder = "Select any product",
Fields = new UiDropDownFields { Text = "ProductName", Value = "ProductID" },
Columns = new List<UiDropDownColumn>
{
new UiDropDownColumn { Field = "ProductID", Header = "Product ID", Width = 100 },
new UiDropDownColumn { Field = "ProductName", Header = "Product Name", Width = 200 },
new UiDropDownColumn { Field = "UnitPrice", Header = "UnitPrice", Width = 90 },
new UiDropDownColumn { Field = "UnitsInStock", Header = "Units In Stock", Width = 120 }
},
PopupHeight = "210px",
PopupWidth = "650px",
DataSource = (IEnumerable<DropdownsDemoController.ProductDetails>)ViewData["data"]
})
</div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class MultiColumnComboBoxController : Controller
{
// The page is Views/MultiColumnComboBox/KeyboardNavigation.cshtml; it draws what ViewData holds.
public ActionResult KeyboardNavigation()
{
ViewData["data"] = new ProductDetails().GetAllRecords();
return View();
}
public class ProductDetails
{
public int ProductID { get; set; }
public string ProductName { get; set; }
public string UnitPrice { get; set; }
public int UnitsInStock { get; set; }
public List<ProductDetails> GetAllRecords()
{
List<ProductDetails> ProductDetails = new List<ProductDetails>();
ProductDetails.Add(new ProductDetails { ProductID= 1, ProductName= "Chai", UnitPrice= "18m", UnitsInStock= 39 });
ProductDetails.Add(new ProductDetails { ProductID= 2, ProductName= "Chang", UnitPrice= "19m", UnitsInStock= 45 });
ProductDetails.Add(new ProductDetails { ProductID= 3, ProductName= "Aniseed Syrup", UnitPrice= "23m", UnitsInStock= 79 });
ProductDetails.Add(new ProductDetails { ProductID= 4, ProductName= "Chef Anton Cajun Seasoning", UnitPrice= "28m", UnitsInStock= 28 });
ProductDetails.Add(new ProductDetails { ProductID= 5, ProductName= "Gumbo Mix", UnitPrice= "11m", UnitsInStock= 50 });
ProductDetails.Add(new ProductDetails { ProductID= 6, ProductName= "Grandma Boysenberry", UnitPrice= "37m", UnitsInStock= 49 });
ProductDetails.Add(new ProductDetails { ProductID= 7, ProductName= "Northwoods Cranberry Sauce", UnitPrice= "23m", UnitsInStock= 91 });
ProductDetails.Add(new ProductDetails { ProductID= 8, ProductName= "Mishi Kobe Niku", UnitPrice= "32m", UnitsInStock= 16 });
ProductDetails.Add(new ProductDetails { ProductID= 9, ProductName= "Ikura", UnitPrice= "80m", UnitsInStock= 29 });
ProductDetails.Add(new ProductDetails { ProductID= 10, ProductName= "Uncle Bob Organic Dried Pears", UnitPrice= "26m", UnitsInStock= 32 });
ProductDetails.Add(new ProductDetails { ProductID= 11, ProductName= "Organic Dried Pears", UnitPrice= "29m", UnitsInStock= 19 });
return ProductDetails;
}
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
To provide users with the ability to navigate, select, and interact with popup data in a MultiColumn ComboBox using keyboard shortcuts for improved accessibility.
Keyboards Actions :
Enter- Select the focused item and close the popup.Esc- Close the popup.Alt + Down Arrow- Open the popup.Alt + Up Arrow- Close the popup.Up Arrow- Select the previous item.Down Arrow- Select the next item.Home- Select the first item.End- Select the last item.Tab- Select the focused item, close the popup, and move to the next focusable element.Shift + Tab- Select the focused item, close the popup, and move to the previous focusable element.