PickList
Since 0.1.0-alpha.21Two lists to move choices between, bound to a collection in the order chosen.
Columns, in order
Bind Value to a collection and set Items. To let people set the order, set Reorderable: Move up and Move down sit beside the chosen list, and items drag within it. The chosen items post in their order.
Static
Preview
Code
Microsoft.AspNetCore.Http
@* A report's columns, in the order chosen: Save posts them in that order, on a static page too. *@
<Form Model="Model" FormName="pick-list-usage" OnValidSubmit="Save" MaxWidth="36.Rem" Grow>
<PickList Label="Columns" @bind-Value="Model!.Columns" Items="AllColumns" Reorderable />
<Row Gap="3" Align="Align.Center" Wrap>
<Button Submit>Save</Button>
if (_saved)
{
<TextBlock Size="TextSize.Sm" Color="Color.Muted" role="status">Columns: (Model!.Columns is { Count: > 0 } columns ? string.Join(", ", columns) : "none")</TextBlock>
}
</Row>
</Form>
{
[SupplyParameterFromForm(FormName = "pick-list-usage")]
private Report? Model { get; set; }
private bool _saved;
[CascadingParameter] private HttpContext? HttpContext { get; set; }
// A post with nothing chosen sends nothing for the field: the defaults only when this form didn't post.
protected override void OnInitialized()
{
var posted = HttpContext?.Request.HasFormContentType == true && HttpContext.Request.Form["_handler"] == "pick-list-usage";
Model ??= posted ? new() : new() { Columns = ["Order", "Customer", "Total"] };
}
private void Save() => _saved = true;
public sealed class Report
{
public List<string> Columns { get; set; } = [];
}
}Add this example to a page with the izzy CLI:
izzy add component PickList --at <file>:<line>Search and a template
For a longer list, set Searchable: a search box goes over each list, and Move all moves only the matches. To draw each item, set ItemTemplate; ItemText is what search matches.
Static
Preview
- Ada Lovelace
- Alan Turing
- Barbara Liskov
- Donald Knuth
- Edsger Dijkstra
- Grace Hopper
- Katherine Johnson
- Ken Thompson
- Margaret Hamilton
- Radia Perlman
Code
@* A longer list: a search box over each list, and Move all moves only the matches. *@
<PickList Label="Team" @bind-Value="_team" Items="People" ItemText="p => p.Name" Searchable MaxWidth="36.Rem" Grow Context="person">
<ItemTemplate><Avatar Name="person.Name" Size="AvatarSize.Xs" Decorative /> person.Name</ItemTemplate>
</PickList>
{
private Person[] _team = [];
}Details
Select items in a list (click; Ctrl or Cmd adds, Shift extends; on a touch screen, a tap adds or takes out one) and move them with the buttons between the lists, double-click, Enter, or by dragging. Reorderable adds Move up and Move down beside the chosen list, and dragging within it; Searchable puts a search box over each list, and Move all then moves only the matches.
How it works three ways:
- No script: a native
<select multiple>holds and posts the values, chosen ones first in their order. - With script (
<ib-pick-list>): the two lists, drawn from the same items; each move changes which options are selected and their order, so the form posts the select. - Interactive: the same, and @bind-Value follows every move.
For a short list where order doesn't matter, CheckboxGroup or MultiSelect take less room.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| Two lists, the move buttons, double-click and Enter | Yes | Yes |
| Dragging between the lists and within Chosen | Yes | Yes |
| Search over each list | Yes | Yes |
| The chosen items post in their order | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Every page starts as plain HTML: before IzzyBlazor's script loads on a static page, while an interactive page prerenders, and with JavaScript off. With JavaScript off, it's a plain multi-select list, without the two lists, moving, ordering or search.
Accessibility
- Each list is a multi-select
listboxnamed by the label and its own heading ("Columns, Available"). One Tab stop each; the arrow keys move between items, Space selects. - The buttons between the lists are named for what they do ("Move to chosen"), and say when there's nothing to move (
aria-disabled) rather than leaving the Tab order. - After a move, focus stays on the button, or goes to the other list if its own is empty. Each move is announced: "Moved
Statusand Owner to chosen". - Typing in a search box announces how many items match ("4 matches",
IzzyText.MatchCount), or "No matches", politely. - With JavaScript off, it's a native multiple
select, with the browser's own keys.
Keyboard navigation
| Press this key | To do this |
|---|---|
| Up or Down or Home or End | Move through a list |
| Space | Select or unselect the item |
| Shift+Up or Shift+Down or Shift+Home or Shift+End | Extend the selection |
| Ctrl+A | Select every item in the list |
| Enter | Move the selected items, or the focused one, to the other list |
| Alt+Up or Alt+Down | With Reorderable, move the selected chosen items up or down |
Parameters
| Prop | Type | Default |
|---|---|---|
ItemsThe items to choose from. | IEnumerable<TItem>? | Required |
ItemTextEach item's text, also what search matches. | Func<TItem, string>? | computed |
ItemTemplateMarkup for each item in the lists, such as an icon. | RenderFragment<TItem>? | |
ItemDisabledItems that can't move, shown dimmed in their list. | Func<TItem, bool>? | |
ReorderableMove up and Move down beside the chosen list, and dragging within it, to set the order. | bool | false |
SearchableA search box over each list. | bool | false |
AllowMoveAllThe buttons that move every item, or every match. | bool | true |
SearchLabelThe search boxes' name and placeholder. | string? | computed |
ReadOnlyMakes the field read-only: the chosen items show in a read-only text field, and the values still post. | bool | false |
@bind-ValueThe value, bound with @bind-Value. | TValue | |
DisplayNameThe field's name in validation messages from the input itself, such as a value that can't be parsed. | string? |
Plus 28 field props.
Full APISee also
- MultiSelect: lets the user choose several options, shown as chips, and type to filter them.
- CheckboxGroup: lets the user pick several choices from a list of checkboxes.