Skip to content
IzzyBlazor

Enter all results ↑ ↓ move Esc close

PickList

Since 0.1.0-alpha.21
Lets the user choose items by moving them from one list to another, in the order they want.

Two 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

Available
  • Date
  • Email
  • Status
  • Items
  • Paid
  • Shipped
Chosen
  • Order
  • Customer
  • Total

Code

Usage.razor
@using 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>

@code {
    [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:

bash
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

Available
  • Ada Lovelace
  • Alan Turing
  • Barbara Liskov
  • Donald Knuth
  • Edsger Dijkstra
  • Grace Hopper
  • Katherine Johnson
  • Ken Thompson
  • Margaret Hamilton
  • Radia Perlman
Chosen

    Code

    Team.razor
    @* 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>
    
    @code {
        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

    What works in each mode, PickList
    FeatureStaticInteractive
    Two lists, the move buttons, double-click and EnterYesYes
    Dragging between the lists and within ChosenYesYes
    Search over each listYesYes
    The chosen items post in their orderYesYes

    Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.

    Accessibility

    • Each list is a multi-select listbox named 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 Status and 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

    PickList keys
    Press this keyTo do this
    Up or Down or Home or EndMove through a list
    SpaceSelect or unselect the item
    Shift+Up or Shift+Down or Shift+Home or Shift+EndExtend the selection
    Ctrl+ASelect every item in the list
    EnterMove the selected items, or the focused one, to the other list
    Alt+Up or Alt+DownWith Reorderable, move the selected chosen items up or down

    Parameters

    PickList parameters
    PropTypeDefault
    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.boolfalse
    SearchableA search box over each list.boolfalse
    AllowMoveAllThe buttons that move every item, or every match.booltrue
    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.boolfalse
    @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?

    See 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.

    Connection lost

    Rejoining the server…