Basic Example
The <collection-filter>
element prepares a query from user input and provides that query on the change
event's detail
property.
In the example below, the change
event is handled with a custom function that does the following:
- Detects if the query is empty and, if so, clears all matching elements.
- Uses the
filterElements
method to find all of the elements in the example whose text content matches the query. - Adds or removes a
match
class to each example element, depending upon whether they match the query or not.
Try searching for "A", then "B", and then "F" to see the different collections that are selected, based on the text content.
Note how matches can occur anywhere within the text, instead of requring an exact text match. In the case that exact text matches are expected, use the regex toggle to perform a Regular Expressions text search.