enes

ListView Beta

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>

Best practices

Please check List for best practices.

Navigation Mode

This option allows you to set keyboard navigation based on your needs. For view-only data, you do not need to set this unless the items perform some action. If your items have multiple actionable elements within the ListViewItem, like buttons or menus, you can set this to composite.

Selection Mode

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

  • Apple
  • Banana
  • Cherry

Checkmark

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

  • Card Content Inside ListItem
  • Note: every actionable element inside this ListViewItem must call e.stopPropagation().

    ListView Props

    NameTypeDefaultDescription
    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.
    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.
    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' | 'div''li'The HTML element to render the item as.
    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 | HTMLDivElementThe DOM reference of the item element.
    HTML Attributes