ListBox

This component presents its assigned children as items in a single-selection list box. This is modeled after the list box controls in macOS and Microsoft Windows, and the standard select element in HTML in its list box mode.

Acai
Acerola
Apple
Apricot
Banana
Blackberry
Blueberry
Cantaloupe
Cherry
Cranberry
Currant
Date
Durian
Fig
Goji berry
Gooseberry
Grape
Grapefruit
Honeydew
Jackfruit
Kiwi
Kumquat
Lemon
Lime
Lychee
Mango
Mangosteen
Mulberry
Nectarine
Orange
Papaya
Passion Fruit
Peach
Pear
Pineapple
Plum
Pomegranate
Pomelo
Prickly Pear
Raspberry
Strawberry
Tangerine
Watermelon
Demo: Typical single-selection list box

ListBox uses SingleSelectionMixin to expose a single selection. The user can click an item to select it, or navigate the selection with the keyboard (per KeyboardDirectionMixin, KeyboardPagedSelectionMixin, and KeyboardPrefixSelectionMixin).

By default, the selected item is shown with standard highlight colors (CSS highlight color for the background, highlighttext for the text). This will eventually be configurable with CSS, although Elix is still working out a general theming strategy.

The ListBox exposes an orientation property that can either by "vertical" (the default), or "horizontal". Moreover, the list reflects its orientation property value as an attribute to simplify conditional styling.

😀
😁
😂
😍
😊
🤔
😆
😮
🙄
😘
Demo: A horizontal list

The ListBox applies SelectedItemTextValueMixin (below) to expose a value property.

Lists typically obtain their items from their child elements using DefaultSlotContentMixin. However, it is easy to create variations of ListBox for lists with hard-coded content. For example, the following demo shows a list of browser "plugins" registered with your browser via navigator.plugins. (These tend to be internal components, rather than user-visible browser extensions. If you do not see a demo, your browser may have no plugins installed.)

Demo: A list with hard-coded items

By default, a ListBox shows a generic visual style. Once the Elix project establishes a theming strategy, we will allow developers to style a ListBox instance with CSS.

The ListBox class is registered as element <elix-list-box>.

Usage

Single-selection list boxes are common in user interfaces. As written, the ListBox component supports the same use cases as a standard select element in list box mode (with the size attribute set to a value greater than 1). The standard select, however, has many constraints on what can be done with it, forcing developers to recreate much of its functionality. The advantage of providing ListBox as a web component is that developers are free to extend it to meet the needs of their interface. For example, one use case for ListBox is a horizontal list (instead of the fixed vertical orientation provided by select).

API

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

getIndexOfItemAtY() method

Return the item whose content spans the given y position (relative to the top of the list's scrolling client area), or null if not found.

If downward is true, move down the list of items to find the first item found at the given y position; if downward is false, move up the list of

items to find the last item at that position.

Inherited from module:KeyboardPagedSelectionMixin

itemForTarget() method

Return the list item that is, or contains, the indicated target node. Return null if not found.

This is sufficiently flexible to accommodate the possibility of the target being inside arbitrarily deep layers of shadow DOM containment.

Inherited from module:ClickSelectionMixin

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

orientation property

The vertical (default) or horizontal orientation of the list.

Supported values are "horizontal" or "vertical".

Type: string

orientation-changed event

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

pageDown() method

Scroll down one page.

Defined by KeyboardPagedSelectionMixin

pageUp() method

Scroll up one page.

Defined by KeyboardPagedSelectionMixin

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

scrollItemIntoView(item) method

Scroll the given element completely into view, minimizing the degree of scrolling performed.

Blink has a scrollIntoViewIfNeeded() function that does something similar, but unfortunately it's non-standard, and in any event often ends up scrolling more than is absolutely necessary.

This scrolls the containing element defined by the scrollTarget property. See that property for a discussion of the default value of that property.

Parameters:
  • item: Elementthe item to scroll into view.

Defined by SelectionInViewMixin

scrollOnePage() method

Move by one page downward (if downward is true), or upward (if false). Return true if we ended up changing the selection, false if not.

Inherited from module:KeyboardPagedSelectionMixin

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

selectItemWithTextPrefix(prefix) method

Select the first item whose text content begins with the given prefix.

Returns: boolean 

Parameters:
  • prefix: stringThe prefix string to search for

Defined by KeyboardPrefixSelectionMixin

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.goDown() method

Invoked when the user wants to go/navigate down. The default implementation of this method does nothing.

Defined by KeyboardDirectionMixin

symbols.goEnd() method

Invoked when the user wants to go/navigate to the end (e.g., of a list). The default implementation of this method does nothing.

Defined by KeyboardDirectionMixin

symbols.goLeft() method

Invoked when the user wants to go/navigate left. The default implementation of this method does nothing.

Defined by KeyboardDirectionMixin

symbols.goRight() method

Invoked when the user wants to go/navigate right. The default implementation of this method does nothing.

Defined by KeyboardDirectionMixin

symbols.goStart() method

Invoked when the user wants to go/navigate to the start (e.g., of a list). The default implementation of this method does nothing.

Defined by KeyboardDirectionMixin

symbols.goUp() method

Invoked when the user wants to go/navigate up. The default implementation of this method does nothing.

Defined by KeyboardDirectionMixin

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

symbols.keydown(event) method

Handle the indicated keyboard event.

The default implementation of this method does nothing. This will typically be handled by other mixins.

Returns: boolean true if the event was handled

Parameters:
  • event: KeyboardEventthe keyboard event

Defined by KeyboardMixin

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

value property

The text content of the selected item.

Setting this value to a string will attempt to select the first list item whose text content match that string. Setting this to a string not matching any list item will result in no selection.

Type: string

Defined by SelectedItemTextValueMixin

© 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.