FilterListBox

List that only shows items containing a given text string
Acai
Akee
Apple
Apricot
Avocado
Banana
Bilberry
Black sapote
Blackberry
Blackcurrant
Blood orange
Blueberry
Boysenberry
Cantaloupe
Cherimoya
Cherry
Chico fruit
Clementine
Cloudberry
Coconut
Crab apple
Cranberry
Cucumber
Currant
Damson
Date
Dragonfruit
Durian
Elderberry
Feijoa
Fig
Goji berry
Gooseberry
Grape
Grapefruit
Guava
Honeyberry
Honeydew
Horned melon
Huckleberry
Jabuticaba
Jackfruit
Jambul
Japanese plum
Jostaberry
Jujube
Juniper berry
Kiwifruit
Kumquat
Lemon
Lime
Longan
Loquat
Lychee
Mandarin
Mango
Mangosteen
Marionberry
Miracle fruit
Mulberry
Nance
Nectarine
Orange
Papaya
Passionfruit
Peach
Pear
Persimmon
Pineapple
Pineberry
Plantain
Plum
Pluot
Pomegranate
Pomelo
Purple mangosteen
Quince
Rambutan
Raspberry
Redcurrant
Salak
Salal berry
Salmonberry
Satsuma
Soursop
Star apple
Star fruit
Strawberry
Surinam cherry
Tamarillo
Tamarind
Tangerine
Ugli fruit
Watermelon
White currant
White sapote
Yuzu
Demo: FilterListBox is used to show matching items in a ListWithSearch

Overview

FilterListBox as a type of ListBox that displays only those items that match a text filter. Additionally, for each item that matches, the component highlights the matching portion of the item's text.

FilterListBox is used to fill the list role of a ListWithSearch (above). FilterListBox also fills the list role in a FilterComboBox:

Fruit:
Acai
Akee
Apple
Apricot
Avocado
Banana
Bilberry
Black sapote
Blackberry
Blackcurrant
Blood orange
Blueberry
Boysenberry
Cantaloupe
Cherimoya
Cherry
Chico fruit
Clementine
Cloudberry
Coconut
Crab apple
Cranberry
Cucumber
Currant
Damson
Date
Dragonfruit
Durian
Elderberry
Feijoa
Fig
Goji berry
Gooseberry
Grape
Grapefruit
Guava
Honeyberry
Honeydew
Horned melon
Huckleberry
Jabuticaba
Jackfruit
Jambul
Japanese plum
Jostaberry
Jujube
Juniper berry
Kiwifruit
Kumquat
Lemon
Lime
Longan
Loquat
Lychee
Mandarin
Mango
Mangosteen
Marionberry
Miracle fruit
Mulberry
Nance
Nectarine
Orange
Papaya
Passionfruit
Peach
Pear
Persimmon
Pineapple
Pineberry
Plantain
Plum
Pluot
Pomegranate
Pomelo
Purple mangosteen
Quince
Rambutan
Raspberry
Redcurrant
Salak
Salal berry
Salmonberry
Satsuma
Soursop
Star apple
Star fruit
Strawberry
Surinam cherry
Tamarillo
Tamarind
Tangerine
Ugli fruit
Watermelon
White currant
White sapote
Yuzu
Demo: FilterListBox in a FilterComboBox

Usage

import FilterListBox from 'elix/src/FilterListBox.js';
const filterListBox = new FilterListBox(); // or
const filterListBox = document.createElement('elix-filter-list-box');

In HTML:

<script type="module" src="node_modules/elix/src/FilterListBox.js"></script>
<!-- By default, only show items that contain the text "berry". -->
<elix-filter-list-box filter="b">
  <div>Acai</div>
  <div>Akee</div>
  <div>Apple</div>
  <div>Apricot</div>
  <div>Avocado</div>
  <div>Banana</div>
  <div>Bilberry</div>
  <div>Black sapote</div>
  <!-- other items... -->
</elix-filter-list-box>

See also

API

Ancestry: FilterListBox → ListBoxReactiveElement → HTMLElement

Built with mixins AriaListMixin, AttributeMarshallingMixin, ComposedFocusMixin, DirectionSelectionMixin, FocusVisibleMixin, ItemsTextMixin, KeyboardDirectionMixin, KeyboardMixin, KeyboardPagedSelectionMixin, KeyboardPrefixSelectionMixin, LanguageDirectionMixin, ReactiveMixin, SelectedItemTextValueMixin, SelectionInViewMixin, ShadowTemplateMixin, SingleSelectionMixin, SlotItemsMixin, and TapSelectionMixin.

This element is used to fill a role in FilterComboBox and ListWithSearch.

$ 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

filter property

A text filter applied to the list's items. Only content elements whose text contains the indicated filter text will be included in the list's items property. The text search is case insensitive.

By default, the filter is empty, so all substantive content elements are included in items.

Type: string

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

pageDown() method

Scroll down one page.

Defined by KeyboardPagedSelectionMixin

pageUp() method

Scroll up one page.

Defined by KeyboardPagedSelectionMixin

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

scrollSelectionIntoView() method

Scroll the selected item 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. By default, it will scroll the element itself.

Defined by SelectionInViewMixin

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

selectItemWithTextPrefix(prefix) method

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

Parameters:

  • prefix: stringThe prefix string to search for

Returns: boolean

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

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

state property

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

Type: State

Defined by ReactiveMixin

suppressFocusVisibility() method

Temporarily suppress visibility of the keyboard focus until the next keydown event.

This can be useful in components like Menu that actively manage where the focus is in response to mouse hover activity. If the user uses the keyboard to invoke a menu, then changes to using the mouse, it can be distracting to see the focus indicator moving as well. In such situations, the component can invoke this method (e.g., in response to mousemove) to temporarily suppress focus visibility.

Defined by FocusVisibleMixin

[symbols.contentSlot] property

Defined by SlotContentMixin

[symbols.getItemText](item) method

Extract the text from the given item.

The default implementation returns an item's alt attribute or its textContent, in that order.

Parameters:

  • item: HTMLElement|SVGElement

Returns: string

Defined by ItemsTextMixin

[symbols.goDown]() method

Invokes selectNext to select the next item.

Defined by DirectionSelectionMixin

[symbols.goEnd]() method

Invokes selectLast to select the next item.

Defined by DirectionSelectionMixin

[symbols.goLeft]() method

Invokes selectPrevious to select the previous item.

If the element has a rightToLeft property and it is true, then this selects the next item.

Defined by DirectionSelectionMixin

[symbols.goNext]() method

Invokes selectNext to select the next item.

Defined by DirectionSelectionMixin

[symbols.goPrevious]() method

Invokes selectPrevious to select the previous item.

Defined by DirectionSelectionMixin

[symbols.goRight]() method

Invokes selectNext to select the next item.

If the element has a rightToLeft property and it is true, then this selects the previous item.

Defined by DirectionSelectionMixin

[symbols.goStart]() method

Invokes selectFirst to select the first item.

Defined by DirectionSelectionMixin

[symbols.goUp]() method

Invokes selectPrevious to select the previous item.

Defined by DirectionSelectionMixin

[symbols.itemMatchesState](item, state) method

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

Parameters:

  • item: HTMLElement|SVGElement
  • state: PlainObject

[symbols.keydown]() method

See the symbols documentation for details.

Defined by KeyboardMixin

[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

[symbols.scrollTarget] property

The element that will be scrolled when the user presses Page Up or Page Down. The default value is calculated by defaultScrollTarget.

See symbols.scrollTarget.

Type: HTMLElement

Defined by KeyboardPagedSelectionMixin

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