Skip to content

Filter

Sets up a live filter for a list element using a linked <input> via useFilter(listEl).

Activate

Filtering is activated by adding the filter attribute on the list element.

html
<input id="fruitFilter" placeholder="Search fruits" />

<ul filter="fruitFilter">
  <li>Apple</li>
  <li>Banana</li>
  <li>Cherry</li>
</ul>

<div id="emptyEl">No matching results.</div>

Method

useFilter(listEl)

ParameterTypeDescription
listElHTMLElementThe list element whose children will be filtered.

Options

AttributeValuesDescription
filter-modedefault, regex, fuzzyDefines the filtering behavior.
filter-highlighttrue, falseEnables the highlighting of matched text.
filter-emptyHTMLElementThe element to display when list is empty.

Modes

NameDescription
defaultMatches string based on a standard pattern. E.g., app → Apple
fuzzyMatches string based on approximate matches. E.g., apl → Apple
regexMatches stting based on JS regex patterns. E.g., ^A → Apple

Released under the MIT License.