Element Framework

List

  • HTML
  • JS
  • CSS
<ef-list></ef-list>
var makeData = function() {
  return Array(1000).fill(0).map(function(_, i) {
    return {
      type: i % 10 === 0 ? 'header' : 'item',
      label: i % 10 === 0 ? i + '\'s' : 'Item number ' + i,
      value: i.toString(),
      disabled: i % 10 === 7,
      hidden: i % 10 === 9
    };
  });
};
document.querySelector('ef-list').data = makeData();
ef-list {
  max-height: 200px;
}

Renders a collection of data items and provides single and multiple selection modes.

Setting array-based data

The easiest way to populate the list is to pass it an array of data items. Items must adhere to the DataItem interface.

const el = document.querySelector('ef-list');

const data = [{
  label: 'Item One',
  value: '1'
},
{
  label: 'Item Two',
  value: '2'
},
{
  label: 'Item Three',
  value: '3'
}];

el.data = data;

Data Property Interface

The data property of the ef-list use the ListData interface for its data items which is described below.

Name Type Description
label string Item's label
value string Value of an item
selected boolean Selection state of the item
readonly boolean Sets the item to be readonly
disabled boolean Sets the item to be disabled

Using a composer to set and manage data

Setting data using a CollectionComposer can be useful when data needs to be managed externally.

import { CollectionComposer } from '@refinitiv-ui/utils';

const el = document.querySelector('ef-list');

const data = [{
  label: 'Item One',
  value: '1'
},
{
  label: 'Item Two',
  value: '2'
},
{
  label: 'Item Three',
  value: '3'
}];

const composer = new CollectionComposer(data);

el.data = composer;

Default renderer

By default, the list renders items using Item and therefore can be controlled by passing data of type ItemData.

Extending the default renderer

Extending the default renderer is the easiest way to display custom content, while retaining all of the default selection states and item types.

Renders are currently being upgraded and should only be used for testing purposes.

import { List, DefaultRenderer } from '@refinitiv-ui/list';

const el = document.querySelector('ef-list');
const defaultRenderer = new DefaultRenderer(el);

el.renderer = function (item, composer, element) {
  const el = defaultRenderer.apply(this, arguments);
  // do something extra
  return el;
};

Creating a fully custom renderer

Creating a fully custom renderer gives you ultimate flexibility, however, you will have to manually handle all of the different item states.

const el = document.querySelector('ef-list');

el.renderer = function (item, composer, element) {

  // Reuse/create element for rendering content
  const el = element || document.createElement('div');

  // Setup the element if it hasn't already been created
  if (!element) {
    el.appendChild(document.createElement('div')).textContent = item.label;
    el.appendChild(document.createElement('ef-sparkline')).data = getLineData(item.value);
  }

  // Get element states
  // These values should be retrieved from the composer, as they can change.
  const selected = composer.getItemPropertyValue(item, 'selected') === true;
  const disabled = composer.getItemPropertyValue(item, 'disabled') === true;

  // Update the element states
  el.selected = selected;
  el.disabled = disabled;

  return el;

};

API Reference

Attributes

boolean
stateless
Disable selections
boolean
multiple
Allow multiple selections
string
value
Returns the first selected item value. Use `values` when multiple selection mode is enabled.

Properties

false
delegatesFocus
Element focus delegation. Set to `false` and relies on native focusing.
false
ListRenderer
renderer
Renderer used to render list item elements
"new ListRenderer(this)"
boolean
stateless
Disable selections
false
boolean
multiple
Allow multiple selections
false
ListData
data
The data object, used to render the list.
string
value
Returns the first selected item value. Use `values` when multiple selection mode is enabled.
object
values
Returns a values collection of the currently selected item values

Methods

selectItem(item)
Selects an item in the list
item
Data Item or Item Element
up()
Navigate up through the list items
down()
Navigate up through the list items
scrollToItem(item)
Scroll to list item element
item
T
Data item to scroll to

Events

value-changed
Dispatched when value changes