Files
fizzy/app/javascript/controllers/hotkey_controller.js
T
2025-10-13 18:04:01 -05:00

26 lines
594 B
JavaScript

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
click(event) {
if (this.#isClickable && !this.#shouldIgnore(event)) {
event.preventDefault()
this.element.click()
}
}
focus(event) {
if (this.#isClickable && !this.#shouldIgnore(event)) {
event.preventDefault()
this.element.focus()
}
}
#shouldIgnore(event) {
return event.defaultPrevented || event.target.closest("input, textarea, lexxy-editor")
}
get #isClickable() {
return getComputedStyle(this.element).pointerEvents !== "none"
}
}