Files
fizzy/app/javascript/controllers/related_element_controller.js
Kevin McConnell d248bd6323 Clear Activity highlights on back navigation
Also small refactor of the controller.
2025-01-29 18:00:21 +00:00

25 lines
545 B
JavaScript

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "related" ]
static classes = [ "highlight" ]
connect() {
this.#highlight(null)
}
highlight(event) {
this.#highlight(event.currentTarget.dataset.relatedElementGroupValue)
}
unhighlight() {
this.#highlight(null)
}
#highlight(groupValue) {
this.relatedTargets.forEach(element =>
element.classList.toggle(this.highlightClass, element.dataset.relatedElementGroupValue === groupValue)
)
}
}