enes

Exported components

  • ItemsView
  • ItemsViewItem

ItemsView AI

An ItemsView displays a collection of items as a stack, a uniform grid or lines that keep the aspect ratio of each item, and lets users select and invoke them.

Item 175 likes
Item 261 likes
Item 339 likes
Item 498 likes
Item 582 likes
Item 660 likes

Usage

<script>
  import { ItemsView, ItemsViewItem } from 'fluentui-svelte';
  let selectedItems = $state([]);
</script>

<ItemsView aria-label="Photos" layout="grid" selectionMode="single" bind:selectedItems>
  <ItemsViewItem value="one"><img src="/one.jpg" alt="One" /></ItemsViewItem>
  <ItemsViewItem value="two"><img src="/two.jpg" alt="Two" /></ItemsViewItem>
  <ItemsViewItem value="three"><img src="/three.jpg" alt="Three" /></ItemsViewItem>
</ItemsView>

Layouts

layout arranges the items as a stack (default), a uniform grid with columns of at least minItemWidth, or a flow of lines lineHeight tall where each item keeps its aspect ratio. orientation turns the stack horizontal and spacing sets the space between items.

Landscape 1
Landscape 2
Landscape 3
Landscape 4
Landscape 5
Landscape 6
Landscape 7
Landscape 8
layout="stack"
Landscape 1
Landscape 2
Landscape 3
Landscape 4
Landscape 5
Landscape 6
Landscape 7
Landscape 8
orientation="horizontal"
Landscape 1
Landscape 2
Landscape 3
Landscape 4
Landscape 5
Landscape 6
Landscape 7
Landscape 8
layout="grid"
Landscape 1
Landscape 2
Landscape 3
Landscape 4
Landscape 5
Landscape 6
Landscape 7
Landscape 8
layout="flow"

Selection modes

selectionMode sets how users select items. Use bind:selectedItems to read or change the selection, and showCheckboxes to show a checkbox on each item.

  • none (default): no selection.
  • single: one item.
  • multiselect: several items; a click toggles each one.
  • extended: several items, with Ctrl + click and Shift + click.
Landscape 1
Landscape 2
Landscape 3
Landscape 4
Landscape 5
Landscape 6
selectionMode="none" (0)
Landscape 1
Landscape 2
Landscape 3
Landscape 4
Landscape 5
Landscape 6
selectionMode="single" (1)
Landscape 1
Landscape 2
Landscape 3
Landscape 4
Landscape 5
Landscape 6
selectionMode="multiselect" showCheckboxes (2)
Landscape 1
Landscape 2
Landscape 3
Landscape 4
Landscape 5
Landscape 6
selectionMode="extended" (2)

Item invocation

onItemInvoke runs when an item is double-clicked or Enter is pressed on it. When nothing is selectable, a click invokes the item.

Item 1
Item 2
Item 3
Item 4
Invoked: -

Keyboard and accessibility

The ItemsView is a listbox when its items are selectable, and a list otherwise. When keyboard focus is available and Tabspot is enabled, its items share a single tab stop. Arrow-key navigation requires FluentUISvelte: the arrows move between items, across the rows of the grid and flow layouts, and Home and End jump to the ends. Space selects. Enter invokes only when onItemInvoke is provided; otherwise, it selects in single-selection mode. Name it with aria-label and describe each image with alt.

ItemsView Props

NameTypeDefaultDescription
layout'stack' | 'grid' | 'flow''stack'How the items are arranged: a stack, a uniform grid or lines of items that keep their aspect ratio.
orientation'horizontal' | 'vertical''vertical'The direction of the stack layout.
spacingnumber | string4The space between items. A number is read as pixels.
minItemWidthnumber | string160The minimum width of a column in the grid layout. A number is read as pixels.
lineHeightnumber | string160The height of a line in the flow layout. A number is read as pixels.
selectionMode'none' | 'single' | 'multiselect' | 'extended''none'How many items can be selected, and how the selection is made.
showCheckboxesbooleanfalseShows a checkbox on each item when items can be selected.
selectedItems bindablestring[]The values of the selected items.
onSelectionChange(e: Event, selectedItems: string[]) => voidCalled whenever the selection changes.
onItemInvoke(e: Event, value: string) => voidCalled when an item is invoked: with a double-click or Enter, or a click when nothing is selectable.
disableTabspotbooleanfalseOpts the items view out of the tabspot focus management, to wire your own.
ref bindableHTMLDivElement | nullThe DOM reference of the items view element.
Element Attributes (div)

ItemsViewItem Props

NameTypeDefaultDescription
valuestringThe value reported to the items view when the item is selected. Falls back to a generated id.
disabledbooleanDisables the user interaction.
ref bindableHTMLDivElement | nullThe DOM reference of the item element.
Element Attributes (div)

Support Fluent UI Svelte

The library is built by one person in their free time. If it helps your work, consider sponsoring it.