Blazor List Group
The Blazor Bootstrap ListGroup component shows a list of items, links, or buttons, with single, multiple, checkbox, or radio selection, or tabs that switch content panes. The examples below cover links and buttons, flush, numbered, horizontal and colors.
INFO
ListGroup follows the Bootstrap 5.3 list group.
Use
ListGroupItem children (static mode), or set Data (data-bound mode).
Set TItem to the type of the item values; a static list without selection still sets it, for example TItem="string".
Basic usage #
A list of items, with an optional active item.
How to use:
How to use:
- Add
ListGroupwithTItem, andListGroupItemchildren. - Set
Active="true"on the current item; it is markedaria-current="true".
Links and buttons #
Make items actionable with a link or a click handler; they get hover, focus, and active styles.
How to use:
How to use:
- Set
Hreffor a link, orOnClickfor a button. - Set
Disabled="true". A disabled link has nohref, is markedaria-disabled="true", and does not navigate; a disabled button uses the nativedisabledattribute.
Flush #
Remove the outer borders and rounded corners so the list sits edge to edge, for example in a card.
How to use:
How to use:
- Set
Flush="true". It is ignored whenHorizontalis set.
Numbered #
Number the items. The list renders as an ordered list.
How to use:
How to use:
- Set
Numbered="true". Items can hold custom content, such as a heading and a badge.
Horizontal #
Lay the items out in a row at every width, or from a breakpoint up.
How to use:
Resize the window to see each list switch from a column to a row.
How to use:
- Set
Horizontal="true", andHorizontalBreakpointtoSmallthroughExtraExtraLarge(defaultAlways).
Colors #
Give an item a contextual color. Actionable items also get matching hover and active styles.
How to use:
How to use:
- Set
ColoronListGroupItem. - Do not rely on color alone to carry meaning; also say it in the text.
Badges #
Add a badge to an item, for example a count.
How to use:
How to use:
- Put a
Badgein the item, and lay it out withClass="d-flex justify-content-between align-items-center".
Custom content #
Put any markup inside an item, including links.
This demo shows a notification panel; the newest notification is active.
This demo shows a notification panel; the newest notification is active.
Checkboxes and radios #
Give each item a real checkbox or radio input with a label.
How to use:
How to use:
- Set
SelectionModetoCheckboxand bind@bind-SelectedItems, or toRadioand bind@bind-SelectedItem. - Set
Valueon each item. The item content is the input's label; setAriaLabelwhen an item has no visible text. - Set
StretchedLink="true"to make the whole row clickable.
Single selection #
Select one item. The list is a listbox: items are options with
How to use:
aria-selected, and a check mark shows the selected item.
How to use:
- Set
SelectionMode="ListGroupSelectionMode.Single", bind@bind-SelectedItem, and set anAriaLabel. - Keyboard: Tab moves into the list, the arrow keys, Home, and End move between items, and Space or Enter selects.
Multiple selection #
Select any number of items. The listbox is marked
How to use:
aria-multiselectable="true".
How to use:
- Set
SelectionMode="ListGroupSelectionMode.Multiple"and bind@bind-SelectedItems. Space or Enter toggles the focused item.
Disabled #
Disable the whole list, or single items.
How to use:
How to use:
- Set
Disabled="true"on the group,Disabledon a static item, orDisabledSelectorfor data-bound items.
Data binding #
Render items from data.
How to use:
How to use:
- Set
DataandTextField. - Set
OnItemClickto make the items buttons that report the clicked item.
Templates #
Render data-bound items with your own markup.
How to use:
This demo combines a template with checkbox selection.
How to use:
- Set
ItemTemplate; it takes precedence overTextField.
Tabs #
Use the items as tabs that switch content panes.
How to use:
How to use:
- Set
TabMode="true", and add aListGroupTabPaneper section with a uniqueName, and aTitleorTitleTemplate. - Panes fade by default; set
Fade="false"to switch instantly. SetTabListClassandTabContentClassto change the two columns. - Handle
OnShowing,OnShown,OnHiding, andOnHidden, and callShowTabAsyncto switch from code. - Keyboard: the arrow keys move between tabs and show them.
- Panes can be added or removed with
@if; their tabs keep the markup order and raise the same events.
EditForm validation #
Selectable lists take part in an
Submit the empty form to see both messages. An invalid list gets the
EditForm like other inputs.
Submit the empty form to see both messages. An invalid list gets the
invalid class and aria-invalid="true".