2025-11-18 15:03:53 -05:00
|
|
|
import { Controller } from "@hotwired/stimulus"
|
|
|
|
|
|
|
|
|
|
export default class extends Controller {
|
2025-11-18 15:14:12 -05:00
|
|
|
static targets = ["display", "hiddenInput"]
|
2025-11-18 15:03:53 -05:00
|
|
|
|
|
|
|
|
select(event) {
|
|
|
|
|
event.preventDefault()
|
|
|
|
|
event.stopPropagation()
|
|
|
|
|
|
|
|
|
|
const button = event.currentTarget
|
|
|
|
|
const icon = button.dataset.icon
|
|
|
|
|
|
2025-11-18 15:14:12 -05:00
|
|
|
if (icon) {
|
|
|
|
|
// Update the display
|
|
|
|
|
if (this.hasDisplayTarget) {
|
|
|
|
|
this.displayTarget.textContent = icon
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the hidden input
|
|
|
|
|
if (this.hasHiddenInputTarget) {
|
|
|
|
|
this.hiddenInputTarget.value = icon
|
|
|
|
|
}
|
2025-11-18 15:03:53 -05:00
|
|
|
|
|
|
|
|
// Close the dropdown by removing focus
|
|
|
|
|
const activeElement = document.activeElement
|
|
|
|
|
if (activeElement) {
|
|
|
|
|
activeElement.blur()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|