New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@daviddarnes/live-filter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@daviddarnes/live-filter

A Web Component for filtering items using a text input

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

live-filter

A Web Component for filtering items using a text input.

Demo

Examples

General usage example:

<script type="module" src="live-filter.js"></script>

<live-filter>
  <label>Filter: <input type="search" aria-controls="list" /></label>
  <ul role="region" id="list" aria-live="polite">
    <li>African Violet</li>
    <li>Aloe Tiger Plant</li>
    <li>Aralia Ming</li>
    <li>Autograph Tree</li>
  </ul>
</live-filter>

Example setting the selector option to select dt elements:

<script type="module" src="live-filter.js"></script>

<live-filter selector="dt">
  <label>Filter: <input type="search" aria-controls="data" /></label>
  <dl role="region" id="data" aria-live="polite">
    <dt>Beast of Bodmin</dt>
    <dd>A large feline inhabiting Bodmin Moor.</dd>
    <dt>Morgawr</dt>
    <dd>A sea serpent.</dd>
    <dt>Owlman</dt>
    <dd>A giant owl-like creature.</dd>
  </dl>
</live-filter>

Example setting the case option to change the search to be case insensitive:

<script type="module" src="live-filter.js"></script>

<live-filter case="insensitive">
  <label>Filter: <input type="search" aria-controls="list" /></label>
  <ul role="region" id="list" aria-live="polite">
    <li>African Violet</li>
    <li>Aloe Tiger Plant</li>
    <li>Aralia Ming</li>
    <li>Autograph Tree</li>
  </ul>
</live-filter>

Features

This Web Component allows you to:

  • Filter a list using a text input field
  • Control how the filtering is presented by using CSS to hook into element attributes data-live-filter-match="true" and data-live-filter-match="false"
  • Adjust what items are filtered using the selector attribute on the live-filter element itself
  • Adjust the case sensitivity of searching using the case attribute on the live-filter element itself

Installation

You have a few options (choose one of these):

  1. Install via npm: npm install @daviddarnes/live-filter
  2. Download the source manually from GitHub into your project.
  3. Skip this step and use the script directly via a 3rd party CDN (not recommended for production use)

Usage

Make sure you include the <script> in your project (choose one of these):

<!-- Host yourself -->
<script type="module" src="live-filter.js"></script>
<!-- 3rd party CDN, not recommended for production use -->
<script
  type="module"
  src="https://www.unpkg.com/@daviddarnes/live-filter@1.1.0/live-filter.js"
></script>
<!-- 3rd party CDN, not recommended for production use -->
<script
  type="module"
  src="https://esm.sh/@daviddarnes/live-filter@1.1.0"
></script>

Using selector and case:

By default live-filter will select all the li elements within it to search through. However with the selector attribute you can pass in a different selector string to search through:

<live-filter selector="dt">
  <!-- ... -->
</live-filter>

By default live-filter will be case sensitive, which can be restrictive when searching through proper nouns and titles. This can be adjusted using the case attribute and setting the value to insensitive:

<live-filter case="insensitive">
  <!-- ... -->
</live-filter>

Credit

With thanks to the following people:

Keywords

FAQs

Package last updated on 23 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc