This commit is contained in:
17
app/javascript/controllers/hotkey_controller.js
Normal file
17
app/javascript/controllers/hotkey_controller.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
click(event) {
|
||||
if (this.#isClickable && !this.#shouldIgnore(event)) {
|
||||
this.element.click()
|
||||
}
|
||||
}
|
||||
|
||||
#shouldIgnore(event) {
|
||||
return event.defaultPrevented || event.target.closest("input, textarea")
|
||||
}
|
||||
|
||||
get #isClickable() {
|
||||
return getComputedStyle(this.element).pointerEvents !== "none"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user