Explorer

Combines a list with an area focusing on a single selected item

Overview

Explorer serves as a base class for implementing item selection user interface patterns that couple two synchronized elements that both support selection. The main "stage" element focuses the user's attention on a single item drawn from a list. A secondary "proxy list" element presents a set of smaller proxy elements, one for each item in the main list. The Explorer keeps the stage and proxy list elements in sync: if the user changes the selection in one element, the selection in the other element is updated to match.

Explorer serves as the basis for a variety of common user interface elements:

Mountain lake Terraced farm Winter trees Forest river Red panda
Demo: Carousel uses a set of dots as proxies, and a SlidingStage as its stage
Page one
Page two
Page three
Demo: Tabs uses TabButton elements as proxies and Modes as its stage
home
Home
search
Search
settings
Settings
Home page
Search page
Settings page
Demo: A Tabs variation for navigation using SlidingStage as the stage
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: ListExplorer uses a ListBox for the proxy list and Modes for the stage

These components present different user interfaces, but they all possess a list synchronized with a stage. The specific form of the stage or proxy list may vary while remaining true to the pattern.

Customizing Explorer using element roles

You can customize Explorer or its subclasses by specifying which tags should be used to fill various element roles:

You can create your own components to fill any of these roles. Generally speaking, any component that supports SingleSelectionMixin should suffice as the stage or proxy list.

Supplying items to an Explorer

Elements you place inside an Explorer become the list items navigated by the stage element. E.g., you could create the first Carousel demo above like this:

    <elix-carousel>
      <img src="image1.jpg">
      <img src="image2.jpg">
      <img src="image3.jpg">
      <img src="image4.jpg">
      <img src="image5.jpg">
    </elix-carousel>

For each item in the main list, Explorer will create an instance of the element specified by proxyTag. E.g., the Carousel above will instantiate a PageDot for each item (image).

Certain subclasses of Explorer will automatically set the content of the proxy element to reflect data in the corresponding list item. E.g., Tabs will use the aria-label or alt attribute of the list item.

If you want to programmatically manipulate the appearance or content of a proxy element, you can override the Explorer's proxyUpdates method.

Supplying proxies for the items

You can also create proxy elements yourself and slot them into the proxy slot. Instead of using the default PageDot proxies in a Carousel, you can supply your own proxies:

    <elix-carousel>
      <div slot="proxy">1</div>
      <div slot="proxy">2</div>
      <div slot="proxy">3</div>
      <div slot="proxy">4</div>
      <div slot="proxy">5</div>
      <img src="image1.jpg">
      <img src="image2.jpg">
      <img src="image3.jpg">
      <img src="image4.jpg">
      <img src="image5.jpg">
    </elix-carousel>
1
2
3
4
5
Mountain lake Terraced farm Winter trees Forest river Red panda
Demo: Carousel with custom proxies

Layout

Explorer manages the top/left/bottom/right visual positioning of the list in relation the stage. You can specify a position through the proxyListPosition property, and control whether the proxy list overlaps the stage with the proxyListOverlap property.

See also

API

Ancestry: Explorer → ReactiveElement → HTMLElement

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

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

Extended by classes Carousel, CarouselSlideshow, CarouselWithThumbnails, ListExplorer, and Tabs.

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

[internal.contentSlot] property

Defined by SlotContentMixin

[internal.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

[internal.ids] 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[internal.ids].foo to obtain the corresponding button in the component instance's shadow tree. The ids property is simply a shorthand for getElementById, so this[internal.ids].foo is the same as this.shadowRoot.getElementById('foo').

Type: object

Defined by ShadowTemplateMixin

[internal.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

[internal.render](changed) method

Render the indicated 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

[internal.renderChanges]() method

Render any pending component changes to the DOM.

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

ReactiveMixin will invoke this method following a setState call; you should not need to invoke this method yourself.

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

Defined by ReactiveMixin

[internal.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

[internal.state] property

The component's current state.

The returned state object is immutable. To update it, invoke internal.setState.

It's extremely useful to be able to inspect component state while debugging. If you append ?elixdebug=true to a page's URL, then ReactiveMixin will conditionally expose a public state property that returns the component's state. You can then access the state in your browser's debug console.

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.

proxyListOverlap property

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

Type: boolean

Default: false

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'

proxyListRole property

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

Type: (component class constructor)|HTMLTemplateElement|string

Default: ListBox

proxyRole property

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

Type: (component class constructor)|HTMLTemplateElement|string

Default: 'div'

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

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