Files
fizzy/app/javascript/controllers/hotkey_controller.js
T
Kevin McConnell 880e3d98b2 Prevent default when handling keyboard shortcuts
Without this, any default action would still happen. With Chrome on
Linux, that causes browser features to be triggered with our CTRL+J and
CTRL+K actions.
2025-05-28 08:18:49 +01:00

19 lines
437 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()
}
}
#shouldIgnore(event) {
return event.defaultPrevented || event.target.closest("input, textarea")
}
get #isClickable() {
return getComputedStyle(this.element).pointerEvents !== "none"
}
}