SelectedItemTextValueMixin

Defines a component's value as the text content of the selected item

Overview

Purpose: defines a value property that reflects the text content of a selected item.

This mixin is independent of the Elix Elix render pipeline.

Expects the component to provide:

  • state.selectedIndex property indicating the index of the currently selected item. This is usually provided by SingleSelectionMixin.
  • items property representing the items that can be selected. This is usually provided by ContentItemsMixin.

Provides the component with:

  • value property representing the text content of the currently-selected item.

Usage

import SelectedItemTextValueMixin from 'elix/src/SelectedItemTextValueMixin.js';
class MyElement extends SelectedItemTextValueMixin(HTMLElement) {}

This mixin exists for list-like components that want to provide a more convenient way to get/set the selected item using text. It adds a value property that gets the textContent of a component's selectedItem. The value property can also be set to set the selection to the first item in the items collection that has the requested textContent. If the indicated text is not found in items, the selection is cleared.

API

Used by classes DropdownList, ListBox, and Menu.

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