ListExplorer

Master/detail user interface pattern navigated with a list box
Autumn foliage on mountainside Coastal mountains Dirt road lined with fallen leaves Forest river Hoodoo formations Iceberg Lake with milky water Mountain lake Palm trees Red panda River at sunrise River canyon Sandy beach Snowy peaks Snowy river Stone arch Sunset over rocky ocean pool Sunset through palm trees Terraced farm Winter trees
Demo: Simple list explorer

Overview

This component implements a master/detail user interface pattern that presents a list of choices with a ListBox. This component is built on top of Explorer, and uses ListBox as the "proxy list" to contain proxy elements for the items in the list.

Usage

import ListExplorer from 'elix/src/ListExplorer.js';
const listExplorer = new ListExplorer(); // or
const listExplorer = document.createElement('elix-list-explorer');

In HTML:

<script type="module" src="node_modules/elix/src/ListExplorer.js"></script>
<elix-listExplorer>
  <!-- List items go here. -->
</elix-listExplorer>

ListExplorer is appropriate when:

  • You want to let the user focus on a single item at a time.
  • The number of items may be large (20 to 100s of items). For large collections, it is helpful to keep the list of items sorted (e.g., alphabetically or chronologically).

See also

API

Ancestry: ListExplorer → ExplorerReactiveElement → HTMLElement

Built with mixins AttributeMarshallingMixin, LanguageDirectionMixin, ReactiveMixin, ShadowTemplateMixin, SingleSelectionMixin, and SlotItemsMixin.

By default, this uses these elements in the following roles:

$ property

A convenient shortcut for looking up an element by ID in the component's Shadow DOM subtree.

Example: if component's template contains a shadow element <button id="foo">, you can use the reference this.$.foo to obtain the corresponding button in the component instance's shadow tree. The $ function is simply a shorthand for getElementById, so this.$.foo is the same as this.shadowRoot.getElementById('foo').

Type: object

Defined by ShadowTemplateMixin

canSelectNext property

True if the selection can be moved to the next item, false if not (the selected item is the last item in the list).

Type: boolean

Defined by SingleSelectionMixin

canSelectPrevious property

True if the selection can be moved to the previous item, false if not (the selected item is the first one in the list).

Type: boolean

Defined by SingleSelectionMixin

defaultState property

The default state for the component. This can be extended by mixins and classes to provide additional default state.

Type: State

Defined by ReactiveMixin

items property

The current set of items drawn from the element's current state.

Type: Array.|null

Defined by ContentItemsMixin

items-changed event

Raised when the items property changes.

Defined by ContentItemsMixin

proxies property

The current set of proxy elements that correspond to the component's main items. If you have assigned elements to the proxy slot, this returns the collection of those elements. Otherwise, this will return a collection of default proxies generated by the component, one for each item.

Type: Array.

Defined by Explorer

proxyListOverlap property

True if the list of proxies should overlap the stage, false if not.

Type: boolean

Default: false

Defined by Explorer

proxyListPosition property

The position of the proxy list relative to the stage.

The start and end values refer to text direction: in left-to-right languages such as English, these are equivalent to left and right, respectively.

Type: 'bottom'|'end'|'left'|'right'|'start'|'top'

Default: 'start'

Defined by Explorer

proxyListRole property

The class, tag, or template used to create the Explorer's list of proxies.

Type: (component class constructor)|HTMLTemplateElement|string

Default: ListBox

Defined by Explorer

proxyRole property

The class, tag, or template used to create default proxies for the list items.

Type: (component class constructor)|HTMLTemplateElement|string

Default: 'div'

Defined by Explorer

render() method

Render pending component changes to the DOM.

This method does nothing if the state has not changed since the last render call.

This method invokes all internal render methods. It then invoked componentDidMount (for first render) or componentDidUpdate (for subsequent renders).

Defined by ReactiveMixin

selected-index-changed event

Raised when the selectedIndex property changes.

Defined by SingleSelectionMixin

selectedIndex property

The index of the currently-selected item, or -1 if no item is selected.

Type: number

Defined by SingleSelectionMixin

selectedItem property

The currently-selected item, or null if no item is selected.

Type: Element

Defined by SingleSelectionMixin

selectFirst() method

Select the first item in the list.

Returns: Boolean True if the selection changed, false if not.

Defined by SingleSelectionMixin

selectionRequired property

True if the list should always have a selection (if it has items).

Type: boolean

Default: false

Defined by SingleSelectionMixin

selectionWraps property

True if selection navigations wrap from last to first, and vice versa.

Type: boolean

Default: false

Defined by SingleSelectionMixin

selectLast() method

Select the last item in the list.

Returns: Boolean True if the selection changed, false if not.

Defined by SingleSelectionMixin

selectNext() method

Select the next item in the list.

If the list has no selection, the first item will be selected.

Returns: Boolean True if the selection changed, false if not.

Defined by SingleSelectionMixin

selectPrevious() method

Select the previous item in the list.

If the list has no selection, the last item will be selected.

Returns: Boolean True if the selection changed, false if not.

Defined by SingleSelectionMixin

setState(changes) method

Update the component's state by merging the specified changes on top of the existing state. If the component is connected to the document, and the new state has changed, this returns a promise to asynchronously render the component. Otherwise, this returns a resolved promise.

Parameters:

  • changes: objectthe changes to apply to the element's state

Returns: Promise - resolves when the new state has been rendered

Defined by ReactiveMixin

stageRole property

The class, tag, or template used for the main "stage" element that shows a single item at a time.

Type: (component class constructor)|HTMLTemplateElement|string

Default: Modes

Defined by Explorer

state property

The component's current state. The returned state object is immutable. To update it, invoke setState.

Type: State

Defined by ReactiveMixin

[symbols.contentSlot] property

Defined by SlotContentMixin

[symbols.itemMatchesState](item, state) method

Returns true if the given item should be shown in the indicated state.

Parameters:

  • item: HTMLElement|SVGElement
  • state: PlainObject

Returns: boolean

Defined by ContentItemsMixin

[symbols.render](changed) method

Internal method for rendering any recent changes in state to the DOM.

The default implementation of this method does nothing. Override this method in your component to update your component's host element and any shadow elements to reflect the component's new state. See the rendering example.

Be sure to call super in your method implementation so that your component's base classes and mixins have a chance to perform their own render work.

Parameters:

  • changed: objectdictionary of flags indicating which state members have changed since the last render

Defined by ReactiveMixin