sterling-svelte  2.0.0
A modern, accessible, lightweight UI component library for Svelte.

List

An scrollable set of items where a single item can be selected.

Code
<script lang="ts">
  import { List } from '@geoffcox/sterling-svelte';
</script>

<List>
  <!-- <ListItem> ... -->
</List>

Members

Property NameTypeDefaultComment
disabledboolean | null | undefinedfalseWhen true, the list and all its items are disabled.
horizontalboolean | null | undefinedfalseWhen true, items are arranged horizontally.
selectedValuestring | undefinedundefinedThe value of the currently selected item.
onSelect(value: string | undefined) => voidCalled when the selectedValue changes.

Method NameParametersReturn TypeComment
scrollToItemScrolls to the item with the given value.
selectItemSelects the item with the given value.
selectNextItemSelects the item after the selected item.
selectPreviousItemSelects the item before the selected item.
selectFirstItemSelects the first item in the list.
selectLastItemSelects the last item in the list.

Considerations

  • Use the children to provide list items.
  • A list item is identified by having data-value and role="listitem" properties. Any content without these properties, will not participate in selection. This allows you to mix in other content with list items such as search boxes, group headers, or decorations.
  • If no item is selected, selectNextItem selects the first item in the list and selectPreviousItem selects the last item in the list.
  • A container wraps the children to allow scrolling when the list dimensions are not set and take up available room.
  • Includes HTMLDivElement props, events, and methods.

Anatomy

list (<div>)
  container (<div>)
    children (Snippet)