Modes

The Modes component shows exactly one of its assigned children at any given time. It can be thought of as a list that only shows the currently selected item.

One
Two
Three
Demo: Modes controlled with Left/Right keyboard keys

Modes uses SingleSelectionMixin to expose a single selection. A developer must programmatically modify which item is currently visible, as Modes provides no user interface itself.

The Modes class is registered as element <elix-modes>.

Usage

Modes can be used for any portion of a UI with a modal state that can display two or more different sets of UI controls depending upon the state. This pattern is so common that developers rarely think of it as a thing itself. Historically, they have often created a containing div holding an inner div for each modal state, then show the div for the current state and hide the rest. But rewriting that code each time is slow and error-prone. Modes serves this need in much the same way as Polymer's iron-pages component.

API

Ancestry: Modes → HTMLElement

Modes is extended by Tabs.

This element uses AttributeMarshallingMixin, ContentItemsMixin, DefaultSlotContentMixin, ShadowTemplateMixin, and SingleSelectionMixin.

attributeChangedCallback() method

Handle a change to the attribute with the given name.

Defined by AttributeMarshallingMixin

attributesForClass() method

Return the custom attributes for the given class.

Inherited from module:AttributeMarshallingMixin

attributeToPropertyName() method

Convert hyphenated foo-bar attribute name to camel case fooBar property name.

Inherited from module:AttributeMarshallingMixin

can-select-next-changed event

Fires when the canSelectNext property changes in response to internal component activity.

Defined by SingleSelectionMixin

can-select-previous-changed event

Fires when the canSelectPrevious property changes in response to internal component activity.

Defined by SingleSelectionMixin

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

items property

The current set of items in the list. See the top-level documentation for mixin for a description of how items differ from plain content.

Type: Array.<Element>

Defined by ContentItemsMixin

items-changed event

Fires when the items in the list change.

Defined by ContentItemsMixin

propertyNameToAttribute() method

Convert a camel case fooBar property name to a hyphenated foo-bar attribute.

Inherited from module:AttributeMarshallingMixin

reflectAttribute(attribute, value) method

Set/unset the attribute with the indicated name.

This method exists primarily to handle the case where an element wants to set a default property value that should be reflected as an attribute. An important limitation of custom element consturctors is that they cannot set attributes. A call to reflectAttribute during the constructor will be deferred until the element is connected to the document.

Parameters:
  • attribute: stringThe name of the *attribute* (not property) to set.
  • value: objectThe value to set. If null, the attribute will be removed.

Defined by AttributeMarshallingMixin

reflectClass(className, value) method

Set/unset the class with the indicated name.

This method exists primarily to handle the case where an element wants to set a default property value that should be reflected as as class. An important limitation of custom element consturctors is that they cannot set attributes, including the class attribute. A call to reflectClass during the constructor will be deferred until the element is connected to the document.

Parameters:
  • className: stringThe name of the class to set.
  • value: booleanTrue to set the class, false to remove it.

Defined by AttributeMarshallingMixin

selected-index-changed event

Fires when the selectedIndex property changes in response to internal component activity.

Defined by SingleSelectionMixin

selected-item-changed event

Fires when the selectedItem property changes in response to internal component activity.

Defined by SingleSelectionMixin

selectedIndex property

The index of the item which is currently selected.

The setter expects an integer or a string representing an integer.

A selectedIndex of -1 indicates there is no selection. Setting this property to -1 will remove any existing selection.

Type: number

Defined by SingleSelectionMixin

selectedItem property

The currently selected item, or null if there is no selection.

Setting this property to null deselects any currently-selected item. Setting this property to an object that is not in the list has no effect.

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

selectIndex() method

Ensure the given index is within bounds, and select it if it's not already selected.

Inherited from module: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

symbols.content property

The content of this component, defined to be the flattened set of nodes assigned to its default unnamed slot.

Type: Array.<Element>

Defined by DefaultSlotContentMixin

symbols.itemAdded(item) method

Handle a new item being added to the list.

The default implementation of this method simply sets the item's selection state to false.

Parameters:
  • item: Elementthe item being added

Defined by SingleSelectionMixin

symbols.itemsChanged() method

This method is invoked when the underlying contents change. It is also invoked on component initialization – since the items have "changed" from being nothing.

Defined by ContentItemsMixin

symbols.itemSelected(item, selected) method

Apply the indicate selection state to the item.

The default implementation of this method does nothing. User-visible effects will typically be handled by other mixins.

Parameters:
  • item: Elementthe item being selected/deselected
  • selected: booleantrue if the item is selected, false if not

Defined by SingleSelectionMixin

trackSelectedItem() method

Following a change in the set of items, or in the value of the selectionRequired property, reacquire the selected item. If it's moved, update selectedIndex. If it's been removed, and a selection is required, try to select another item.

Inherited from module:SingleSelectionMixin

updatePossibleNavigations() method

Following a change in selection, report whether it's now possible to go next/previous from the given index.

Inherited from module:SingleSelectionMixin

© 2016-2017 Component Kitchen Inc. and contributors to the Elix project. ELIX and the Elix project logo are registered or unregistered trademarks of Component Kitchen Inc. in the United States and/or other countries. Other trademarks are the property of their respective owners. Any use of such trademarks without written permission sought and obtained from Component Kitchen is prohibited.

The Elix project is administered, as a courtesy, by Component Kitchen for the benefit of the project’s contributors and the developer community as a whole.