Rokkit 1.0.3

List

Data-driven list component with field mapping and customization

A flexible, keyboard-navigable list component for displaying and selecting from collections of items. Supports primitives, nested groups, field mapping, and fully customizable item rendering via snippets.

Basic Example

Pass an array of objects with label and optionally icon fields. Bind value to track the current selection and use onselect for a callback.

Highlighting code...
No preview available
Example

Primitive Arrays

Pass a plain array of strings or numbers — no objects required. Each primitive becomes both the display text and the selected value.

No preview available
Example

Nested Groups

Items with a children array are rendered as collapsible groups. Add the collapsible prop to allow toggling. Keyboard navigation with arrow keys moves through all visible items; left/right keys collapse and expand groups.

No preview available
Example

Field Mapping

Your data rarely matches the component's default field names. Use the fields prop to remap — for example, mapping name → text and path → value without altering your data.

Highlighting code...
No preview available
Example

Custom Icons

Override the default expand/collapse chevrons with any icon via the icons prop. Here we use folder icons to make a file-tree style list.

No preview available
Example

Custom Item Rendering

Use the itemContent snippet to fully control what appears inside each list item. The snippet receives a ProxyItem — use proxy.label, proxy.icon, and proxy.get('fieldName') to access any field. Here each item shows a status badge alongside the icon and label.

Highlighting code...
No preview available
Example

Per-Item Snippets

For items that need entirely different layouts, set item.snippet = 'name' to route each item to a named snippet. Items without a snippet field fall back to itemContent (or the default renderer). Here fruits and vegetables get distinct treatments.

Highlighting code...
No preview available
Example

Interactive Elements in Snippets

Snippets support full Svelte reactivity — you can embed checkboxes, toggles, or inputs. Use proxy.value to access the original item and mutate it directly. Call e.stopPropagation() on the control's click to prevent the List from also triggering item selection.

No preview available
Example

Props

  • items: Array of objects or primitives
  • fields: Remap your data keys to component fields
  • value (bindable): Currently selected item value
  • collapsible: Allow groups to be expanded/collapsed
  • icons: Override the expand/collapse icons
  • disabled: Disable the entire list
  • size: Size variant (sm, md, lg)

Snippets

  • itemContent(proxy): Custom rendering for leaf items
  • groupContent(proxy): Custom rendering for group headers
  • [name](proxy): Per-item snippet — set item.snippet = 'name'

ProxyItem API

Snippets receive a ProxyItem instance:

  • proxy.label: Mapped display text
  • proxy.icon: Mapped icon class
  • proxy.href: Mapped href (renders an <a>)
  • proxy.value: The original raw item (object or primitive)
  • proxy.disabled: Whether the item is disabled
  • proxy.expanded: Expand state for groups
  • proxy.get('field'): Read any field by name

Events

  • onselect(value, proxy): Fired when an item is selected — receives the raw item value and its ProxyItem