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>

ListView API

Best practices

Please check List for best practices.

As

You can control which tag the ListView component should use: ul, ol, or div. Default: ul.

Shape

Instead of setting this on every ListViewItem, you can set it here and every item will inherit it. Possible values are rounded, circular, or square. Default: rounded.

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.

Value

Sets the value of the current item. You must set this when using the ListView selection system or if items change dynamically.

On Action

This event is triggered when clicking or tapping the element. It executes the primary action and, if the role is not row, it also executes the selection itself.

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

    NameTypeDescription
    asstringThe HTML tag to use for the list container. Possible values: ul, ol, div.
    selectionModestringSelection mode for the list. Possible values: single, multiselect, extended.
    navigationModestringNavigation mode for keyboard navigation. Possible values: items, composite.
    selectedItemsstring[]The currently selected item values.
    shapestringThe shape of the list items. Possible values: rounded, circular, square.
    onSelectionChange(Event, string[]) => voidCallback fired when the selection changes.
    elementDynamicReference to the list DOM element. Depends on the selected as value.
    childrenOnly ListViewItemRead more here
    Element AttributesDynamicBased on the chosen as value, you will have autocomplete for all HTML attributes of that tag.

    ListViewItem Props

    NameTypeDescription
    asstringThe HTML tag to use for the item container. Possible values: li, a, div.
    activebooleanWhether the item is currently active or selected.
    shapestringThe shape of the item. Possible values: rounded, circular, square.
    valuestringThe value of the item used for selection.
    onAction(MouseEvent, string) => voidCallback fired when the item is activated.
    onFocus(Event, string) => voidCallback fired when the item receives focus.
    rolestringARIA role for the item. Possible values: treeitem, menuitem, option, row.
    disabledbooleanWhether the item is disabled.
    checkmarkobjectProps for the checkmark or checkbox.
    childrenSnippetThe content of the item.
    Element AttributesDynamicBased on the chosen as value, you will have autocomplete for all HTML attributes of that tag.