Sha256: 0757cdb156db2c513eafe312e0f757ff3878ea49b56ae1ed4072a57b9dbf0bd7
Contents?: true
Size: 1.32 KB
Versions: 4
Compression:
Stored size: 1.32 KB
Contents
import {Controller} from "@hotwired/stimulus" export default class extends Controller { static get targets() { return ["button", "popup"] } // Attaches controller logic to the element itself // This allows calling controller methods from the element in other controllers connect () { this.element['controller'] = this } toggle(event) { event.preventDefault() const expanded = this.buttonTarget.getAttribute('aria-expanded') === 'true' if (expanded) { this.close(null) } else { this.open() } } open() { this.buttonTarget.setAttribute('aria-expanded', 'true') this.popupTarget.classList.remove('closed') } close(event) { if (this.isClickedInside(event)) { event.preventDefault() return } this.buttonTarget.setAttribute('aria-expanded', 'false') this.popupTarget.classList.add('closed') } isClickedInside(event) { if (!event) { return false } const inPopup = this.popupTarget.contains(event.target) const inButton = this.buttonTarget.contains(event.target) const inAddButton = event.target.dataset.action === "click->filters#add" return (inPopup || inButton || inAddButton) } }
Version data entries
4 entries across 4 versions & 1 rubygems