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

Version Path
refine-rails-2.10.0 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.14 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.13 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.12 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.11 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.10 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.9 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.8 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.7 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.6 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.5 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.4 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.3 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.2 app/javascript/controllers/refine/typeahead-list-controller.js
refine-rails-2.9.1 app/javascript/controllers/refine/typeahead-list-controller.js