enes

ListView

The ListView is a component for rendering a set of vertically stacked items. These items can be focusable, selectable, have one primary action and one or more secondary actions, and support keyboard navigation and accessibility features.

  • Chile
  • Colombia
  • Dominican Republic
  • Costa Rica
  • Venezuela

Usage

<script>
	import { ListView, ListViewItem } from 'fluentui-svelte';
	let list = ['A', 'B', 'C'];
	let selected = ['A'];
</script>

<ListView selectedItems={selected}>
	{#each list as item (item)}
		<ListViewItem value={item}>{item}</ListViewItem>
	{/each}
</ListView>

Navigation Mode

Use items to keep each item in the Tab order. Use composite to give the list one tab stop and enter an item's secondary controls with Right. Selection uses listbox and option roles in items mode, or grid, row and gridcell roles in composite mode. For selectable navigation with sublists, set role="list" on each ListView and use aria-current on links: each list manages its own selectedItems, without selecting items at other levels.

Best practices

  • Keep lists that only display text out of the Tab sequence. Configure navigationMode on the outer ListView: use items for native link navigation and composite for selectable cards with secondary controls. Let the component manage item and control tabindex unless you opt out with disableTabspot.
  • With the default grid roles in selectable composite lists, the component wraps each row's content in one gridcell and manages navigation to its controls. No manual gridcell wrappers are needed.
  • Use onAction for an item's primary action and native buttons or links with onclick for secondary actions. Enter and Space both activate non-native actionable items; links retain native keyboard behavior. In composite selection rows, the checkmark changes selection independently, and secondary buttons and links do not trigger the row's action or selection.
  • Keep the default roles for flat selection widgets; they depend on both selectionMode and navigationMode. Match the HTML tags: ul/ol with li items, or as="div" on both a card list and its items.
  • Use ListViewItemBranch for expandable sublists. Branches are never selectable and manage their disclosure attributes and focus. Each nested list owns its selection. Set role="list" on each selectable list containing branches to preserve native list semantics.
  • Give selectable ListView widgets an accessible name with aria-label or aria-labelledby. Give navigation a named nav landmark and mark the current link with aria-current="page". Use meaningful visible text or aria-label for controls, a descriptive branch label, and stable item value strings when using selection.

Keyboard navigation

Up and Down move between siblings; Home and End move to the ends of the current level. Right opens a collapsed branch; Right on an expanded branch enters its sublist. Left closes an expanded branch; Left on a collapsed branch or child returns to its parent. Escape closes the nearest branch and restores focus to its button. Right also enters a composite item's controls: Left and Right move between them, and Left from the first control returns to the row. Enter activates links; Enter and Space activate buttons and selectable items. In items mode, Tab visits the items and their controls; in composite mode, the entire list has one tab stop. disableTabspot opts out of arrow-key focus management.

Simple navigation

Wrap the list in a named nav landmark and use as="a" with href for navigation links. ListView wraps links in native list items when the list is a ul or ol. Use aria-current="page" on the current link; site navigation keeps native list and link semantics.

Navigation with sublists

Nest a ListView inside ListViewItemBranch. Branches are focusable disclosure buttons and never selectable. Expanded state, aria-expanded, aria-controls, hidden content and focus restoration are managed automatically. Each nested list keeps its own selection state when collapsed. Use native list semantics; set role="list" when enabling selection on a list containing branches.

Selection Mode

Use selectionMode (single, multiselect, or extended) to control how items are selected.

  • Apple
  • Banana
  • Cherry

Toggle on click

In a multiselect list, a plain click selects only that item and Ctrl/Cmd + click toggles it. Set toggleOnClick to make a plain click toggle the item directly.

  • Apple
  • Banana
  • Cherry

Checkmark

Add and configure a checkbox for the element. You can use the same props for the Checkbox component.

The checkbox toggles the selection of its item without triggering onAction. Bind selectedItems to read or control the selection.

  • Apple
  • Banana
  • Cherry

Selected: Apple

Cards with a primary action

With navigationMode set to composite and a selectionMode, every item is a row. Set as="div" on both the list and its card items to keep the HTML structure valid. Clicking a row runs its primary action (onAction), the checkbox toggles its selection, and any button inside is a secondary action. Use checkmark.wrapperAttributes.style to place the checkbox where you need it, like the top-right corner of the card.

Fluent

Design system

Svelte

UI framework

Vite

Build tool

Selected:

Last action:

Secondary controls run their own actions without selecting the item or triggering its primary action. The checkbox only toggles selection.

ListView Props

NameTypeDefaultDescription
roleAriaRoleOverrides the list role and the roles derived for its items. Use list for nested navigation with independent selection.
selectionMode'none' | 'single' | 'multiselect' | 'extended''none'How many items can be selected, and how the selection is made.
navigationMode'items' | 'composite''items'Whether the list itself takes a single tab stop, or every item takes its own.
manageSpecialKeysboolean | TabspotRootOptions['manageSpecialKeys']trueWhich special keys Tabspot handles at the root. Set individual keys to leave Escape to an enclosing panel. Omitted keys in an object are off.
selectedItems bindablestring[]The values of the selected items.
shape'circular' | 'rounded' | 'square''rounded'The items can have a circular, rounded or square shape.
onSelectionChange(e: Event, selectedItems: string[] | []) => voidCalled whenever the selection changes.
toggleOnClickbooleanfalseWhen selectionMode is 'multiselect', clicking an item toggles its selection directly instead of requiring Ctrl/Cmd + click.
as'ul' | 'ol' | 'div''ul'The HTML element to render the list as.
ref bindableHTMLUListElement | HTMLOListElement | HTMLDivElementThe DOM reference of the list element.
disableTabspotbooleanfalseOpts the list out of the tabspot focus management, to wire your own.
HTML Attributes

ListViewItem Props

NameTypeDefaultDescription
as'li' | 'a' | 'button' | 'div''li'The HTML element to render the item as. Links and buttons are wrapped in a list item when the list renders as ul or ol. Use li or div for nested lists and content with multiple controls. Buttons cannot contain checkmarks or composite rows.
shape'circular' | 'rounded' | 'square'The item can have a circular, rounded or square shape. Inherited from the list by default.
valuestringThe value reported to the list when the item is selected. Falls back to a generated id.
activebooleanRenders the item in its pressed state.
role'treeitem' | 'menuitem' | 'option' | 'row'The ARIA role of the item. Derived from the list by default.
disabledbooleanDisables the user interaction.
checkmarkCheckboxPropsThe props to spread on the checkbox rendered when the list is multiselect.
onAction(e: MouseEvent, value: string) => voidCalled when the item is clicked or activated with the keyboard.
onfocus(e: Event, value: string) => voidCalled when the item receives the focus.
ref bindableHTMLLIElement | HTMLAnchorElement | HTMLButtonElement | HTMLDivElementThe DOM reference of the item element.
HTML Attributes

ListViewItemBranch Props

NameTypeDefaultDescription
labelstringThe accessible label rendered in the disclosure button.
iconSnippet | ComponentThe decorative icon before the label.
expanded bindablebooleanfalseWhether the nested content is visible. Branches only expand or collapse and are never selectable.
onExpandedChange(e: Event, expanded: boolean) => voidCalled when a user expands or collapses the branch.
disabledbooleanfalseDisables the disclosure button.
shape'circular' | 'rounded' | 'square'The disclosure button shape. Inherited from the list by default.
ref bindableHTMLButtonElementThe DOM reference of the native disclosure button. Additional HTML attributes, including class and id, also target this button.
wrapperRef bindableHTMLLIElement | HTMLDivElementThe DOM reference of the wrapper element, the list item that holds the button and the nested list.
wrapperAttributesHTMLAttributesThe attributes to spread on the wrapper element.
childrenSnippetNested ListView content, kept mounted while collapsed to preserve its selection.
HTMLButtonAttributes without children, role, type, value, aria-expanded, aria-controls
Edit this Doc View as Markdown