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.
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
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.
Checkmark
Add and configure a checkbox for the element. You can use the same props for the Checkbox component.
Note: every actionable element inside this ListViewItem must call e.stopPropagation().
ListView Props
| Name | Type | Default | Description |
|---|---|---|---|
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 bindable | string[] | 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[] | []) => void | Called whenever the selection changes. | |
as | 'ul' | 'ol' | 'div' | 'ul' | The HTML element to render the list as. |
ref bindable | HTMLUListElement | HTMLOListElement | HTMLDivElement | The DOM reference of the list element. | |
disableTabspot | boolean | false | Opts the list out of the tabspot focus management, to wire your own. |
| HTML Attributes |
ListViewItem Props
| Name | Type | Default | Description |
|---|---|---|---|
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. | |
value | string | The value reported to the list when the item is selected. Falls back to a generated id. | |
active | boolean | Renders the item in its pressed state. | |
role | 'treeitem' | 'menuitem' | 'option' | 'row' | The ARIA role of the item. Derived from the list by default. | |
disabled | boolean | Disables the user interaction. | |
checkmark | CheckboxProps | The props to spread on the checkbox rendered when the list is multiselect. | |
onAction | (e: MouseEvent, value: string) => void | Called when the item is clicked or activated with the keyboard. | |
onfocus | (e: Event, value: string) => void | Called when the item receives the focus. | |
ref bindable | HTMLLIElement | HTMLAnchorElement | HTMLDivElement | The DOM reference of the item element. | |
| HTML Attributes |
