Sha256: 7ccf4c75940c8f377f20f648efabf489db6893bf47d5003bebae0fcaf2dfc202
Contents?: true
Size: 995 Bytes
Versions: 15
Compression:
Stored size: 995 Bytes
Contents
import { Controller } from "@hotwired/stimulus" export default class extends Controller { static targets = ['listItem', 'category'] filter(event) { const query = event.currentTarget.value.toLowerCase() const visibleCategories = new Set() // hide / show listItem links that match the query and note which // categories should be visible this.listItemTargets.forEach(listItemNode => { const listItemName = listItemNode.dataset.listItemValue.toLowerCase() if (listItemName.includes(query)) { listItemNode.hidden = false visibleCategories.add(listItemNode.dataset.category) } else { listItemNode.hidden = true } }) // hide / show category headers that have this.categoryTargets.forEach(categoryNode => { const categoryName = categoryNode.innerHTML if (visibleCategories.has(categoryName)) { categoryNode.hidden = false } else { categoryNode.hidden = true } }) } }
Version data entries
15 entries across 15 versions & 1 rubygems